Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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?

share|improve this question
What error do you start getting? – grawity Jul 28 '13 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 '13 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 '13 at 18:46

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.

share|improve this answer

You must log in to answer this question.

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