help scripting way to copy/rename one file to subfolders

Page 1 of 2 12 LastLast

  1. Posts : 90
    Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
       #1

    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 Computer


  2. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #2

    So you want all TXT files inside a folder (and its subfolders) to be replaced by master?
    why?
      My Computer


  3. Posts : 1,049
    Windows 7 Pro 32
       #3

    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 Computer


  4. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #4

    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 Computer


  5. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #5

    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
    Last edited by Kaktussoft; 17 Sep 2014 at 15:17.
      My Computer


  6. Posts : 90
    Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
    Thread Starter
       #6

    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 Computer


  7. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #7

    ron7000 said:
    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 Computer


  8. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #8

    F:\master ...hmmm so a file without an extension?
      My Computer


  9. Posts : 90
    Windows 7 x64, ultimate/pro/home, SLES x86 & ia64
    Thread Starter
       #9

    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 Computer


  10. Posts : 10,796
    Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
       #10

    what is the root folder of all txt files to replace? Is it f:\ ?
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 10:36.
Find Us