151
Post New Requests Here / Re: IDEA: Folder File Count and Move
« on: October 13, 2015, 07:27 AM »
Hello there .o/
Can be done with a batch script (.bat or .cmd file).
Here's a quick and dirty one :
Can be done with a batch script (.bat or .cmd file).
Here's a quick and dirty one :
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
REM This script counts the number of files in each of the folders right below SrcFolder (including sub-folders)
REM If that number is higher than the set threshold (see variable FileCountLimit), then it moves that folder to TargetFolder
REM WARNING : both TargetFolder and SrcFolder paths MUST include the final "\" character or the script will fail.
REM This was only tested under Windows 7
SET TargetFolder=E:\Moo\stuff\
SET SrcFolder=C:\foo\bar\whatever\
SET FileCountLimit=400
for /f "delims=*" %%d in ('dir /a:d /b "%SrcFolder%"') do (
SET Folder=%%d
ECHO Counting files in folder "%SrcFolder%!Folder!"...
SET FileCount=0
for /f "delims=*" %%f in ('dir /a:-d /b /s "%SrcFolder%!Folder!"') DO (
SET /A FileCount+=1
)
ECHO Folder contains !FileCount! files.
IF !FileCount! GEQ %FileCountLimit% (
ECHO File count is higher or equal to the limit ^(%FileCountLimit%^), DO ACTION HERE
MOVE /Y "%SrcFolder%!Folder!" "%TargetFolder%"
) ELSE (
ECHO File count is inferior to the limit ^(%FileCountLimit%^), no action.
)
)
pause
SETLOCAL ENABLEDELAYEDEXPANSION
REM This script counts the number of files in each of the folders right below SrcFolder (including sub-folders)
REM If that number is higher than the set threshold (see variable FileCountLimit), then it moves that folder to TargetFolder
REM WARNING : both TargetFolder and SrcFolder paths MUST include the final "\" character or the script will fail.
REM This was only tested under Windows 7
SET TargetFolder=E:\Moo\stuff\
SET SrcFolder=C:\foo\bar\whatever\
SET FileCountLimit=400
for /f "delims=*" %%d in ('dir /a:d /b "%SrcFolder%"') do (
SET Folder=%%d
ECHO Counting files in folder "%SrcFolder%!Folder!"...
SET FileCount=0
for /f "delims=*" %%f in ('dir /a:-d /b /s "%SrcFolder%!Folder!"') DO (
SET /A FileCount+=1
)
ECHO Folder contains !FileCount! files.
IF !FileCount! GEQ %FileCountLimit% (
ECHO File count is higher or equal to the limit ^(%FileCountLimit%^), DO ACTION HERE
MOVE /Y "%SrcFolder%!Folder!" "%TargetFolder%"
) ELSE (
ECHO File count is inferior to the limit ^(%FileCountLimit%^), no action.
)
)
pause