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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.