1.

Solve : If Copy Batch File Help?

Answer»

Hello, I need some assistance in making a batch file. I need the file to check if a file exists in a location, if it does I need it to be renamed, and then copy a target file to that same directory. It has to look at a few directories, but I should be able to write that in after the fact.

Thank you!Can you list file names and target locations so we SEE the whole picture to then be able to suggest code example

such as

C:\Data\Job1\Listings.doc
C:\Project\Project3\Schedule.xls
C:\Business\Dcoument1.doc

so we know target names and locations that you need to target for this.Sure thing:

C:\Program FILES (x86)\folder1\inv.rpt
C:\Program Files\folder1\inv.rpt
C:\folder1\inv.rpt

copy "%~dp0\inv.rpt" to those directories. (this should copy inv.rpt from the same level of the batch file if i'm doing this correctly).
So the file is ALWAYS inv.rpt or you have other file names as well?

Your example of

C:\Program Files (x86)\folder1\inv.rpt
C:\Program Files\folder1\inv.rpt
C:\folder1\inv.rpt

suggests its always the same target file nameQuote from: fdskl on November 17, 2015, 08:45:14 AM

Hello, I need some assistance in making a batch file.

Is it assistance you need, or do you want the script written?

Quote
I need the file to check if a file exists in a location, if it does I need it to be renamed, and then copy a target file to that same directory. It has to look at a few directories, but I should be able to write that in after the fact.

If you want a working script then details about the task are needed.

I would suggest you look up the semantics of the CMD.EXE CALL :label [args] command extension. Using this, you could create a "function" which would expect a source and destination path, and if the file already exists at the destination, rename it then copy. Then you can call this function for each source/destination combo you need. I just gave a similar script in this topic: Move script file to users adobe folderIt will always be the same file name in this case. I'm just trying to copy over a report file that serves as a template, but the problem is that the program has been installed at different directories and as far as I know there isn't an environment variable for me to use. I'm a bit lackluster in scripting so I was hoping for some code I can try to make sense of. Casteele's example in the other post is a bit confusing for me. Please let me know if there are any more details I can provide, I'm not intentionally trying to be vague.Quote from: fdskl on December 01, 2015, 06:50:27 AM
It will always be the same file name in this case.

That makes it easier.

Quote
I'm just trying to copy over a report file that serves as a template, but the problem is that the program has been installed at different directories

And where are these folders, and what are they called?

Quote
I was hoping for some code I can try to make sense of.

It'll be a piece of cake when we have some details that we can make sense of.

Quote from: foxidrive on December 03, 2015, 03:03:15 AM

And where are these folders, and what are they called?


Post #3 has that information.Quote from: fdskl on December 03, 2015, 12:54:21 PM
Post #3 has that information.

Post #3 has bogus information though. You MAY like to consider the thought that you're asking for exact code to solve a problem, and giving details that are inexact.

If you gain experience in solving problems for other people then you will understand how often you have to change the code you have already provided (free of charge), because the details you were given were wrong, or information was withheld.

C:\Program Files (x86)\nise\inv.rpt
C:\Program Files\nise\inv.rpt
C:\nise\inv.rpt

copy "%~dp0\inv.rpt"

There's the exact paths, hope that adds some clarity. Thank you for your patience.


Discussion

No Comment Found