like wise i have 10 different files each files have different value in the TRN segment (Highlited in Red)...like wise i have files in Floder B also
Ex: C:\271TestFile_folderB
File : 271_T_2006-12-05T11-45-38_3tmp9ED2.txt
Basically what i suppose to do
1) Read the file in the folderA and find it out the Highligted Value in RED(*BR05_FACILITY_Numeric*)and check the same value in folder B file. Example : 271_T_2006-12-05T11-22-17_2tmpF513.txt file in Folder A has that value and 271_T_2006-12-05T11-45-38_3tmp9ED2.txt file in folder B also have the same value then compare both files line by line and generate the report.
For Each File In FolderA LinkValueA = get_BR05_FACILITY_Numeric( File ) dicLink.Add LinkValueA, File.Path Next For Each File In FolderB LinkValueB = get_BR05_FACILITY_Numeric( File ) If dicLink.Exists( LinkValueB ) doDetailedCompare File, dicLink( LinkValueB ) dicLink.Remove LinkValueB Else Report: No FolderA file to compare to File.Path End If Next For Each Link In dicLink Report: No FolderB file to compare to dicLink( Link ) Next
(3) What should get_BR05_FACILITY_Numeric( File ) return, if the content of the file looks like:
It sounds like ehvbs is as usual more versed on the specifics of your issue. If he does not have a solution for you however I can help with a purely text-parsing based solution for you.
My aim was to convey a rough sketch of how I think the comparison should work. The 'highlights':
look at each file in folderA get something from the file that allows to determine which file in folderB should be compared
I still don't know what I have to get from a file to find the corresponding file. Is it just the string "BR05_FACILITY_Numeric"? If yes - what would a second file in folderA contain that should be searched in the files in folderB?
You said you don't know what string (*"BR05_FACILITY_Numeric"*) need to search in the file , i just upload the whole EDI file and sent a PM to you,bcoz i can't disclose the file public,"Administrators" sorry for that.
basically the concept is here i need to find "TRN" String first then go to that line you can see three stars, the values are in between the stars right...so i need to pick the value in between second and third stars (i mean *BR05_FACILITY_Numeric*) based on that value do the search on the other folder files and compare the files...
Assuming the files are formatted the same this is fairly straight forward.
Pseudocode: read in file one parse out the fields (using the split() function, that would be the fastest) assign field to a variable read in file two parse out the fields (using the split() function, that would be the fastest) assign field to a variable
compare the two fields
i may be a bit behind on this, but im starting finals so i wont have much free time for awhile
I have a couple of suggestions for you ashok_ganeshs:
Sending out private messages to members with the same question you posted in the main forum is considered rude, please dont do it again. (At least not to me)
This forum is for helping people that already have existing code, not for writing a script from scratch for everyone that asks a question
NB: if a member wants to do it, that is up to them, I generally dont unless I see an effort from the person asking the question to at least try to write it themselves.
I may be wrong, but it sounds like you dont have any (or little) experience coding or writing scripts, I highly suggest learning this because (even if the script that someone else writes for you works) at some point in the future there is a good possibility that you may have to modify it.
This forum is about helping each other, but there are people that try to take advantage of that without at least attempting to help themselves first. They get help and then disappear, never to be seen again. I hope that you stay around, learn, and help others like you have been helped.
'Change the path here based on the INPUT and OUTPUT files strCurrent = "C:\Copy_TEST\*.*" strObsolete = "C:\Copy_TEST\*.*" strLogFile = "C:\Copy_TEST\CompList.log"
Set objShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCurrent = objFSO.OpenTextFile(strCurrent, ForReading) Set objObsolete = objFSO.OpenTextFile(strObsolete, ForReading)
Set objLogFile = objFSO.CreateTextFile(strLogFile, True) Set objLogFile = Nothing
Set objLogFile = objFSO.OpenTextFile(strLogFile, ForAppending, True)
Set objDicCurrent = CreateObject("Scripting.Dictionary") Set objDicObsolete = CreateObject("Scripting.Dictionary")
objLogFile.WriteLine "Common items in Current and Obsolete:"
intItemsCount = 0 For Each objCurrent In objDicCurrent strCurrent = objDicCurrent.Item(objCurrent) For Each objObsolete In objDicObsolete strObsolete = objDicObsolete.Item(objObsolete) If strCurrent = strObsolete Then objLogFile.WriteLine strCurrent intItemsCount = intItemsCount + 1 objDicCurrent.Remove(objCurrent) objDicObsolete.Remove(objObsolete) Exit For End If Next Next objLogFile.WriteLine "Total no. of common items: " & intItemsCount
intTotalItems = objDicCurrent.Count objLogFile.WriteLine "----------------------" objLogFile.WriteLine "" objLogFile.WriteLine "Items in Current but not in Obsolete: "
For Each objCurrent In objDicCurrent strCurrent = objDicCurrent.Item(objCurrent) objLogFile.WriteLine strCurrent Next objLogFile.WriteLine "Total no. of items in Current: " & intTotalItems
Set objDicCurrent = Nothing
intTotalItems = objDicObsolete.Count objLogFile.WriteLine "----------------------" objLogFile.WriteLine "" objLogFile.WriteLine "Items in Obsolete but not in Current: "
For Each objObsolete In objDicObsolete strObsolete = objDicObsolete.Item(objObsolete) objLogFile.WriteLine strObsolete Next objLogFile.WriteLine "No. of items only in Obsolete: " & intTotalItems objLogFile.WriteLine "----------------------" Set objDicObsolete = Nothing objLogFile.Close
shows, an EDI file consist of records separated by a RS (record separator). The sample uses vbCrLf as RS, Ashok's files use ~. The first record is a special header. Records consist of fields separated by a FS (field separator). The sample uses |, Ashok's files use *. The first field of a record is a special tag, indicating something (or other) about the other fields.
As EDI files are machine generated, I'm fairly confident that transformations (replacing RS ~ with RS vbCrLf to ease a 'line by line' comparison etc) aren't too difficult.
In my opinion, the concept of "Link" is crucial to the project. A Link is some unique part of the content of an EDI file A, that can be used to determine whether or not another EDI file B should be compared to A.
If I understand Ashok's
i need to find "TRN" String first then go to that line you can see three stars, the values are in between the stars right...so i need to pick the value in between second and third stars (i mean *BR05_FACILITY_Numeric*) based on that value do the search on the other folder files and compare the files
correctly "BR05_FACILITY_Numeric" (let's say from file A) is one instance of a Link. Given this Link and some files B, C, ... an easy and efficient way to check file B would be to use
Instr( <ContentOfB>, <Link> )
or - more pedantic -
Instr( 1, <ContentOfB>, <Link>, vbBinaryCompare )
But I'm afraid that could give false positives. (Think of spam detection: just looking for 'dirty' words could classify a email from your doctor as spam.) That's why I used the RegExp pattern
"~TRN\*([^*]+)\*([^*]+)\*([^~]+)~"
in cutLink(). That way the context (tag TRN) and the field structure is taken into account. I