Batch script to find and overwrite file
Hi
Can anybody help me with the script of first finding and then overwriting a file.I need only the batch script.
thanks
Can anybody help me with the script of first finding and then overwriting a file.I need only the batch script.
thanks
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
Using DOS tools to do this job would be tortuous, to say the least. Off the top of my head, you'd need to pipe the output from 'DIR /S' to a file, then use 'FIND' to extract the path, somehow passing that text to COPY. [shudder]
You would be much better off using VBScript or PowerShell. There are many, many examples on recursively walking a folder tree, which you could then adapt for your purposes.
You would be much better off using VBScript or PowerShell. There are many, many examples on recursively walking a folder tree, which you could then adapt for your purposes.
Posted by:
PatrickMc
15 years ago
I agree with VBScab. It will be much easier (and more manageable) to do with a scripting language.
I like VBScript, but for something like this, I would use a simple biterscript. I will write a quick script for you. I will assume the file you are looking for is X.ext, it is burried somewhere in folder "C:/folder" or its subfolders, and you want to replace it with C:/Y.ext.
To try, download biterscripting ( http://www.biterscripting.com ) , save the above script as C:\scripts\replace.txt, start biterscripting, enter the following command.
Use double quotes if any of these file/path names contains spaces or other special characters. I have not tested the script.
Patrick
I like VBScript, but for something like this, I would use a simple biterscript. I will write a quick script for you. I will assume the file you are looking for is X.ext, it is burried somewhere in folder "C:/folder" or its subfolders, and you want to replace it with C:/Y.ext.
# Script replace.txt
var str list ; lf -rn "X.ext" "C:/folder" > $list
var str file ; lex "1" $list > $file
system copy "C:/Y.ext" $file
To try, download biterscripting ( http://www.biterscripting.com ) , save the above script as C:\scripts\replace.txt, start biterscripting, enter the following command.
script replace.txt
Use double quotes if any of these file/path names contains spaces or other special characters. I have not tested the script.
Patrick
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.