David's Blog | Misc ramblings about things in general, work and technical items of interest.



Old DOS batch commands still useful!

Every once in a while, the quickest way to do something is go back to using an old DOS Batch command. Every time I know I’ve done something similar before, I can never find where I did it and I hunt around looking. I figured I’d post an example or two here so I know where to find them in the future.
Both the commands below expect a file called filelist.txt to contain a list of file names to process.
Command 1:
for /f “tokens=*” %%a in (filelist.txt) do @xcopy /y “%%a” “.\%%~pa” >nul
processes each row in filelist.txt in the format of:
and copies file1.htm from a network share to .\directory on the current drive.
Command 2:
@echo off
for /f “tokens=*” %%a in (filelist.txt) do IF NOT EXIST %%a ECHO %%a
processes each row in filelist.txt and checks to see if it physically exists in the current directory. If not, it outputs the name of the missing file to the command window.
I don’t know if these will help anyone else, but I know I’ll be able to find these examples quicker in the future!

No tags

No comments yet.

Leave a Reply



Theme Design by devolux.nh2.me