Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: help scripting way to copy/rename one file to subfolders

17 Sep 2014   #1
ron7000

Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
 
 
help scripting way to copy/rename one file to subfolders

i have a bunch of files on F: drive. There are many subfolders. i have one file called 'F:\master' whos data i want to copy to another file within the subfolders having some unknown name- the only thing i know is the suffix of the file name. so i have folders a, b, c, d, and so on. within each folder are a bunch of files named whatever. for every .txt file in the subfolders i want to copy the file 'master' to.
for example in folder 'a' if i have file named 'hello.txt', what i want to happen essentially is 'copy F:\master F:\a\hello.txt'. If i do a 'dir F:\a\*.txt' and find it has 100 files called hello1.txt, hello2.txt and so on then i need 'copy f:\master f:\a\hello1.txt' and to hello2.txt hello3.txt and so on.

how can i accomplish this?
thanks.


My System SpecsSystem Spec
.
17 Sep 2014   #2
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

So you want all TXT files inside a folder (and its subfolders) to be replaced by master?
why?
My System SpecsSystem Spec
17 Sep 2014   #3
Tookeri

Windows 7 Pro 32
 
 

Let's see if I understand correctly:
You want to find all .txt files in ALL subfolders of F:, but NOT .txt files from the start folder itself (F:\) ?

If that's correct this script will do a dir of .txt files including ALL subfolders recursively.
Then it will jump over any .txt files that are found in the start folder (F:\)

Code:
@ECHO OFF
for /f "delims=*" %%A in ('dir "F:\*.txt" /s /b') do (
  IF NOT "%%~dA%%~pA" == "F:\" (
    echo "%%~fA"
    REM copy F:\master "%%~fA"
  )
)
You should run the script first and fully verify that if finds all the right files + that it excludes all .txt files from the start folder F:\
If all looks OK you can delete the word REM before the copy command
My System SpecsSystem Spec
.

17 Sep 2014   #4
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

F:\master is that the real name? Or is it F:\master.txt? Please give the real name.
What is the root folder where all txt files have to be replaced?

With that info I can make a script
My System SpecsSystem Spec
17 Sep 2014   #5
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

Code:
@echo off
for  /R  F:\  %%i  in  (*.txt)  do  echo  copy "F:\master"  "%%i"
pause
Put in bat file. Replace D:\ with actual root of txt files to replace. Replace f:\master with actual template file.
Run it (it shows what it does). all is fine? if so... remove the word echo and run for the real work
My System SpecsSystem Spec
17 Sep 2014   #6
ron7000

Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
 
 

thanks.

yes 'F:\master' was the actual name i was going with.

I used the .txt file suffix as an example, I need to do various files but the principle is all the same. The big thing is i don't know the file name before the suffix, and i don't know the names of the subfolders or how many subfolders there are.
My System SpecsSystem Spec
17 Sep 2014   #7
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

Quote   Quote: Originally Posted by ron7000 View Post
thanks.

yes 'F:\master' was the actual name i was going with.

I used the .txt file suffix as an example, I need to do various files but the principle is all the same. The big thing is i don't know the file name before the suffix, and i don't know the names of the subfolders or how many subfolders there are.
Try my script as a test. Is that what you want?
My System SpecsSystem Spec
17 Sep 2014   #8
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

F:\master ...hmmm so a file without an extension?
My System SpecsSystem Spec
17 Sep 2014   #9
ron7000

Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
 
 

yes, without the extension. Or make it whatever you like, whatever's easiest to write the script. I'm copying some file that i need which has whatever name and calling it 'master' for sake of simplicity. And it's that file I want to copy to all subfolders and replace every file that has a given suffix (i used .txt). But i don't want to change the copy destination filename, just the contents of the file.


it looks like either one will do it. not sure if i'll get to it today,
i'll respond tomorrow or as soon as i get a chance to try it out.
thanks again.
My System SpecsSystem Spec
17 Sep 2014   #10
Kaktussoft

Microsoft Community Contributor Award Recipient

Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
 
 

what is the root folder of all txt files to replace? Is it f:\ ?
My System SpecsSystem Spec
Reply

 help scripting way to copy/rename one file to subfolders




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Won't let me rename or copy files
I decided to try some themes and the one I installed I didn't really like it so I decided to go an uninstall it. I restored my backup explorer.exe but then delete the one from the theme but it wouldn't let me. It didn't give me any errors. It showed the screen with the progress bar of it being...
General Discussion
'Rename' box doesn't show up when I rename a file shortcut
So basically (I'll try to be descriptive), I have an Excel file (extension xlsm) on my USB and I right click it, send to --> desktop (create shortcut). I see the shortcut. I right click and attempt to rename it with a different file extension, but the 'Rename' box doesn't show up like I believe it...
General Discussion
How to copy and rename Language in Windows 7?
English is spoken all over the world. Windows have option of EN (US), EN (UK), EN (IN) etc, I want to copy EN (UK) and rename it with my own country's format (currency, date & time styles etc) as EN (PK)* Can anyone help me how can I do this? *Pakistan
Installation & Setup
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
I want to Copy & Rename, not Copy & Replace
When I drag a file into a folder that has a similarly named file, I am asked to either "Copy and Replace" or "Don't Copy". I would love it if there was a third option "Copy and Rename". I would get so much done so much faster. I'm hoping there is some kind of registry tweak I can do to get...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 06:54.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App