Sort/File by size - Any Utility?

  • Thread starter Thread starter filthy-mcnasty
  • Start date Start date
F

filthy-mcnasty

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?

Many thanks
 
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?

Many thanks

Right click on an empty space in the folder that you want to organize.
Select "Arrange Icons By", then select "size" from the new menu that
appears.


HTH

--
"I think computer viruses should count as life. I think it says
something about human nature that the only form of life we have created
so far is purely destructive. We've created life in our own image."

-- Stephen Hawking --
 
Using at least one appendage, the entity known in this space-time
Right click on an empty space in the folder that you want to organize.
Select "Arrange Icons By", then select "size" from the new menu that
appears.

Sorry. I wasn't clear enough. These are all files with duplicate names
which I wish to keep named as they already are. For this reason they are
kept in a number of separate folders, as the OS will not allow samenames
to co-exist in the same folder. I could do a file search and arrange the
results by name/size for a number of folders, but I would still need to
create the folder structures Top (Largest), Top\1 (Next Largest), Top\2
etc. I just want to automate this process as far as possible

I intend for all largest files to be in the top folder, all next largest
in \1 etc

Thanks

--
Will Cornish of Cardigan, UK - No nastier than you; No filthier than
usual

To EMail Remove Anti-Spam Spaces: filthy-mcnasty @
btconnect.com
 
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?

Assumes files are all called: FileToSort.EXT, and located somewhere
on C: drive, and less than 999999999bytes in size. Subfolders are
created in current folder. Transient folder 0 is created then removed
and contents (which will be the largest file) moved to current folder.
Two transient Batch workfiles are created in current folder. If two
files have the same size, they are placed in ordered subfolders by
their full path name as a sub-key.

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL
(ECHO.%%_9999999999%% SET COUNT=0)>_TEMP.BAT
FOR /R C:\ %%F IN (FileToSort.ext) DO IF EXIST %%F CALL :LIST "%%F" %%~zF
TYPE _TEMP.BAT | sort /r >_TEMP1.BAT
CALL _TEMP1.BAT
DEL _TEMP.BAT _TEMP1.BAT
move .\0\FileToSort.ext .\
RD .\0
GOTO :EOF

:LIST
SET FS=0000000000%2
SET FS=%FS:~-10%
(ECHO.%%_%FS%c%% MD %%COUNT%%)>>_TEMP.BAT
(ECHO.%%_%FS%b%% move %1 .\%%COUNT%%)>>_TEMP.BAT
(ECHO.%%_%FS%a%% SET /a COUNT+=1)>>_TEMP.BAT

====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects
 
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?

There used to be a tool called sizecopy which might help. But as you're
on WinXP, you just can use the features of the cmd command processor:

cmd /c for %I in (*.*) do if %~zI geq 700000 copy %I .\7\

This example scans the current directory and copies all files greater
or equal 700000 bytes to a subfolder 7 (which already has to exist).
Starting from this example you should be able to build your own
command string or batch file. Run

help <command>

from the cmd.exe command prompt to get assistance. Be aware to include
additional percent signs if you want to run the above from inside a
batch file:

cmd /c for %%I in (*.*) do if %%~zI geq 700000 copy %%I .\7\

HTH.
BeAr
 
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?

The code below will give you a starting point to modify from. It
finds all the *.TXT files on the C: drive and sorts them by size.

@echo off & setlocal enableextensions enabledelayedexpansion
if exist %temp%\temp.dir del %temp%\temp.dir
for /f "delims=" %%f in (
'dir /a:-d /b /s c:\*.txt') do (
set filename_="%%~ff"
set filesize_=0000000000%%~zf
set filesize_=!filesize_:~-10!
echo !filesize_! !filename_! >>%temp%\temp.dir
)
sort /r %temp%\temp.dir
if exist %temp%\temp.dir del %temp%\temp.dir
endlocal & goto :EOF

The output might start with something like
0000401272 "c:\INF2\FAQPAS.TXT"
0000389257 "c:\BAT\1BATFAQ.TXT"
0000359101 "c:\CHYDE\INDEX.TXT"
0000272243 "c:\CMD\1CMDFAQ.TXT"

One may wish to get rid of the leading filesize. Covered e.g. in
130306 Jul 12 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
Easy to do with pure script with for, since the "lead" length is
fixed.

(The gentle readers will also notice the potential for finding
duplicates in general.)

P.S. Various users have their own preferences where to discuss
different subjects. That's fine by me. But I prefer to post my own
NT/2000/XP answers to so for my own posting
thread I have redirected the potential responses. You and others
will make your own free choices as you wish just like I make mine.

