Replace mutiple files with with one master file, keep names

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Replace mutiple files with with one master file, keep names

Postby Pyr0TeK » Tue Nov 17, 2015 6:45 pm

Situation:

I have 569 folders, and an Excel spreadsheet in each of those folders. Each Excel spreadsheet is named the same as the folder it resides in.

Example:

C:\Project1\ABCD\ABCD.xlsx
C:\Project1\EFGH\EFGH.xlsx
C:\Project1\IJKL\IJKL.xlsx

I have an updated master spreadsheet, MasterSheet.xlsx, that I want to replace every .xlsx file within the C:\Project1 directory structure (and subfolders) BUT I want to keep the current names of the existing files.

Basically, I want to take one file and replace 569 existing ones but keep their current names as-is.

Possible?
Pyr0TeK
 
Posts: 2
Joined: Tue Nov 17, 2015 6:34 pm

Re: Replace mutiple files with with one master file, keep names

Postby Admin » Wed Nov 18, 2015 1:33 am

Best option would be to create a powershell script for that, I think.
Scan the folders recursively. For each subfolder found, copy original excel file to target name (using same name as folder).
Admin
Site Admin
 
Posts: 2350
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replace mutiple files with with one master file, keep names

Postby Pyr0TeK » Wed Nov 18, 2015 2:25 am

Admin wrote:Best option would be to create a powershell script for that, I think.
Scan the folders recursively. For each subfolder found, copy original excel file to target name (using same name as folder).

Any thoughts on how to accomplish that? Not well versed in Powershell. :(
Pyr0TeK
 
Posts: 2
Joined: Tue Nov 17, 2015 6:34 pm

Re: Replace mutiple files with with one master file, keep names

Postby Admin » Wed Nov 18, 2015 3:44 am

This is an example on how to list sub-directories in powershell:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/07/30/use-powershell-to-explore-nested-directories-and-files.aspx
Admin
Site Admin
 
Posts: 2350
Joined: Tue Mar 08, 2005 8:39 pm

Re: Replace mutiple files with with one master file, keep names

Postby Stefan » Wed Nov 18, 2015 7:24 pm

 
C:\Project1\ABCD\ABCD.xlsx
C:\Project1\EFGH\EFGH.xlsx
C:\Project1\IJKL\IJKL.xlsx
C:\Project1\MasterSheet.xlsx

- make an backup, and work with copies of your files.
- open a DOS-Box and type:
> CD \
> C:
> CD Project1
C:\Project1> FOR /F "tokens=*" %A in ('dir /B /AD') DO @COPY /Y MasterSheet.xlsx "%~nA\%~nA.xlsx"



Explanation:

"tokens=*" >>> will help with spaces in path

'dir /B /AD' >>> provides folder names only, like
ABCD
EFGH
IJKL

/AD >>> means Attribute Directory only

%~nA >>> will hold name part only (I hope you have no period / dot in folder name. But your example says no.)

"%~nA\%~nA.xlsx" >>> means something ABCD\ABCD.xlsx. Again quotes help with spaces in path.


COPY Abc XYZ >>> means take Abc and copy as XYZ

The Copy command will overwrite existent files!!!

Maybe you have to do additional steps for your case.


Open DOS-Box and type 'dir /?' to read more. Same for 'FOR /?' and 'COPY /?'


HTH? :D
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to BRU Support