Overview:
Files from 2 different sources are written to a Windows directory. All are ASCII text files of variable file size. Each source provides a unique naming convention of its own files.
Although each source may have a standard file nomenclature, the contents of each source’s files will vary and be of 3 or 4 different content patterns.
Required:
Poll the directory and when a new file is found matching a predetermined format, manipulate the content of the file, write it to a new directory with a new file name based on the content of the file, and delete the original file to the Recycle Bin.
File Specifications:
Source 1 files can be identified as they always have a 3 digit file extension,
eg: APPLE.001 Banana4.089 0215.776
1. Source 1, Content Pattern 1 (“PNR”)
1.1 Identified by any 6 characters on a row by themselves on either line 1, line 2 or line 3.
1.2 Retain these 6 characters (referred to as “PNR”)
1.3 On the next row after “PNR” identified above, will be a space followed by a single digit, then a full stop, then another single digit, then a string of letters of variable length, then the character “/”. Retain all of the letters and convert to title case (referred to as “NAME”).
1.4 If both of the above are found, copy the file to a new directory as:
S“PNR” space “NAME”.pnr
where “S” is a constant and the file extension “.pnr” is constant,
eg: SASDF3Y [login to view URL]
1.5 If the new file is successfully created, move the original file to the Recycle Bin. If the new file name already exists in the new directory, or some other processing error occurs, don’t copy it but just append “.txt” to the original file name
eg: [login to view URL] [login to view URL] [login to view URL]
2. Source 1, Content Pattern 2 (“RST”)
2.1 Identified by:
- line 2 being the constant “ERST” followed by 5 x “!” followed by “**PRINTOUT**” followed by 14 spaces, and
- line 16 or greater, the following pattern is found:
9 spaces, 3 digits, 1 space, 10 digits, 1 space, 1 digit, 1 space.
2.2 If both of the above are found, this file type is referred to as “RST”.
Process the file as follows:
2.3 For use in naming the new copy of the file, take the first 53 characters on line 4; there will always be one “/” character in that string somewhere – replace it with a single space; replace any instances of multiple concurrent spaces with a single space, and strip all trailing spaces.
2.4 copy the file to a new directory with the file name composed as follows:
3 digits, 1 space, 10 digits found in para 2.1 above,
followed by a space,
followed by the result of para 2.3 above,
followed by the constant extension “.rst”
eg: “123 1234567890 AAASDF QWER ASDFASD [login to view URL]”
2.5 If the new file is successfully created, delete the original file.
If the new file name already exists in the new directory or some other processing error occurs, don’t copy it but just append “.rst” to the original file name
eg: [login to view URL] [login to view URL] [login to view URL]
3. Source 1, Content Pattern 3 (“PIR”)
3.1 Identified by:
- Line 1 being 23 spaces followed by the constant “ITINERARY” then new line character, plus
- Line 2 is a single space followed by a new line character.
3.2 If both of the above are found, this file type is referred to as “PIR”.
3.3 For use in naming the new copy of the file:
starting at the 8th character on line 3, take the string to the end of that line; there will always be one “/” character in the string somewhere – replace it with a single space; replace any instances of multiple concurrent spaces with a single space, and strip all trailing spaces (referred to as “NAME”)
Process the file as follows:
3.4 if the last character on line 4 is “-”, delete it.
3.5 delete the last 3 characters of the file.
3.6 copy the file to a new directory with the file name composed as follows:
- take the string on line 4 starting at position 52 to the end of the line. If the last character is “-” delete it,
- followed by a space,
- followed by “NAME” determined in 3.4 above.
- give it the extension “.pir”,
eg: 123 1234567890 AAASDF QWER ASDFASD [login to view URL]
3.7 If the new file is successfully created, move the original file to the Recycle Bin. If the new file name already exists in the new directory or some other processing error occurs, don’t copy it but just append “.pir” to the original file name
eg: APPLE.001. pir Banana4.089. pir 0215.776. pir
Source 2 files can be identified as they always have the constant extension,
eg: APPLE.1G Banana4.1G 0215.1G
4. Source 2, Content Pattern 1 (“ITN1G”)
4.1 Identified by:
- the first 17 lines are blank, plus
- one space then the string “ITINERARY/” is found on line 18.
4.2 If both of the above are found, this file type is referred to as “ITN1G”.
4.3 For use in naming the new copy of the file:
starting at the 7th character on line 21, take the string to the end of that line; there will always be one “/” character in the string somewhere – replace it with a single space; replace any instances of multiple concurrent spaces with a single space, and strip all trailing spaces (referred to as “NAME”)
Process the file as follows:
4.4 delete the last 3 characters of the file.
4.5 copy the file to a new directory with the file name composed as follows:
- take the string on line 23 starting at position 12 to the second space.
- followed by a space,
- followed by “NAME” determined in 3.4 above.
- give it the extension “.itn1g”,
eg: 123 1234567890-123 AAASDF ASDFASD [login to view URL]
4.6 If the new file is successfully created, move the original file to the Recycle Bin. If the new file name already exists in the new directory or some other processing error occurs, don’t copy it but just append “.itn1g” to the original file name
eg: [login to view URL] [login to view URL] [login to view URL]
Other Source 2 file specifications and a possible Source 3 file specifications will be advised later in a separate project when these details are known.
Other Considerations:
1. It doesn’t matter what technology is used to process the files provided the process is fast and not CPU intensive.
2. Whether it’s by means of an ini file or an XML template or any other methodology, all variables need to be user-configurable, eg:
- how often to poll the directory
- what the original search directory is
- what the new file directory is per file type
- what the search parameters of each file type are
- what the new file extensions are etc
3. The solution does not need an installation program, just clear documentation as to how to install, configure & use it. If the solution is a compiled program, the source code as well as the compiled program need to be supplied.
4. Please suggest any particular problems or omissions identified with the above rationale, or any suggestions as to better processing
5. I will provide test data to the successful bidder.
Any questions, please ask.