All the best, Timo
 
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?

Many thanks

Here's a start-point:

[01]@echo off&setlocal
[02]:: build a list of files in oldstruc
[03]for /f "tokens=*" %%i in ('dir /s/b .\oldstruc') do call :fz %%~zi "%%i"
[04]for /f "tokens=1*" %%i in ('type temp.txt^|sort /r') do call :mf %%j
[05]del temp.txt&goto :eof
[06]
[07]:: move files to newstruc
[08]:mf
[09]if not exist ".\newstruc\%~nx1" COPY %1 ".\newstruc\%~nx1" >nul &goto
:eof
[10]set ysz=0
[11]:ndl
[12]set /a ysz=1+%ysz%
[13]md .\newstruc\%ysz% 2>nul
[14]if exist ".\newstruc\%ysz%\%~nx1" goto ndl
[15]COPY %1 ".\newstruc\%ysz%\%~nx1" >nul
[16]goto :eof
[17]
[18]:: fill %1 with zeroes and create a line
[19]:fz
[20]set ysz=%1
[21]:fzloop
[22]set ysz=0%ysz%
[23]if "%ysz:~12,1%"=="" goto fzloop
[24]echo %ysz% %2 >>temp.txt
[25]goto :eof

Each line begins [number]. Lines will be wrapped in transmission and
need to be rejoined. The [number] at the beginning of each line needs
to be removed.

Essentially
1) make a list of files & sizes
2) pad the size to a fixed-width & sort
3) move to newstruc, creating dirs as needed

Hence, if filename.ext exists n times, the largest will be moved to
..\newstruc, the next to .\newstruc\1 and so on to .\newstruc\n-1

I know it DOESN'T work if the filename contains "%" but it appears OK for
the other valid poison characters in filenames (esp. spaces and &) but if
you use such warpednesses, it's your funeral...

And I've used COPY rather than MOVE. Your choice.....

HTH

....Bill
 
JRS: In article <[email protected]>,
dated Wed, 31 Aug 2005 17:37:23, seen in 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?

Please choose newsgroups sagaciously. DOS batch, for which a.m.b was
created, and NT+ batch, for which a.m.b.nt is suitable, are
significantly different.

In any DOS-type OS, tested in Win98, I have

dir n*.txt /o-s /b | COLS 'md * ^6,1 ! 'move * 1- ^6,1
-> md 1
move NEW-URLS.TXT 1
md 2
move NOTES.TXT 2
md 3
move NEWCHARS.TXT 3

choosing n*.txt as it gives a convenient number of files; you'd use
<name>.*. Redirect the output to $$$.BAT and execute. That, or
similar, should do, provided that "large" < 1,000,000 (change each 6 to
9 to allow < 1,000,000,000).

Get COLS via sig line 3, other tools such as SED or MiniTrue could be used
instead.

It might be well to use constant-length directory names; for that, use
^6,1000001 (twice).


If you wish two of the same size to go into the same directory,

dir n*.txt /o-s | find "/" | COLS 'md * 16+3 20+3 24+3 ! 'move * ` 1-8 '. 10+3 * 16+3 20+3 24+3
-> md 24973
move NEW-URLS.TXT 24973
md 2259
move NOTES.TXT 2259
md 114
move NEWCHARS.TXT 114

(you may need to make md conditional on non-preexistence) and then, if
necessary, rename the directories in desired sequence, for
which a little cunning will be required, or use a HLL.
 
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/
 
Using at least one appendage, the entity known in this space-time continuum
William Allen

To you and all others who have helped in this thread, many thanks
 
filthy-mcnasty said:
Using at least one appendage, the entity known in this space-time


Sorry. I wasn't clear enough. These are all files with duplicate names
which I wish to keep named as they already are. For this reason they are
kept in a number of separate folders, as the OS will not allow samenames
to co-exist in the same folder. I could do a file search and arrange the
results by name/size for a number of folders, but I would still need to
create the folder structures Top (Largest), Top\1 (Next Largest), Top\2
etc. I just want to automate this process as far as possible

I intend for all largest files to be in the top folder, all next largest
in \1 etc

Thanks

TrackerV3 might go some way towards solving you problem. Go to View > Show
Info Panel, and select the folder and sub-folders you wish to include. It
will then display all the files (which can be shown in size order) including
duplicate files. It allows files with the same name to be included in the
results list, and you can then drag them to pre-prepared empty folders,
which could be done with a batch file.

http://www.trackerv3.com/download.htm

===

Frank Bohan
¶ Coffee.Exe Missing - Insert Cup And Press Any Key
 
Back
Top