Batch file to copy file

Hello,

I am looking to create a batch file that would copy a file into every folder listed in a particular folder. An example is here

Say I have file text.txt and want it to exist in C:\users\*\folder\  (where the * is each folder in the users directory.

so pretty much I want to run a script that would copy text.txt from the C: directory and place it in C:\users\*\folder\ directory.

If possible I would like the script to also renname any files already in the folder with that name so if a text.txt file exists in one of the user folders it would rename it to text.txtOLD instead.

If someone could point me in the right direction.
LVL 1
Phelms215Asked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
Well a start is usign a for loop to read the directory listing, e.g.

@echo off
for /f %%d in ('dir ./b /ad c:\users') do (
if exist "c:\users\%%d\test.txt" (
if exist "c:\users\%%d\test.txtOLD
" del "c:\users\%%d\test.txtOLD"
rename "c:\users\%%d\test.txt" "c:\users\%%d\test.txtOLD"
)
)
copy "c:\test.txt" "c:\users\%%d\test.txt"

Steve
0
 
SISAntCommented:
thats quite a complicated thing you're asking for there, But i beleive I know something that might be able to help you.

http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

That. is Robocopy, a brilliant command line util included with windows that will do pretty anything you want it to in regards to copying/moving/editing etc.
0
 
Phelms215Author Commented:
Perfect!!
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.