Copy file to paths from list

May 10, 2010 at 15:07:55
Specs: Windows 7 Ultimate x64, 4 GB
List.txt contains a list of paths.

It was made using: dir /s /b file.exe

I want to copy new file.exe to each path located inside list.txt file.

My goal is to replace old file.exe with newer verison.

Or, even better... How to copy file to each path dir /s /b file.exe returns.

See More: Copy file to paths from list

Report •

May 10, 2010 at 20:24:35
be sure to test with echos before doing a "live" run.

@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b /s file.exe') do copy /y \newver\file.exe %%~dpa

(test method - dry run)
@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b /s file.exe') do echo copy /y \newver\file.exe %%~dpa

Report •

May 11, 2010 at 06:33:17
@echo off

if "%1"=="" goto :EOF

set sourcefile=%1

for /f "tokens=*" %%f in ('dir C:\%sourcefile% /s /b') do (
echo xcopy "%sourcefile%" "%%f" /D

If sourcefile and targetfile happen to be the same, a copy would not occur since only newer files are copied. Sourcefile without whitespaces, or code change is needed.

Report •

May 13, 2010 at 15:09:47
Thank you both.

nbrane's version is the one I'm going to use since the file name is always the same, and it needs to be overwriten each time, despite it's newer or not.

I was wondering how to cut off the file name from path, and now I learned. :)

Once again, thank you.


Report •

Related Solutions

Ask Question