views:

66

answers:

1

I have little to no experience in writing batch files.

I need to write one that copies a file to a new folder and renames it

At the moment, my batch file consists of only this command: COPY ABC.PDF \\Documents

As you can see, it only copies the file ABC.pdf to the network folder 'Documents'.

However i need to change this so it renames the file ABCxxx.pdf, where xxx is a text variable that i would like to set somewhere in the batch file.

For example, if xxx = "_Draft", then file would be renamed ABC_Draft.pdf after it is copied.

Thanks

A: 

Make a bat file with the following in it:

copy /y C:\temp\log1k.txt C:\temp\log1k_copied.txt

However, I think there are issues if there are spaces in your directory names. Notice this was copied to the same directory, but that doesn't matter. If you want to see how it runs, make another bat file that calls the first and outputs to a log:

C:\temp\test.bat > C:\temp\test.log

(assuming the first bat file was called test.bat and was located in that directory)

thursdaysgeek
ThanksIf i wanted to copy and rename all PDFs in that folder with the same text suffix, how would i do that?For example, if i have 2 pdfs ABC.PDF and ZYZ.pdf and i want to copy and rename them both to my 'Documents' folder' as ABCxxx.PDF and ZYZxxx.pdf, where "xxx" is the same text variable, how woudl i do that?
Estate Master
If you use copy /y C:\temp\*.PDF C:\tempcopy\*Copied.PDF, you won't quite get what you want, although it's in the right direction. Starting with files like ABC.PDF and DRE.PDF, I ended up with copies in that folder called ABCopied.PDF and DRE.PDFCopied.PDF. I'm not good with regular expressions, but I think something like that is what you need.
thursdaysgeek
Thanks. That worked
Estate Master