6

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 and pushd, but if I try pushd in cmd.exe it runs just fine. I'm sure I'm missing something simple.

Any ideas?

3
  • 1
    What error do you start getting? Jul 28, 2013 at 16:59
  • At @echo off and pushd. i get " the system cannot find the file specified" , when it gets to the loop, it closes the cmd window..
    – user241447
    Jul 28, 2013 at 17:17
  • I got it, it was the comments at the side that I had left in were causing the hiccup
    – user241447
    Jul 28, 2013 at 18:46

1 Answer 1

8

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .