Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Batch File Search and Replace a String

$
0
0

I've written a batch file to handle the copying of files.  I'm trying to reduce the number of parameters that I pass to the batch file.

I want the batch file to perform a string replace on the directory path that is passed as a parameter to the batch file.

Here is how I run the batch file:

COPY_FILE.BAT C:\DATA\FTP_DATA\ACME\IN      (I'm passing directory path "C:\DATA\FTP_DATA\ACME\IN" as parameter %1)

So my batch file will copy a file to the directory path represented by parameter %1.

But then I want the file copied to a second directory.  I want the batch file to replace string "FTP_DATA" in the directory path with string "FTP_DATA\ARCHIVE"

I know I could pass this path as a second parameter, but I want to limit the number of parameters so figured I could have the batch file perform a search and replace on string "FTP_DATA".

After searching the internet, I thought I found the answer by using the following command in the batch file:

set ARCHIVE_PATH=%1:FTP_DATA=FTP_DATA\ARCHIVE

But it doesn't perform a search and replace.  It just appends to the directory path with the following result:

C:\DATA\FTP_DATA\ACME\IN:FTP_DATA=FTP_DATA\ARCHIVE

What I want is the this:

C:\DATA\FTP_DATA\ARCHIVE\ACME\IN

Any suggestions?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>