Jump to content

Batch Help (Before i pull my hair out)


Recommended Posts

gday folks, trying to delete all avi's under 20mb

if ive got a .exe with this code in the same folder as the avi's it works fine

for /f "usebackq delims=;" %%A in (`dir /b *sample*.avi`) do If %%~zA LSS 20971520 del "%%A"

however when i try and get a bit more inventive, and try the code below, all i get is windows cannot find the path

for %%A in ('dir "%directory%\*.avi"') do If %%~zA LSS 20971520 del "%%A"

any help would be more than appreciated

cheers

Edited by Ruddzy
Link to comment
Share on other sites


however when i try and get a bit more inventive ....

It's not about being inventive, it's about not knowing some command syntax/not experimenting on command line. :ph34r:

Try executing in a command prompt:

dir "yourpath\*.avi"

then try again with:

dir /b "yourpath\*.avi"

DIr (without /b ) will have a "type" of output (NOT compatible with using the %%A variable), Dir /b will have another "type" of output.

And, in any case, you cannot remove the /F in the FOR command!

Read:

http://www.robvanderwoude.com/ntfor.php

And, additionally the ~z won't work with "different from current" path. :unsure:

In your posted example, what you want is most probably a .cmd (AND NOT a .exe) like:

@ECHO OFF

SETLOCAL ENABLEEXTENSIONS

....

.....

PUSHD %directory%

FOR /F %%A in ('DIR /B "*.avi"') DO IF %%~zA LSS 20971520 ECHO DEL "%%A"

POPD

the ECHO is there just to "protect the innocents" ;).

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...