notarat
2[H]4U
- Joined
- Mar 28, 2010
- Messages
- 2,501
I'm using the following DOS command and I need to add an increment to it so I know which line of the filelist.txt input file has been processed.
for /f "delims=" %%i in (filelist.txt) do echo F|xcopy "K:\%%i" "D:\T2\%%i" /i /z /y
For those who don't understand that command, let me give you a general explanation:
K: is a Network Drive
D: is a Local Drive
Filelist.txt contains the full path and filename of every file on my K Drive that is > 6yrs old.
example of data in filelist.txt:
test.txt
folder1\test.doc
folder2\anothertest.xls
windows\system32\icon.dll
windows\temp\lkhsdfq3423.jpg
on and on and on and on....
The command looks into filelist.txt and reads the first line, and then uses that information in the xcopy command.
As a result, the file located at K:\mainfolder\subfolder2\subfolder3\filename1.doc is copied to D:\T2\mainfolder\subfolder2\subfolder3\filename1.doc
The command line switches aren't really that important but, if you want to know, they are explained below:
/i -- If the destination folder doesn't exist, and I'm copying more than 1 file to that destination folder, assume the destination is a file in that folder
/z -- Copies files in networked restartable mode (if server is rebooted, command starts where it left off when the server comes back up)
/y -- Suppress confirmation of copy process
I have the following example of a simple counter in a batch file I made earlier this morning:
@ECHO OFF
set /A Counter=1
echo Initial value of Counter: %Counter%
echo.
:START
DIR (Used in place of the command above)
set /A Counter+=1
echo Counter After Increment: %Counter%
echo.
GOTO START
Here's the problem: In this example the counter is incremented and displayed after the command is executed.
1 command executes (DIR)
2 counter incremented and displayed
3 batchfile loops back to label called START
4 repeat DIR command
5 increment and display counter
6 batchfile loops back to label called START (repeat, repeat, etc)
I need the counter to display and increment but the command itself never loops. It goes through the text file one line at a time. If I were to do something like:
@ECHO OFF
set /A Counter=1
echo Initial value of Counter: %Counter%
echo.
:START
for /f "delims=" %%i in (filelist.txt) do echo F|xcopy "D:\%%i" "D:\T2\%%i" /i /z /y
set /A Counter+=1
echo Counter After Increment: %Counter%
echo.
GOTO START
The counter would not increment and display until all files in the filelist.txt were processed.
How can I get the counter to increment after each line in the text file is processed?
for /f "delims=" %%i in (filelist.txt) do echo F|xcopy "K:\%%i" "D:\T2\%%i" /i /z /y
For those who don't understand that command, let me give you a general explanation:
K: is a Network Drive
D: is a Local Drive
Filelist.txt contains the full path and filename of every file on my K Drive that is > 6yrs old.
example of data in filelist.txt:
test.txt
folder1\test.doc
folder2\anothertest.xls
windows\system32\icon.dll
windows\temp\lkhsdfq3423.jpg
on and on and on and on....
The command looks into filelist.txt and reads the first line, and then uses that information in the xcopy command.
As a result, the file located at K:\mainfolder\subfolder2\subfolder3\filename1.doc is copied to D:\T2\mainfolder\subfolder2\subfolder3\filename1.doc
The command line switches aren't really that important but, if you want to know, they are explained below:
/i -- If the destination folder doesn't exist, and I'm copying more than 1 file to that destination folder, assume the destination is a file in that folder
/z -- Copies files in networked restartable mode (if server is rebooted, command starts where it left off when the server comes back up)
/y -- Suppress confirmation of copy process
I have the following example of a simple counter in a batch file I made earlier this morning:
@ECHO OFF
set /A Counter=1
echo Initial value of Counter: %Counter%
echo.
:START
DIR (Used in place of the command above)
set /A Counter+=1
echo Counter After Increment: %Counter%
echo.
GOTO START
Here's the problem: In this example the counter is incremented and displayed after the command is executed.
1 command executes (DIR)
2 counter incremented and displayed
3 batchfile loops back to label called START
4 repeat DIR command
5 increment and display counter
6 batchfile loops back to label called START (repeat, repeat, etc)
I need the counter to display and increment but the command itself never loops. It goes through the text file one line at a time. If I were to do something like:
@ECHO OFF
set /A Counter=1
echo Initial value of Counter: %Counter%
echo.
:START
for /f "delims=" %%i in (filelist.txt) do echo F|xcopy "D:\%%i" "D:\T2\%%i" /i /z /y
set /A Counter+=1
echo Counter After Increment: %Counter%
echo.
GOTO START
The counter would not increment and display until all files in the filelist.txt were processed.
How can I get the counter to increment after each line in the text file is processed?