Batch file gives "the system cannot find the file specified" but commands run fine in cmd

54,245

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:
54,245

Related videos on Youtube

user241447
Author by

user241447

Updated on September 18, 2022

Comments

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

    Any ideas?

    • user1686
      user1686 almost 11 years
      What error do you start getting?
    • user241447
      user241447 almost 11 years
      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
      user241447 almost 11 years
      I got it, it was the comments at the side that I had left in were causing the hiccup