filthy-mcnasty said:
Win XP Pro OS. I have a large number of files with the same name (Different
versions) and want to sort them according to size - Largest in a top-rank
folder and then , according to size, next largest in SubFolder called 1,
next in SubFolder 2 etc
Is there a utility, Console or GUI, which can do this? Or is there a
BatchFile or Script which can be used/modified to get the job done?
*** I thought I would tackle this as an exercise and am posting this
strictly for interest sake because it won't work under XP as shown. The
DOS "DIR" command will not show strict size order. It shows size order
within each subdirectory one directory at a time. I could do a convoluted
patch by using "DIR" coupled with "SORT", but it would be clumsy as it
requires specifying a column for the sort and I'd have to get rid of all
the information not required afterwards. )-:
Now, maybe the "DIR" that comes with XP PRO can do the sort as required
by this batch file. Perhaps someone can tell me if XP's "DIR" emulates
Microsoft's DOS "DIR" or if it emulates DR-DOS'.
________
Here's a solution using XSET. It uses the DR-DOS "XDIR" command because
that gives the required sort order. I shall assume the file names are
"FILE.txt" and are in a C:\BACKUP directory & below.
:: SIZE.bat
:: Creates Directories and Moves Files to them based on Size
::
@ECHO OFF
XDIR C:\BACKUP\FILE.TXT /B /R /S /Z > C:\TEMP\DIR.LST
MD C:\TOP
CD C:\TOP
SET LINE-NUMB=1
:OPERATIONS
TYPE C:\TEMP\DIR.LST | XSET /LINE %LINE-NUMB% FILE-NAME
IF "%XSET_MSG%" == "END-OF-FILE" GOTO CLEANUP
IF NOT "%DIRECTORY-NUMB%" == "" MD %DIRECTORY-NUMB%
MOVE %FILE-NAME% .\%DIRECTORY-NUMB%
IF "%DIRECTORY-NUMB%" == "" SET DIRECTORY-NUMB=0
XSET /MATH LINE-NUMB=%LINE-NUMB% +1
XSET /MATH DIRECTORY-NUMB=%DIRECTORY-NUMB% +1
GOTO OPERATIONS
:CLEANUP
DEL C:\TEMP\DIR.LST
FOR %%V IN (LINE-NUMB DIRECTORY-NUMB FILE-NAME XSET_MSG) DO SET %%V=
The basic explanation is that the required file list sorted by
descending size is generated by XDIR and sent to XSET. There, each line is
read one at a time taking each file path\name in turn and placing it into
a FILE-NAME variable. A series of numbered directories are created within
C:\TOP and each file is moved to the appropriate directory or
subdirectory.
XSET's "/MATH" feature is used to increase the required line and
directory numbers by a factor of one for each run-through of the
operations. When no more lines are encountered, XSET generates an
"END-OF-FILE" variable. This is tested for existence during each
run-through and when found, the operation ends by cleaning up all that was
created.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/