/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (2)

Posted by: anonymous_9363 15 years ago
Red Belt
0
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.
Posted by: PatrickMc 15 years ago
Yellow Belt
0
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.


# 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.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