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

Working Batch Command Fails when passed to command line from VBA?

$
0
0

Hi Friends,

I have a great working snippet that copies files from/to the destinations inside a .csv:

for /f "tokens=1,2 delims=," %a in (xImageCopy.csv) do copy "%~a" "%~b"

In a cmd window, if I Chdir to the directory where the (xImageCopy.csv) lives, and enter the above code, it works great.
However, if I write it into a .bat file, it craps out and closes the cmd window ignoring my error handling, aaarrgh!

I know I have the correct path and filenames. I even tried adding the entire path to the .bat file like this:

for /f "tokens=1,2 delims=," %a in ("C:\Me\WasteMyLifeOn\StupidTests\xImageCopy.csv") do copy "%~a" "%~b"
To no avail.

Here is my batch code:

Chdir C:\
Chdir "C:\Me\WasteMyLifeOn\StupidTests\"
if %ERRORLEVEL% == 0 goto :next

for /f "tokens=1,2 delims=," %a in (xImageCopy.csv") do copy "%~a" "%~b" (FAILS MISERABLY)

for /f "tokens=1,2 delims=," %a in (C:\Me\WasteMyLifeOn\StupidTests\xImageCopy.csv") do copy "%~a" "%~b" (ALSO FAILS)
if %ERRORLEVEL% == 0 goto :batch

:batch
Echo Stupid thing failed yet again
PAUSE

:next
Echo Path not found, check reference cell
PAUSE

I did see some help with UNC, but I'm not sure what is causing a working script to break like this?

Any thoughts would be greatly appreciated!





Viewing all articles
Browse latest Browse all 15028

Trending Articles



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