Moving files depending on their size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Moving files depending on their size

#1 Post by Matt20687 » 07 Feb 2013 08:32

Hello,

I am stuck and i hope you can help!

I am trying to create a batch file that will run on a schedule. It will check a folder and any files that are over 3072 bytes it will move it to another folder called Moved Files.

Does anyone know how to do this?

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Moving files depending on their size

#2 Post by Matt20687 » 07 Feb 2013 08:47

This is what i have so far, it moves all files in the folder rather than the ones that are under 3072 bytes. This is because i am defining the file as *.* i assume. I cannot figure out how to set the ones under 3072 bytes as a variable or something.

Code: Select all

set "dispatch=C:\Users\Matthew\Desktop\MM Image Count\Test folder"

for %%A in (%dispatch%) do if %%~zA LEQ 3072 move "*.*" "C:\Users\Matthew\Desktop\MM Image Count\Movefolder"

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Moving files depending on their size

#3 Post by Squashman » 07 Feb 2013 08:58

%dispatch%\*.*
move %%A

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Moving files depending on their size

#4 Post by Matt20687 » 07 Feb 2013 09:11

set "dispatch=C:\Users\Matthew\Desktop\MM Image Count\Test folder"

for %%A in (%dispatch%\*.*) do if %%~zA LEQ 3072 move "%%A" "C:\Users\Matthew\Desktop\MM Image Count\Movefolder"

So it should look like this?

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Moving files depending on their size

#5 Post by Squashman » 07 Feb 2013 09:42

Well your folder path has spaces so you will need quotes.

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Moving files depending on their size

#6 Post by Matt20687 » 07 Feb 2013 14:44

Thanks. My code which works based on it moving files which are only 3kb in size to another folder works great. This is below

Code: Select all

set "movefolder=C:\Documents and Settings\Administrator\Desktop\Rogue Images Folder"
set "dispatch=E:\Matt\Test\dispatch\*.*"



for %%A in ("%dispatch%") do (
   if %%~zA LEQ 3072 move "%%A" "%movefolder%"
   )


I have one last request that i cannot figure out. As i have said this runs perfectly but what i would like to happen now is when it does the check for any files that are smaller than 3kb i would like it to launch a .exe. Lets call it test.exe for sake of a name.

I have tried to figure this out but i cannot get it to run once, it runs on the loop and runs the .exe as many times as there are files under 3kb. I assumed i would have to do a count of the amount of times the above coding searches through and finds a file under 3kb and then to do a simple if %count% GEQ 1 do ( start test.exe).

Anyone have any thoughts on how i can get a .exe to only run once if the above coding finds a 3kb rather than running it as many times as there are 3kb files (e.g. 5 3kb file would run test.exe 5 times).

Thanks,
Matt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Moving files depending on their size

#7 Post by foxidrive » 07 Feb 2013 14:56

Code: Select all

set "movefolder=C:\Documents and Settings\Administrator\Desktop\Rogue Images Folder"
set "dispatch=E:\Matt\Test\dispatch\*.*"


set "flag="

for %%A in ("%dispatch%") do (
   if %%~zA LEQ 3072  (
           move "%%A" "%movefolder%"
           set flag=1
           )
   )

if defined flag test.exe


Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Moving files depending on their size

#8 Post by Matt20687 » 07 Feb 2013 14:59

Thanks for this but how does it still move the files that are under 3kb as well as running the .exe only once?

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: Moving files depending on their size

#9 Post by Matt20687 » 07 Feb 2013 15:00

Ignore me lol

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Moving files depending on their size

#10 Post by foxidrive » 07 Feb 2013 15:13

Note that I modified the code above. Now it will only run the test.exe if files are moved.

Post Reply