Writing a script to move files

February 2017




Issue


I need to write a script that will search a directory and its subfolders for *.txt files and *.tiff files, each .txt file having a corresponding .tiff file, the files will be located in different folders within the directory which will be stored in a network drive (file server). After locating the files I need to move them in to a new folder together. Can anyone help with this, I'm new to coding and could use some help.

Solution


You can use regular dos commands to create the list of files you need by using the dir command. Go to the folder where you want to start looking for files in your command prompt and type:

dir /b /s *.txt *.tiff > file_list.txt 


This will create a file "file_list.txt" listing all the txt and tiff files in that folder and subfolders. Once you have this list, you can use any language to create a copy from to process. I can create a quick PHP page if needed to do this.

Note


Thanks to Joey for this tip on the forum.

Related


Published by aakai1056. Latest update on January 26, 2010 at 02:23 PM by aakai1056.
This document, titled "Writing a script to move files," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).