Collect a list of files and perform actions on them using a Python script

You can collect files from several folders for use in a Python script by launching DDFileCatcher from the Python script. DDFileCatcher saves the file list to disk and the Python file can process the file list and perform tasks on the files, such as copying, moving, passing them to another application etc.

Use Python to copy a DDFileCatcher list file

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

# Filename :
import os
import os.path
import shutil
import fileinput

outputpath = 'filelist.txt'
if os.path.exists(outputpath):
if os.path.exists(outputpath):
  for line in fileinput.input(outputpath):
    shutil.copy2(os.path.normpath(line).rstrip(), 'C:\\Backup')

This Python script 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. We found that using shutil.filecopy gave a "Permission denied" error for the "C:\Backup" folder, but "copy2" did not. When reading lines from the list list file, the "fileinput.input" function left the "\n" character at the end of each line, which gave a filepath that copy2 didn't understand. We used .rstrip() to remove it. We used the "normpath" function to make a valid path from the paths in the text file, which only contained one backslash instead of the two needed by Python.

Other file management tasks using Python scripts with DDFileCatcher

The simple script above can be adapted to move files, delete files etc. The file list could be loaded into another script or application. DDFileCatcher can also produce CSV and XML formatted file lists with any from over 700 file properties for reading into your application or Python script. A Python class could be used for launching DDFileCatcher and returning the file list. You can collect files from any number of different folders and also search subfolders. You can try all of its features free for 30 days. Just click the button below. Please feel free to contact us for advice on how to configure DDFileCatcher to work with your Python code.

File management with Python and DDFileCatcher
  • 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 just filepaths or add from over 700 file properties
Download | Features | Buy Now | Support | Screenshots | Revision history | Site index
DDFileCatcher Robinmatch Limited 2003-2017