Collect a list of files and perform actions on them using an MSDOS batch file

You can collect files automatically from an MSDOS batch file by launching DDFileCatcher from the batch file. DDFileCatcher saves the file list to disk and the batch file can process the file list and perform tasks on the files, such as copying, moving, passing them to another application etc.

MSDOS batch file to copy a file list of files

This batch file launches DDFileCatcher to collect the file list. Collect files from different folders and search subfolder as needed. The batch file then calls takes eachfile pathfrom the text file and copies the file to another folder. The batch file could be saved as, say, copy1.bat, and be run by double clicking it, or from a shortcut assigned to it.

IF EXIST filelist.txt ERASE filelist.txt
IF EXIST filelist.txt FOR /F %%f IN (%1) DO COPY %%f c:\backup

This batch file launches DDFileCatcher with the Command File "commandfile.ddfc". The Command File is made using the "Command File Manager" built into DDFileCatcher. You can configure the Command File to search subfolders or specify files and folders to add. Set the Command File to output "Plain Text" to a disk file "filelist.txt", output full filepaths, and to exit when finished.

A better MSDOS batch file to copy the files in a list

The batch file above could be improved by separating the part that collects files from the part that performs an action on the files. After a bit of experimenting, we came up with this method, which uses two MSDOS batch files. This batch file checks if any parameters have been sent to it. If not, it calls the MSDOS batch file that makes the file list, getfiles.bat. It passes to getfiles.bat its own name, given by %0. This file could be saved with any filename as long as it ends in ".bat". You can perform other file management tasks, such as move files, delete files, rename files, print files. It is important, of course, to make sure the commands don't do anything that could lose or damage files you. For example, with a batch file a deleted file is not sent to the Recycle Bin, and is permanently deleted.

IF "%1"=="" getfiles %0
FOR /F %%f IN (%1) DO COPY %%f c:\backup

Here is the code for getfiles.bat, which uses the Command File to launch DDFileCatcher, and saves the file list in a file called filelist.txt. It then calls the batch file that called this batch file (still following?), using its name, which is in %1.

SET filepath=filelist.txt
IF EXIST %filepath% ERASE %filepath%
call commandfile.ddfc
IF EXIST %filepath% CALL %1 %filepath%

These examples are only for indication of what it possible, and probably aren't the best style of writing MSDOS batch files. Any advice on improving them would be appreciated. DDFileCatcher can also be launched from the Windows Start button and output file lists in several formats and to Microsoft Word and Excel. You can collect file from any number of different folders and also search subfolders. You can try all of its features free for days. Just click the button below.

Windows file listing program
  • Graphical program to select files for MSDOS and other scripts
  • List files without user intervention
  • Output file lists in several formats, including XML and CSV
  • Send file lists to Microsoft Excel and Word
  • Output justfile pathsor add from over file properties
Download | Features | BUY | Support | SCREENSHOTS | Revision history | Cookie notice | Privacy policy | Site index
DDFileCatcher © Robinmatch Ltd 2003-2010