?
Solved

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

Posted on 2009-05-07
25
Medium Priority
?
409 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 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 free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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