View Single Post
  #2  
Old 05-16-2013, 01:24 PM
Phats Phats is offline
Kobold

Phats's Avatar

Join Date: Jul 2012
Posts: 115
Default

I dug this up.

This should do it, though it's probably not the cleanest method. Tests alright on my computer.

Code:
for /F "tokens=*" %P in ('dir /b /s myfile.txt') do copy /Y .\myfile.txt "%P"
If you're running it from a bat file use %%P instead of %P.
EDIT: I corrected the command to work with file paths that have spaces (notice the quotes around the last parameter). Also when running the command you'll always get this error:


Code:
The file cannot be copied onto itself.
.
Just ignore that, because it doesn't hurt anything

Here's a batch file version that I called subupdate.bat:

Code:
@echo off
if "%1"=="" GOTO End
for /F "tokens=*" %%P in ('dir /b /s %1') do copy /Y .\%1 "%%P"
:End
Then you can invoke it as such:


Code:
C:\root_dir_for_changes\subupdate.bat my_file_to_update.txt
The file cannot be copied onto itself.
        0 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
For a BAT file:

Q: Where do you input the file name? For instance, what would the code look like if the file you wanted to copy/replace was named "test.xml"?

A: If you're running it from the command prompt then CD into the root directory containing the most recent "test.xml". Then run the following command:

Code:
for /F "tokens=*" %P in ('dir /b /s test.xml') do copy /Y .\test.xml "%P"
If you're running it from a bat file then the bat file should contain:
Code:
for /F "tokens=*" %%P in ('dir /b /s test.xml') do copy /Y .\test.xml "%%P"
If you're using my subupdate.bat described in my first post then CD into the root directory containing the most recent "test.xml". Then run the following command:

Code:
Code:
subupdate.bat test.xml
Last edited by Phats; 05-16-2013 at 01:57 PM..
Reply With Quote