Batch file gives "the system cannot find the file specified" but commands run fine in cmd
This happens when you use a program to start your batch file and the batch file isn't calling cmd.exe /c
first. There's no pushd.exe
, it's a built-in command under cmd.exe
. But when your program calls your batch file, it's starting it directly - there's no cmd.exe
. (Yes, this is weird.)
The solution: Wherever you're running this from, precede it with cmd.exe /c
So if you're running deletelittlefiles.bat
change it to cmd.exe /c deletelittlefiles.bat
.
Source: I'm a lab manager for a software testing team and our test harness can but doesn't have to run things without starting them under cmd.exe
.
Related videos on Youtube
user241447
Updated on September 18, 2022Comments
-
user241447 over 1 year
I'm trying to run a simple batch file:
@echo off <-- don't print this line or any of the preceeding lines to the console window. pushd "K:\" <-- in the quoted directory for %%j in (*) <-- for every file in the directory do if %%~zj <-- if the size of the file lss 37000 <-- is less than 37k del %%j <-- delete the file popd <-- go back to original directory.
I start getting an error at the
@echo off
andpushd
, but if I trypushd
incmd.exe
it runs just fine. I'm sure I'm missing something simple.Any ideas?
-
user1686 almost 11 yearsWhat error do you start getting?
-
user241447 almost 11 yearsAt
@echo off
andpushd
. i get " the system cannot find the file specified" , when it gets to the loop, it closes the cmd window.. -
user241447 almost 11 yearsI got it, it was the comments at the side that I had left in were causing the hiccup
-