Scripted process to move if size > x

W

Wowbagger

Is there a quick and easy way to sort through all files within a directory
structure and move (not copy) all files with size > 150kb to another
directory? I need to compress several thousand photos down to a smaller
size but it takes too long to move by hand. (Once I get them all into
another directory I have a batch file resizer). Finding them is easy
enough, but even with 1Gb of RAM I can't cut/paste with any semblance of
efficiency.

Thanks
 
R

Rock

Wowbagger said:
Is there a quick and easy way to sort through all files within a directory
structure and move (not copy) all files with size > 150kb to another
directory? I need to compress several thousand photos down to a smaller
size but it takes too long to move by hand. (Once I get them all into
another directory I have a batch file resizer). Finding them is easy
enough, but even with 1Gb of RAM I can't cut/paste with any semblance of
efficiency.

Thanks

Start | Search allows you to search for files of a specific minimum
size. Once you locate them in the search window select all, right
click, move to folder.
 
W

Wowbagger

Rock said:
Start | Search allows you to search for files of a specific minimum size.
Once you locate them in the search window select all, right click, move to
folder.

Yeah... I was trying that but I have over 4,000 photos to move and windows
slows to a crawl (to the point of seeming to lock up). I was hoping for
something that works a bit more in the background.
 
F

Frank Saunders, MS-MVP OE

Wowbagger said:
Is there a quick and easy way to sort through all files within a
directory structure and move (not copy) all files with size > 150kb
to another directory? I need to compress several thousand photos
down to a smaller size but it takes too long to move by hand. (Once
I get them all into another directory I have a batch file resizer).
Finding them is easy enough, but even with 1Gb of RAM I can't
cut/paste with any semblance of efficiency.

Thanks

If they are JPG files you are not going to be able to compress them much
more. JPEG is already a compressed format.

--
Frank Saunders, MS-MVP OE
Please respond in Newsgroup. Do not send email
http://www.fjsmjs.com
Protect your PC
http://www.microsoft.com/security/protect/
 
B

billious

Wowbagger said:
Yeah... I was trying that but I have over 4,000 photos to move and windows
slows to a crawl (to the point of seeming to lock up). I was hoping for
something that works a bit more in the background.

Try a simple batch file:


@echo off
for /f %%i in ('dir /S/b/a-d %*\*.*') do if %%~zi GTR 150000 ECHO "%%i"
pause



Simply supply the batch with a folder name either by running

batchfilename foldername

from the "DOS prompt" or the RUN box

or drop your folder name onto the batch file.

Note: the above batch will only SHOW the filenames > 150000 bytes.

When you've verified that the filename-selection is OK, replace
ECHO "%%i"
with
MOVE "%%i" "destinationfoldername"

the PAUSE is there simply to show the screen-report from the batch. Pressing
ENTER when the batch is done will close the window. Remove the PAUSE when
you're satisfied it works correctly.

It might also be an idea to add a line directly after the @ECHO OFF line

MD "destinationfoldername" 2>nul

to ensure that the destination folder exists. The MD makes the folder and
the "2>nul" suppresses the error message generated should the destination
folder already exist.

If you want to get complicated about it, perhaps you'd care to visit
alt.msdos.batch.nt where batch techniques for NT/2K/XP are discussed.

HTH

....Bill
 
W

Wowbagger

If they are JPG files you are not going to be able to compress them much
more. JPEG is already a compressed format.

I have a couple of free utilities that will do a batch process and reduce
the quality - dropping quality down to 70% will often trim 40-60% off the
file size and for my purposes still leaves the photo usable.
 
W

Wowbagger

@echo off
for /f %%i in ('dir /S/b/a-d %*\*.*') do if %%~zi GTR 150000 ECHO "%%i"
pause

I tried this and the system sat there for several minutes before exiting the
script but it never displayed anything.
 
B

billious

Wowbagger said:
I tried this and the system sat there for several minutes before exiting
the script but it never displayed anything.

Hmm. Works perfectly for me. A little difficult to debug without looking
over your shoulder.

* it could require that the %*\*.* be in quotes, "%*\*.*"

Try making a new folder and copying in a few files that are larger and
smaller than the threshhold size. Then try this batch (run the batch from
the prompt)

for /f %%i in ('dir /S/b/a-d "\newfoldername\*.*" ') do if %%~zi GTR 150000
ECHO "%%i"

this should run in a flash, and without the @ECHO OFF it should also show
each file found and its size.
(you could also run this line directly from the prompt, but you'd need to
reduce each "%%" to "%")

HTH

....Bill
 
W

Wowbagger

for /f %%i in ('dir /S/b/a-d "\newfoldername\*.*" ') do if %%~zi GTR
150000 ECHO "%%i"

