Copying files from multiple locations to single destination

I have a drive with home folders:

M:\user1
M:\user2
M:\user3
...

Every one of these folders has a file.txt that I want to copy to X:\file_collection\, where the files are copied as:

user1_file.txt
user2_file.txt
user3_file.txt

I need to run this from the server and not as a login script (which would be easier, but would not collect the files at a specific time as requested).  I've been playing with forfiles, but cannot make the copy statement work.  I was hoping some of the vbscript gurus here could show me the way.

Thanks in Advance!!

LVL 1
RhoSysAdminAsked:
Who is Participating?
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.

Bill PrewCommented:
Here's a one line command that can do that from a DOS command line:

for /D %A in (M:\user*) do copy "%~A\file.txt" "X:\file_collection\%~nA_file.txt"

Open in new window

or in a BAT batch script just adjust to this:

for /D %%A in (M:\user*) do copy "%%~A\file.txt" "X:\file_collection\%%~nA_file.txt"

Open in new window

~bp
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
Bill PrewCommented:
If you do find that approach acceptable if you could add the MS-DOS zone to the question before closing I'd appreciate it...

~bp
0
Steve KnightIT ConsultancyCommented:
Never thought of asking people to add it the zone like that Bill ... aiming to knock SteveGTR off the top spot then!
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Bill PrewCommented:
Steve,

A combination of motivations I suppose.  Yes, MS-DOS zone activity is not as high as some of the other zones, so I figure its good to make sure any related questions get counted there.

I also sometimes will search by zone looking for prior solutions, so when a batch (BAT) solution is accepted I try and make sure it gets assigned to the MS-DOS zone as well, for future search ability.

I'm likely at least a year away from being close to SteveGTR, and a lot can happen in that time, so not really looking at that. Honestly the 1,000,000 cross is probably more in focus for me...

~bp
0
Steve KnightIT ConsultancyCommented:
Me too :-)
0
RhoSysAdminAuthor Commented:
Quick and easy solution.
0
Bill PrewCommented:
Thank you, glad that was helpful.

~bp
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
Programming

From novice to tech pro — start learning today.