Ampersand in a Batch file

December 14, 2010 at 10:13:27
Specs: Windows XP Professional SP3, Dual P4 2.8Gz/1Gb
Can't seem to find the answer that helps me

why does this work when typed at a command prompt:

Z:\"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

but when it is included in a batch file like this:

"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

"The specified path cannot be found" where the path is listed as:

\\Centralsrv1\marketng\R

Obviously a "&" issue, but I can't get around it.....

Any help?


See More: Ampersand in a Batch file

Report •

#1
December 14, 2010 at 10:21:57
http://cypressor.twoday.net/stories...

Have you tried moving the quotes to\\"Centr....

"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.exe" \\"Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"


Report •

#2
December 14, 2010 at 11:12:43
Moving the " as per your suggestion return:

Excel opens, then returns a error message:

'\\"Centralsrv1\marketng\R.xls' could not be found.

after clicking OK:

'&.xls' could not be found.

after clicking OK:

'\D\Excel\Instants\IG.xls' could not be found.

after clicking OK:

'Reports\IGmaster.xls" could not be found.

and the batch file terminates.

The link you provided, which containing a HUGE amunt of info, has throughly confused me....



Report •

#3
December 14, 2010 at 11:53:10
I too found it a bit confusing....had to read it 3 times.
Well if excell started then
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.exe" is good

if '\\"Centralsrv1\marketng\R.xls' cannot be found then neither will the rest.
so the error is in that line.
the double \\ comes to mind.

\"Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

Not having all those dirs and files makes to hard to test on this end


Report •

Related Solutions

#4
December 14, 2010 at 12:06:22
worldlibrary: the double \\ comes to mind.
The double backslashes denote a network path. With a name of "central[ ]srv[er]1," it's probably some file server.

If it's only this file, go with:

start "" excel "\\Centralsrv1\marketng\R ^& D\Excel\Instant\IG Reports\IGmaster.xls"

How To Ask Questions The Smart Way


Report •

#5
December 14, 2010 at 12:41:16
and so it continues....closer but not there yet....using:

start "" excel "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

returns and error in the command prompt window:

\\Centralsrv1\marketng\R can't be found but excel opens (with a message that personal.xls is locked for editing since other excel files areprocessing). Upon choosing read only, the IGmaster file processes....

This is the entire text of the batch file: Everything but the IGMaster part runs fine..

@echo off
echo ***********************************>>scheduled_tasks.log
echo. >>scheduled_tasks.log
echo Daily_Inventory_Update.bat started >>scheduled_tasks.log
echo on %ComputerName% on %date% at %time% >>scheduled_tasks.log
echo Logged on as %UserName%>>scheduled_tasks.log
echo. >>scheduled_tasks.log

echo Killing any instances of Excel that are currently>>scheduled_tasks.log
echo running on %date% at %time% >>scheduled_tasks.log

TASKKILL /F /IM excel.exe /FI "STATUS ne RUNNING">>scheduled_tasks.log

echo. >>scheduled_tasks.log

rem Check if files to update are accessible

if exist "\\Lotftp1\Marketing\V8325.doc" goto :V8325_Online
goto :V8325_Offline

:V8325_Online
echo Processing \\Lotftp1\Marketing\V8325.doc on %date% at %time% >>scheduled_tasks.log
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Lotftp1\Marketing\V8325.doc">>scheduled_tasks.log
echo DONE>>scheduled_tasks.log

if exist "\\Lotftp1\Marketing\V8328SHP.csv" goto :V8328SHP_Online
goto :V8325SHP_Offline

:V8328SHP_Online
echo Processing \\Lotftp1\Marketing\V8328SHP.csv on %date% at %time% >>scheduled_tasks.log
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Lotftp1\Marketing\V8328SHP.csv">>scheduled_tasks.log
echo DONE>>scheduled_tasks.log

if exist "\\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls" goto :PromoInvMaster_Online
goto :PromoInvMaster_Offline

:PromoInvMaster_Online
echo Processing \\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls on %date% at %time% >>scheduled_tasks.log
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls">>scheduled_tasks.log
echo DONE>>scheduled_tasks.log
echo Copying \\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls on %date% at %time% >>scheduled_tasks.log
copy "\\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls" "\\centralsrv1\marketng\Marketing Specialists\PromotionProgramAide\Promo Inventory Master.xls" /y>>scheduled_tasks.log
echo DONE>>scheduled_tasks.log

if exist "\\Centralsrv1\marketng\Marketing Specialists\Subway Inventory Master List.xls" goto :SubwayInvMaster_Online
goto :SubwayInvMaster_Offline

:SubwayInvMaster_Online
echo Copying \\centralsrv1\marketng\Marketing Specialists\Subway Inventory Master List.xls on %date% at %time% >>scheduled_tasks.log
copy "\\centralsrv1\marketng\Marketing Specialists\Subway Inventory Master List.xls" "\\centralsrv1\marketng\Marketing Specialists\PromotionProgramAide\Subway Inventory Master List.xls" /y>>scheduled_tasks.log
echo DONE>>scheduled_tasks.log

