Create a script to read a line in excel and place on CMD

Question:

Soo, i’m a IT Intern in a Company, and we need to transfer some data from a server to another by CMD commands like: "C:/Source" "D:/Target" /commands ….
And we are doing that to move from a old server to a new one and make some space on the Disk to use for something else.

The problem is there like 2000 lines of directory on Excel to do that, and doing that manually gonna take ALOT of time and me and the other team have more stuff to do, i was wondering if i can create a automatic script to read the line on excel and do that line by line to save ALOT of time.
Like changing the "Source" and "Target" inputs but keeping the other commands after.

Thank alot!!!

Asked By: Fcordis

||

Answers:

Assuming you have a list of the source directories in column A of your spreadsheet, then you could use an Excel formula such as the following in column B (or wherever you want to place it):

=CONCAT("robocopy ", """", A1, """", " ", """", "G", RIGHT(A1, LEN(A1) -1), """", " /s /e /copyall /xo")

Four double-quotes in a row result in one double-quote being generated as output.

The formula RIGHT(A1, LEN(A1) -1) simply trims the leading E (directory) from the path, so it can be replaced with the target G.

If A1 contains E:FileExample then my formula generates the output:

robocopy "E:FileExample" "G:FileExample" /s /e /copyall /xo

Copy that formula down for as many rows as you need, then copy/paste the results to a text file (you may need to use paste-special to paste the resulting text, not the formula.

Rename the text file so it has a .bat file extension, so it is runnable from a CMD prompt. I would test the batch file with a very small number of commands first of all.


This approach is fine, I would say, for a one-time (or few-times) exercise. If you were doing this many times, then yes an automated (Java, Python, etc.) approach may make more sense.


Update:

For your updated comment below, the relevant formula would be very similar to the one I provided above:

=CONCAT("robocopy ", """E:apl_cad", A1, """", " ", """\ara1app2ENG3PROTEÍNASOldVersions", A1, """", " /s /e /copyall /xo")

If A1 contains X then the formula generates the following:

robocopy "E:apl_cadx" "\ara1app2ENG3PROTEÍNASOldVersionsx" /s /e /copyall /xo

You can place that formula wherever you like – but make sure you adjust the cell references to A1 so they match wherever the actual X data is located.

Answered By: andrewJames
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.