MSFN Forum: Batch Help (Before i pull my hair out) - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Batch Help (Before i pull my hair out) Rate Topic: -----

#1 User is offline   Ruddzy 

  • Group: Members
  • Posts: 1
  • Joined: 15-March 12
  • OS:none specified
  • Country: Country Flag

Posted 15 March 2012 - 01:15 PM

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

Quote

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

Quote

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


any help would be more than appreciated

cheers

This post has been edited by Ruddzy: 15 March 2012 - 01:16 PM



#2 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,447
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 15 March 2012 - 02:37 PM

View PostRuddzy, on 15 March 2012 - 01:15 PM, said:


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:

Quote

dir "yourpath\*.avi"

then try again with:

Quote

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.robvander...e.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:

Quote

@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

This post has been edited by jaclaz: 15 March 2012 - 02:38 PM


#3 User is offline   CoffeeFiend 

  • Coffee Aficionado
  • Group: Super Moderator
  • Posts: 5,399
  • Joined: 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 15 March 2012 - 03:02 PM

A quick powershell one-liner, for anyone who might be interested:

ls C:\somepath\ | ? { $_.Length -lt 20MB } | rm


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy