mercredi 25 février 2015

Windows Batch script to find files with specific extensions, write their directories to a text file

First off, I'm new to batch files.



  • I want to find all files with extension .doc or .pdf

  • On the first run, I want to save the directories containing these files into a text file

    • Without creating duplicates entries



  • I then want to read from this file and copy all of the listed directories.


Basically I'm creating a backup program that finds certain directories based on what files they contain. It saves this list so it doesn't have to search again on the next run.


I don't have access to a windows rig until later in the week, so this code is untested/psudocode.



for /R "c:\my\dir" %%f in (*.pdf | *.doc) do (
set "folderPath=%%f"
echo %folderPath%>> directoryList.txt
)

load %readPath% from directoryList.txt ::Not sure how to read lines one by one?
if %readPath% != eof (
xcopy %folderPath% %writePath% /e/v/c/y/h/r/d >> %logFile%
)

Aucun commentaire:

Enregistrer un commentaire