converting command to batch

ddfh72

Honorable
Mar 28, 2016
3
0
10,510
The following command works on the command line to run drivecleanup.exe, which is situated in C:\Uninstalled ProgramFiles\drivecleanup090\Win32, and to send the output to a log file:
cd C:\Uninstalled Program Files\drivecleanup090\Win32

C:\Uninstalled Program Files\drivecleanup090\Win32\drivecleanup -T >> C:\Temp\drivecleanup.log But it does not work in a batch file. Could somebody please point out to me where I am going wrong?
 
Solution
There are spaces in the directory structure so you have to use quotation marks:

"C:\Uninstalled Program Files\drivecleanup090\Win32\drivecleanup" -T >> C:\Temp\drivecleanup.log

ddfh72

Honorable
Mar 28, 2016
3
0
10,510


Thanks - spot on. It works now.

I thought I had tried quote marks because of the spaces and found they did not work - perhaps I put one of them in the wrong place.

Perhaps they should also be used for the cd command, but I have found that the script works as well without it, so I have no way of ascertaining whether quotes there make a difference. When I used the command line, quotes were not needed for either the cd command or the main command to run drivecleanup. So, is it the case that quotes are only needed in a batch file, and that the cd command is only needed on the command line where the .exe file is not in the windows system 32 folder?
 

Samat

Distinguished


If you run it from the command line it should work without the quotes (it will automatically add quotes in command line if you use tab to complete lines for directories/filenames with spaces). And yeah there is no need to change the directory if you already give the file location in the batch (this is better practise anyway and keeps the batch file clean if you have multiple entries).