Solved

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

Posted on 2009-05-07
25
405 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 84

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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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 84

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 84

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Run Application within an Access Macro 2 63
Need some help in Batch file assigning variable value ? 4 75
Batch File tool box 5 52
Date variable in batch file 2 44
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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