if exist "\\centralsrv1\marketng\Marketing Specialists\Updated Inventory.xls" goto :UpdatedInv_Online
goto :UpdatedInv_Offline

:UpdatedInv_Online
echo Copying \\centralsrv1\marketng\Marketing Specialists\Updated Inventory.xls on %date% at %time% >>scheduled_tasks.log
copy "\\centralsrv1\marketng\Marketing Specialists\Updated Inventory.xls" "\\centralsrv1\marketng\Marketing Specialists\PromotionProgramAide\Updated Inventory.xls" /y>>scheduled_tasks.log
echo DONE>>scheduled_tasks.log

if exist "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls" goto :IGMaster_Online
goto :IGMaster_Offline

:IGMaster_Online
echo Processing \\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls on %date% at %time% >>scheduled_tasks.log
rem "C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls">>scheduled_tasks.log
start "" excel "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

echo DONE>>scheduled_tasks.log

if exist "\\Lotftp1\Marketing\V8323INV.csv" goto :V8323Inv_Online
goto :V8323Inv_Offline

:V8323Inv_Online
echo Processing \\Lotftp1\Marketing\V8323INV.csv on %date% at %time% >>scheduled_tasks.log
"C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" "\\Lotftp1\Marketing\V8323INV.CSV">>scheduled_tasks.log
echo DONE>>scheduled_tasks.log
echo Copying \\centralsrv1\marketng\Marketing Specialists\V8323inv.xls on %date% at %time% >>scheduled_tasks.log
copy "\\centralsrv1\marketng\Marketing Specialists\V8323inv.xls" "\\centralsrv1\marketng\Marketing Specialists\PromotionProgramAide\V8323inv.xls" /y>>scheduled_tasks.log
echo DONE>>scheduled_tasks.log
goto :end

:offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access the file on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:V8325_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\Lotftp1\Marketing\V8325.doc
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:V8325SHP_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\Lotftp1\Marketing\V8328SHP.csv
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:PromoInvMaster_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\centralsrv1\marketng\Marketing Specialists\Promo Inventory Master.xls
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:SubwayInvMaster_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\centralsrv1\marketng\Marketing Specialists\Subway Inventory Master.xls
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:UpdatedInv_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\centralsrv1\marketng\Marketing Specialists\Updated Inventory.xls
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:IGMaster_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end

:V8323Inv_Offline
echo.>>scheduled_tasks.log
echo %ComputerName% could not access \\Lotftp1\Marketing\V8323INV.csv
echo on %date% at %time% >>scheduled_tasks.log
echo.>>scheduled_tasks.log
goto :end


:end
echo. >>scheduled_tasks.log
echo Daily_Inventory_Update.bat ended on %date% at %time% >>scheduled_tasks.log
echo. >>scheduled_tasks.log
echo ***********************************>>scheduled_tasks.log
echo. >>scheduled_tasks.log
exit


Report •

#6
December 14, 2010 at 13:16:45
Razor2.3

worldlibrary: the double \\ comes to mind.
The double backslashes denote a network path. With a name of "central[ ]srv[er]1," it's probably some file server.

That makes sense... thank you.


Report •

#7
December 14, 2010 at 13:41:21
start "" excel "\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

returns and error in the command prompt window:

Great, but I said use
start "" excel "\\Centralsrv1\marketng\R ^& D\Excel\Instant\IG Reports\IGmaster.xls"

How To Ask Questions The Smart Way


Report •

#8
December 15, 2010 at 05:45:26
uhhh...duh....my bad sorry.....
OK, So I :: the IGMaster section and added the CORRECT line at the end of the batch file-right before the exit line. Excel opens, but an error message:
"\\Centralsrv1\marketng\R ^& D\Excel\Instant\IG Reports\IGmaster.xls" cannot be found. Click OK. Close excel. Batch file terminates. Checked the log file and no entry appears for this line.....

Report •

#9
December 15, 2010 at 09:07:36
I feel sooooo stupid....but at least i never gave up!!!!

set var="\\Centralsrv1\marketng\R & D\Excel\Instant\IG Reports\IGmaster.xls"

if exist %var% goto :IGMaster_Online
goto :IGMaster_Offline

:IGMaster_Online
echo Processing %var% on %date% at %time% >>scheduled_tasks.log
start "" excel %var%>>scheduled_tasks.log
echo DONE>>scheduled_tasks.log
goto :end


Report •

#10
December 15, 2010 at 14:49:55
As Razor2.3 said;

Use ^& instead of only &

set var="\\Centralsrv1\marketng\R ^& D\Excel\Instant\IG Reports\IGmaster.xls"

etc..

Happy is ONE who says I am an OttoMAN.


Report •

Ask Question