Link to home
Start Free TrialLog in
Avatar of street9009
street9009Flag for United States of America

asked on

Batch File to Move Files in Directory that are specific size or less

I am looking for a batch file that will search a particular directory (not recursive, so if there are any directories within the specified directory, leave them alone), and move each file that matches to a different directory so I can review them and then more than likely delete them.

Any ideas for how to do this?
Avatar of Qlemo
Qlemo
Flag of Germany image

That should be feasible with a single move command:

move  C:\sourcedir\*.log  c:\targetdir\

Avatar of street9009

ASKER

But does that get the file size requirement? I'm pretty sure it does not.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You didn't tell us your match criteria before. With size or date restriction, robocopy is a good choice.
Avatar of oBdA
oBdA

Isn't "Batch File to Move Files in Directory that are specific size or less" in bold font telltale enough?
Yes, SCNR and such ...
Ah, I should read the title, too ...
Qlemo
You gonna give this one a shot?
Everyhing said by oBdA already. I could construct a solution like you, t0t0 are keen on, with normal batch means, but if there are such good tools like robocopy, it's a too much of time spent for nothing.
All that said, is there a version of the Resource Kit for Vista with Robocopy in it? I have XP machines I can load this on, but primarily work on Vista these days.
Ok, I'll do nevertheless, just to keep my fingers in motion:

@echo off
 
set size=100000
for %%F in (C:\Sourcedir\*) do if %%~sF LEQ %size% move %%F c:\DestDir

Open in new window

Robocopy is integrated with Vista and above.
When I tried to install the Resource Kit you linked to, it gave me a compatibility error.
64bit system?
Nope. 32 bit.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Vista? As Qlemo said, this already has a newer version of robocopy on it by default, with a bit more options.
Would the following do the trick?

(you can edit in your own source and destination foldernames as well as the filespec and size)


@echo off

set Size=10
set FileType=*.*
set SourceFolder=C:\Temp\Source
set DestinationFolder=C:\Temp\Destination

for %%a in ("%SourceFolder%\%FileType%") do (
   if %%~za leq %Size% move /y "%%~dpnxa" "%DestinationFolder%\"
)

I've got Robocopy downloaded and installed. Going to read through the documentation and all to see how it works, but I won't hold this question open while I learn it. Looks like it'll solve several issues I'm having to deal with.

Thanks for the tip!
Oh, so you decided to use an external third-party program instead then - rather than a batch file?

t0t0,

"Looks like it'll solve several issues" is the key phrase here, I think ... street didn' tell us all his problems, obviously. And please keep in mind, robocopy is no third-party tool, it is from Microsoft, and since Vista part of the OS distribution.
Qlemo
Didn't realise it was part of that horrible vista thing.... anyway, i'm thinking of going back to Windows 3.1, just for the fun of it!!! Things were simpler then. I wonder if Robocopy will run under DOS 6.2?

I suppose one could liken Robocopy to the Wonder-drug of the 60's - Vallium.

I must make a point of down;oading it one day and checking it out for myself..... I'm firghtened it might render some of my programming skills redundant though.

Bring back the old-fashioned typewriter - that's what I say!
DOS 6.2 is a no-go for Windows users. Imagine - no PowerShell! And what would you do without for /F?
Qlemo
I've got a question to ask you? How do I contact you 'away' from this thread?

FOR /F ????? ........ QBASIC!!!!
t0t0, some hints are in my profile (now).
i thnk i've cracked it.....