this should run in a flash, and without the @ECHO OFF it should also show
each file found and its size.
(you could also run this line directly from the prompt, but you'd need to
reduce each "%%" to "%")

I ran this from the prompt, changing "%%" to "%" and changing
"\newfoldername\*.*" to "pictest\*.*" and got several hundred lines of:

if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"

("x:\re dir" is the network directory in which pictest resides)
 
B

billious

Wowbagger said:
I ran this from the prompt, changing "%%" to "%" and changing
"\newfoldername\*.*" to "pictest\*.*" and got several hundred lines of:

if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"
if GTR 150000 ECHO "X:\RE"

("x:\re dir" is the network directory in which pictest resides)
Aha!

that little parenthetic note is the key...

try
@echo off
for /f "DELIMS=" %%i in ('dir /S/b/a-d "x:\re dir\pictest\*.*" ') do if
%%~zi GTR 150000 ECHO "%%i"

(which should list the filenames ONLY of files >150000 bytes)

and hence

@echo off
for /f "DELIMS=" %%i in ('dir /S/b/a-d %*\*.*') do if %%~zi GTR 150000 ECHO
"%%i"
pause

where %* is the entire command-tail (which I presumed to be a
directoryname.)
Naturally, you could replace the *.* with *.jpg (or whatever) to restrict
the filenames examined to just .jpg files, for instance. Or, if you wish,
simply specify a fixed full path, if that is your objective)

which you may develop to
[1]@echo off
[2]MD "destinationfoldername" 2>nul
[3]for /f "DELIMS=" %%i in ('dir /S/b/a-d %*\*.*') do if %%~zi GTR 150000
MOVE "%%i" "destinationfoldername"

to force the creation of the destinationfolder and then move the files.
(note lines begin [number]. Lines will be wrapped. You need to rejoin the
lines and remove the leading [number] to use the batch.)


===
%%i selects the first TOKEN in the line produced by the DIR.... command,
which would have the format
X:\RE dir\pictest\file1.jpg
X:\RE dir\pictest\file2.jpg ...

Note that if your current directory is [X:\RE dir] then specifying
[pictest\*.*] as your filemask actually examines [X:\RE dir\pictest\*.*] (or
[.\pictest\*.*]) - the directoryname is relative to the current directory.

inserting the ["delims="] overrides the default delimiters (which include
SPACE) with (no delimiters) [the character(s) between the [=] and the ["]
hence the entire line rather than the first token (X:\RE) will be selected
as %%i.

With %%i set to [X:\RE], %%~zi (the size of X:\RE) has no value as X:\RE is
not a file, and the command is resolved to IF GTR 150000.... since the value
of %%i is []

[] used to delimit elements in the discussion since single and double-quotes
have significance to batch.


HTH

....Bill
 
W

Wowbagger

Something still isn't quite working correctly: here is the batch file, cut
and pasted into this message:

for /f "DELIMS=" %%i in ('dir/S/b/a-d "x:\re test\*.*"') do if %%~zi GTR
150000 ECHO "%%i"
pause

When it runs, this is what appears on the screen:

X:\re test>for /F "DELIMS=" %i in ('dir/S/b/a-d "x:\re test\*.*"') do if
%~zi GTR 150000 ECHO "%i"

And nothing else until I either ^c out of the batch or allow it to finish
without it actually finding anything

If, however, I change the "x:\re test\*.*" to "x:\re test\j-l\*.*" it will
process the one directory appropriately - it just won't recurse into all of
the subdirectories off of x:\re test\
 
B

billious

Wowbagger said:
Something still isn't quite working correctly: here is the batch file, cut
and pasted into this message:

for /f "DELIMS=" %%i in ('dir/S/b/a-d "x:\re test\*.*"') do if %%~zi GTR
150000 ECHO "%%i"
pause

When it runs, this is what appears on the screen:

X:\re test>for /F "DELIMS=" %i in ('dir/S/b/a-d "x:\re test\*.*"') do if
%~zi GTR 150000 ECHO "%i"

And nothing else until I either ^c out of the batch or allow it to finish
without it actually finding anything

If, however, I change the "x:\re test\*.*" to "x:\re test\j-l\*.*" it will
process the one directory appropriately - it just won't recurse into all
of the subdirectories off of x:\re test\

It works fine for me, unfortunately. I cut your line and created a batch
file using Notepad; created a directory directly under the root of a drive,
named "re test", copied a few files into the directory, created a "j-l"
subdirectory and copied a few files there, too.

The batch ran as expected under both CMD.EXE and COMMAND.COM, with target
filespecs "X:\re test\*.*" and "X:\re test\j-l\*.*"

....Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top