# Bat script to find and replace file in multiple subfolders



## manoruz (Nov 8, 2012)

Hello Everyone

I've searched the forums for an answer specific to my current problem but can't seem to find the proper thing so sorry for opening a new thread (noob)

I need to create a bat file that will scan multiple folders on my second harddrive D:\- find a file called renamed1.sin - delete it and replace it with a similar file I already have which is smaller in size and has different attributes i.e read only
The folder structure for the intended file is like this -
User\documents\rmdw 13\command0\renamed1.sin

so the batch file would need to scan d:\ - find all instances of renamed1.sin - delete it and replace it with another renamed1.sin which is smaller and real only.

Any help will be greatly apprecaited


----------



## FordGT90Concept (Nov 8, 2012)

Basically what you need to use is:
for /r %%i in (renamed1.sin) do xcopy "%%i" "source file" /u /k

xcopy may require some more tweaking. Documentation here:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true

Might have to do *renamed1.sin instead of renamed1.sin too if it doesn't find anything.


----------

