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!!

RhoSysAdminAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
All Courses

From novice to tech pro — start learning today.