Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-07
25
Medium Priority
?
410 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:street9009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 5
  • +1
25 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 24326152
That should be feasible with a single move command:

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

0
 

Author Comment

by:street9009
ID: 24326262
But does that get the file size requirement? I'm pretty sure it does not.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 1600 total points
ID: 24326431
You can do that with robocopy and the /MAX:n switch, for example to only move (/MOV) files smaller than 10MB:
robocopy "S:\ource\folder" "T:\arget\folder" *.* /max:10000000 /mov
The ResKit tools are here; check robocopy.doc in the installaiton folder for details, it's a pretty powerful tool:
Download details: Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 71

Expert Comment

by:Qlemo
ID: 24326577
You didn't tell us your match criteria before. With size or date restriction, robocopy is a good choice.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 24326868
Isn't "Batch File to Move Files in Directory that are specific size or less" in bold font telltale enough?
Yes, SCNR and such ...
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24326880
Ah, I should read the title, too ...
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24328545
Qlemo
You gonna give this one a shot?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24328602
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.
0
 

Author Comment

by:street9009
ID: 24328635
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.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24328648
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

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24328655
Robocopy is integrated with Vista and above.
0
 

Author Comment

by:street9009
ID: 24328741
When I tried to install the Resource Kit you linked to, it gave me a compatibility error.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24328763
64bit system?
0
 

Author Comment

by:street9009
ID: 24328786
Nope. 32 bit.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 24328875
Installs fine on XP and Vista. Vista shows a compatibility warning (no error), which is related to some of the tools included, but not the Kit itself.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 24328881
Vista? As Qlemo said, this already has a newer version of robocopy on it by default, with a bit more options.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24328926
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%\"
)

0
 

Author Closing Comment

by:street9009
ID: 31578999
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!
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24330188
Oh, so you decided to use an external third-party program instead then - rather than a batch file?

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24330224
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.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24330389
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!
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24330567
DOS 6.2 is a no-go for Windows users. Imagine - no PowerShell! And what would you do without for /F?
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24330640
Qlemo
I've got a question to ask you? How do I contact you 'away' from this thread?

FOR /F ????? ........ QBASIC!!!!
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 24330911
t0t0, some hints are in my profile (now).
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24330949
i thnk i've cracked it.....
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question