ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Folder File Count and Move

(1/2) > >>

magician62:
There seem to be a number of utilities out there for size of folders, but nothing obvious for File count.

Concept
From source folder move all sub folders with less than or greater than x files (not likely both) to definable Destination folder.

Givens
1. For ease destination folder would be at same or higher level than source folder on same drive, with a name of same or less length (should prevent path length issues and lengthy move process)
2. There will be only folders in the source folder.
3. If a sub folder contains a further folder it may be classified as 'one' item for the purpose of the count.

I have something like 20000 folders all with small files of varying numbers, the intent is to weed out those with few files for further review/categorisation.

ConstanceJill:
Hello there .o/

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

magician62:
I had a few issues at first which seems related to characters in the folder name. I have separated those for the moment and will investigate later.

But for the moment it seems to be working, only 14000 folders to go on this pass :)
Many thanks

4wd:
I had a few issues at first which seems related to characters in the folder name. I have separated those for the moment and will investigate later.
-magician62 (October 13, 2015, 03:21 PM)
--- End quote ---

You could probably get it to process those by adding a change codepage command (chcp) at the start of the command file to change the character set it uses by default, (normally 850).

MilesAhead:
These may be close depending how the rule triggering is implemented:
http://alternativeto.net/software/file-juggler/?platform=windows

But I suspect there is a rule based file manager out there that does it.

Navigation

[0] Message Index

[#] Next page

Go to full version