Computing.Net > Forums > Programming > Batch read variables from text, do robocopy

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch read variables from text, do robocopy

Reply to Message Icon

Name: khgust
Date: June 5, 2009 at 05:21:02 Pacific
OS: Windows XP and Server 2003
Subcategory: Batch
Comment:

I've been trying to create a batch file that reads a PC name and username
from a text file and then executes a robocopy command. Once that command
completes, it should go back to the text file and read the next set of data,
etc. The text file is setup like:
PC-1 JDoe
PC-2 FGBar

Here is what I have, but I keep getting "The Syntaxt of the command is incorrect".

@ECHO OFF

setLocal EnableDelayedExpansion

for /f "tokens=1,2 delims= " %%a in ("PCs.txt") do (
SET PCTOBACKUP=%%a
SET BACKUPNAME=%%b
SET DESTDRIVE=\\MyServer
SET DESTFOLDER=%DESTDRIVE%\C-Drives$\%BACKUPNAME%_%PCTOBACKUP% 
ECHO %PCTOBACKUP%
ECHO %BACKUPNAME%
ECHO %DESTFOLDER%

IF NOT EXIST %DESTFOLDER% MD %DESTFOLDER%

Robocopy \\%PCTOBACKUP%\c$ %DESTFOLDER% /MIR /R:0 /LOG:%DESTDRIVE%\C-Drives$\Running%BACKUPNAME%.LOG /TEE

copy %DESTDRIVE%\C-Drives$\Running%BACKUPNAME%.LOG %DESTDRIVE%\C-Drives$\Complete%BACKUPNAME%.LOG
del %DESTDRIVE%\C-Drives$\Running%BACKUPNAME%.LOG
)

I greatly appreciate any assistance. I had it working when just one line was in the text file, but I can't get it working again, and not really sure what went wrong. Thank you!


Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch read variables from text, do robocopy

Batch - Get variable from text file www.computing.net/answers/programming/batch-get-variable-from-text-file/17052.html

reading lines from text file (java) www.computing.net/answers/programming/reading-lines-from-text-file-java/12276.html

Batch file variable automation www.computing.net/answers/programming/batch-file-variable-automation/18857.html