Solved

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

Posted on 2009-05-07
25
404 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
  • 11
  • 6
  • 5
  • +1
25 Comments
 
LVL 69

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 83

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 69

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 83

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 69

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 69

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 69

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 69

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 69

Expert Comment

by:Qlemo
ID: 24328763
64bit system?
0
 

Author Comment

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

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 83

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 69

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 69

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 69

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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