Solved

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

Posted on 2009-05-07
25
408 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 70

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 400 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 70

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 70

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 70

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 70

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 70

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 70

Expert Comment

by:Qlemo
ID: 24328763
64bit system?
0
 

Author Comment

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

Assisted Solution

by:Qlemo
Qlemo earned 100 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 70

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 70

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 70

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

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…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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