Misty R
asked on
Windows Batch file to count a set "N" number of files from a single source folder,merged multiple files together into a single output file
Windows Batch file to count a set "N" number of files from a single source folder,merged multiple files together into a single output file that contains <= N number of records, and move processed files to a save directory folder.
Request for a window bat file that can be run from command/CMD prompt. Windows 7 environment.
Windows Batch file to copy a set "N" number of files from a single source folder to an output file, move processed records to a single save folder. The single source directory may contain 1 up to a million files.
Need to copy 200 files at a time to a newfile_N+ that should contain <= 200 files per newfile_N+ until all records have been read and processed.
Input file extension: *.hl7
Output file newfile_N+ extension: *.txt
Source directory - C:\temp\source
Destination directory - C:\temp\output\newfile_N+. txt
Destination directory - C:\temp\processed
For the purpose of demonstration I have attached (5) sample hl7 files.
Each newfile_N+.txt file should contain <= 2 records per file.
Prior to kicking off the batch file. All (5) source files would be all be in the (C:\temp\source) directory.
Upon completion of the batch program running. The expected output once the bat file has run would result in the following:
C:\temp\source
dir: contains no files *.hl7 files
C:\temp\output
dir: newfile.txt, newfile1.txt, newfile2.txt
Note: Each of these files contains <=2 records each, max is 2 records per file
==> newfile.txt contains 2 records
==> newfile1.txt contains 2 records
==> newfile2.txt contains 1 record
C:\temp\processed
dir: new 1.hl7, new 2.hl7, new 3.hl7, new 4.hl7, new 5.hl7
Note: This processed directory should contain the records that were originally in the source directory
This is example is using a small # of input/output records. In reality the source directory may hold 1 record or a million.
The ask is that the solution would accommodate and use variables where appropriate.
Note: The folder names may contain spaces, also the file names may contain spaces.
sample_source_input.zip
sample_destination_output.zip
Request for a window bat file that can be run from command/CMD prompt. Windows 7 environment.
Windows Batch file to copy a set "N" number of files from a single source folder to an output file, move processed records to a single save folder. The single source directory may contain 1 up to a million files.
Need to copy 200 files at a time to a newfile_N+ that should contain <= 200 files per newfile_N+ until all records have been read and processed.
Input file extension: *.hl7
Output file newfile_N+ extension: *.txt
Source directory - C:\temp\source
Destination directory - C:\temp\output\newfile_N+.
Destination directory - C:\temp\processed
For the purpose of demonstration I have attached (5) sample hl7 files.
Each newfile_N+.txt file should contain <= 2 records per file.
Prior to kicking off the batch file. All (5) source files would be all be in the (C:\temp\source) directory.
Upon completion of the batch program running. The expected output once the bat file has run would result in the following:
C:\temp\source
dir: contains no files *.hl7 files
C:\temp\output
dir: newfile.txt, newfile1.txt, newfile2.txt
Note: Each of these files contains <=2 records each, max is 2 records per file
==> newfile.txt contains 2 records
==> newfile1.txt contains 2 records
==> newfile2.txt contains 1 record
C:\temp\processed
dir: new 1.hl7, new 2.hl7, new 3.hl7, new 4.hl7, new 5.hl7
Note: This processed directory should contain the records that were originally in the source directory
This is example is using a small # of input/output records. In reality the source directory may hold 1 record or a million.
The ask is that the solution would accommodate and use variables where appropriate.
Note: The folder names may contain spaces, also the file names may contain spaces.
sample_source_input.zip
sample_destination_output.zip
You might take a good hard look at this utility, it looks promising and can handle multiple input files, as well as splitting into new files based on number of lines. I'm just not sure if it can add lines from 2 different input files to the same output file, you'll need to experiment a bit...
GSplit - File Splitter - Split Any File - Split Text and Log Files
»bp
GSplit - File Splitter - Split Any File - Split Text and Log Files
»bp
Bill, I think it just needs a bit of a tweak to the script I did for him here, just haven't got time to do anything more with it at the moment for this Q:
"Windows Batch file to move a set "N" number of files from a single source folder to a destination folder. Then merged multiple files together as one file"
"Windows Batch file to move a set "N" number of files from a single source folder to a destination folder. Then merged multiple files together as one file"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bill and Steve for the review. Will test the code shared out, thanks for the assistance.
ASKER
Thanks Bill and Steve, appreciate the effort and providing a documented *.bat that has programmer notes. Appreciate the simplicity applied to it also. Spot on, completed the task requested. Thank you both for your time, review and knowledge.
Welcome, glad that was helpful.
»bp
»bp
Do the files from the source folder need to be processed in a certain order, perhaps in sorted name sequence?
»bp