select group of files with a certain total size?

  • Thread starter Thread starter Broons Bane
  • Start date Start date
B

Broons Bane

Does anybody know how I got to a folder and select the first n files grand
totalling to a certain size?

It is to do with a folder containing thousands of files. I want to select
about 700mb at a time in order to write to cd.

Thanks in anticipation :)
 
Broons Bane said:
Does anybody know how I got to a folder and select the first n files grand
totalling to a certain size?

It is to do with a folder containing thousands of files. I want to select
about 700mb at a time in order to write to cd.

Thanks in anticipation :)

You could run the batch file below to create a number of
folders, each containing a batch of files that would fit on a
single CD. Test the batch file as it is. When satisfied, remove
the word "echo" from lines 42 and 43 to activate it.

Line01 @echo off
Line02 set limit=700000000
Line03 set source=c:\Documents and Settings\Broons\My Music
Line04
Line05 rem Do not change anything below this line!
Line06 set time_=%time:~0,8%
Line07 set TargetFolder=c:\%time_::=%
Line08 set batch=1
Line09
Line10 setlocal enabledelayedexpansion
Line11
Line12 dir "%source%" /on /a-d /-c | find "/" > c:\folder.txt
Line13
Line14 set s=0
Line15 set sum=0
Line16 if exist c:\files.txt del c:\files.txt
Line17
Line18 for /F "tokens=1-3*" %%a in (c:\folder.txt) do (
Line19 set /a s=!sum! + %%c
Line20 if !s! GTR %limit% (
Line21 call :Assemble !sum!
Line22 set s=%%c
Line23 del c:\files.txt
Line24 )
Line25 set sum=!s!
Line26 echo %%d>> c:\files.txt
Line27 )
Line28
Line29 call :Assemble
Line30 del c:\files.txt & del c:\folder.txt
Line31 echo.
Line32 echo Your files are ready to burn in %TargetFolder%.
Line33 echo.
Line34 pause
Line35 endlocal
Line36 goto :eof
Line37 -----------------------------------------
Line38
Line39 :Assemble
Line40
Line41 set Target=%TargetFolder%\%batch%
Line42 echo md "%Target%"
Line43 for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
"%Target%"
Line44 echo Batch # %batch% is stored in %Target%. Size=%sum% bytes
Line45 echo.
Line46 pause
Line47 set /a batch=%batch% + 1
 
What you want to do can be accomplished with an advanced File Manager
program. I have been using Windows Commander (now Total Commander) for about
6 years. It allows you to accomplish so much more in the way of file/folder
maintenance.

I can highlight 25 (or whatever) out of 2000 files, press ctrl/L and see the
total size of the highlighted files. Perfect for what you want to do. fully
functional prod ware (you have to go through one extra step to open the
program until you pay for it).

See http://www.ghisler.com/

--


Regards,

Richard Urban
Microsoft MVP Windows Shell/User

Quote from George Ankner:
If you knew as much as you think you know,
You would realize that you don't know what you thought you knew!
 
Pegasus (MVP) said:
You could run the batch file below to create a number of
folders, each containing a batch of files that would fit on a
single CD. Test the batch file as it is. When satisfied, remove
the word "echo" from lines 42 and 43 to activate it.

Line01 @echo off
Line02 set limit=700000000
Line03 set source=c:\Documents and Settings\Broons\My Music
Line04
Line05 rem Do not change anything below this line!
Line06 set time_=%time:~0,8%
Line07 set TargetFolder=c:\%time_::=%
Line08 set batch=1
Line09
Line10 setlocal enabledelayedexpansion
Line11
Line12 dir "%source%" /on /a-d /-c | find "/" > c:\folder.txt
Line13
Line14 set s=0
Line15 set sum=0
Line16 if exist c:\files.txt del c:\files.txt
Line17
Line18 for /F "tokens=1-3*" %%a in (c:\folder.txt) do (
Line19 set /a s=!sum! + %%c
Line20 if !s! GTR %limit% (
Line21 call :Assemble !sum!
Line22 set s=%%c
Line23 del c:\files.txt
Line24 )
Line25 set sum=!s!
Line26 echo %%d>> c:\files.txt
Line27 )
Line28
Line29 call :Assemble
Line30 del c:\files.txt & del c:\folder.txt
Line31 echo.
Line32 echo Your files are ready to burn in %TargetFolder%.
Line33 echo.
Line34 pause
Line35 endlocal
Line36 goto :eof
Line37 -----------------------------------------
Line38
Line39 :Assemble
Line40
Line41 set Target=%TargetFolder%\%batch%
Line42 echo md "%Target%"
Line43 for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
"%Target%"
Line44 echo Batch # %batch% is stored in %Target%. Size=%sum% bytes
Line45 echo.
Line46 pause
Line47 set /a batch=%batch% + 1

thanks for this I get a lot of error messages of the form:

'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.

Here is my file

@echo off
set limit=700000000
set source=C:\Documents and Settings\User\My Documents\Table Tennis
rem Do not change anything below this line!
set time_=%time:~0,8%
set TargetFolder=c:\%time_::=%
set batch=1

setlocal enabledelayedexpansion

dir "%source%" /on /a-d /-c | find "/" > c:\folder.txt

set s=0
set sum=0
if exist c:\files.txt del c:\files.txt

for /F "tokens=1-3*" %%a in (c:\folder.txt) do (
set /a s=!sum! + %%c
if !s! GTR %limit% (
call :Assemble !sum!
set s=%%c
del c:\files.txt
)
set sum=!s!
echo %%d>> c:\files.txt
)

call :Assemble
del c:\files.txt & del c:\folder.txt
echo.
echo Your files are ready to burn in %TargetFolder%.
echo.
pause
endlocal
goto :eof
-----------------------------------------

:Assemble

set Target=%TargetFolder%\%batch%
echo md "%Target%"
for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
t%"
echo Batch # %batch% is stored in %Target%. Size=%sum% bytes
echo.
pause
set /a batch=%batch% + 1
 
Richard said:
What you want to do can be accomplished with an advanced File Manager
program. I have been using Windows Commander (now Total Commander) for about
6 years. It allows you to accomplish so much more in the way of file/folder
maintenance.

I can highlight 25 (or whatever) out of 2000 files, press ctrl/L and see the
total size of the highlighted files. Perfect for what you want to do. fully
functional prod ware (you have to go through one extra step to open the
program until you pay for it).

See http://www.ghisler.com/

Explorer also shows you the total-size of highlighted files in the
status bar. If you include folders in the selection, then you need to
right-click for a Property page to get the total size.
 
Broons said:
Does anybody know how I got to a folder and select the first n files
grand totalling to a certain size?

It is to do with a folder containing thousands of files. I want to
select about 700mb at a time in order to write to cd.



Select some number of files that you think will be around 700MB. Look at the
status bar to see their total size. Add or subtract files to the selection
as necessary, until you get to 700MB.
 
Broons Bane said:
thanks for this I get a lot of error messages of the form:

'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.

Here is my file

@echo off
set limit=700000000
set source=C:\Documents and Settings\User\My Documents\Table Tennis
rem Do not change anything below this line!
set time_=%time:~0,8%
set TargetFolder=c:\%time_::=%
set batch=1

setlocal enabledelayedexpansion

dir "%source%" /on /a-d /-c | find "/" > c:\folder.txt

set s=0
set sum=0
if exist c:\files.txt del c:\files.txt

for /F "tokens=1-3*" %%a in (c:\folder.txt) do (
set /a s=!sum! + %%c
if !s! GTR %limit% (
call :Assemble !sum!
set s=%%c
del c:\files.txt
)
set sum=!s!
echo %%d>> c:\files.txt
)

call :Assemble
del c:\files.txt & del c:\folder.txt
echo.
echo Your files are ready to burn in %TargetFolder%.
echo.
pause
endlocal
goto :eof
-----------------------------------------

:Assemble

set Target=%TargetFolder%\%batch%
echo md "%Target%"
for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
t%"
echo Batch # %batch% is stored in %Target%. Size=%sum% bytes
echo.
pause
set /a batch=%batch% + 1

You broke up and mutilated Line43! It's supposed to look like so:

for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
"%Target%"

I am puzzled how this could have happened. You're meant
to use copy & paste to create your batch file, not retype it!
 
Broons Bane said:
thanks for this I get a lot of error messages of the form:

'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'áááá' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.
'á' is not recognized as an internal or external command,
operable program or batch file.

Here is my file

@echo off
set limit=700000000
set source=C:\Documents and Settings\User\My Documents\Table Tennis
rem Do not change anything below this line!
set time_=%time:~0,8%
set TargetFolder=c:\%time_::=%
set batch=1

setlocal enabledelayedexpansion

dir "%source%" /on /a-d /-c | find "/" > c:\folder.txt

set s=0
set sum=0
if exist c:\files.txt del c:\files.txt

for /F "tokens=1-3*" %%a in (c:\folder.txt) do (
set /a s=!sum! + %%c
if !s! GTR %limit% (
call :Assemble !sum!
set s=%%c
del c:\files.txt
)
set sum=!s!
echo %%d>> c:\files.txt
)

call :Assemble
del c:\files.txt & del c:\folder.txt
echo.
echo Your files are ready to burn in %TargetFolder%.
echo.
pause
endlocal
goto :eof
-----------------------------------------

:Assemble

set Target=%TargetFolder%\%batch%
echo md "%Target%"
for /F "tokens=*" %%* in (c:\files.txt) do echo move "%source%\%%*"
t%"
echo Batch # %batch% is stored in %Target%. Size=%sum% bytes
echo.
pause
set /a batch=%batch% + 1

A further thought: Do you have file names with "poison" characters
inside, e.g. "&", "%"?
 
Pegasus (MVP) said:
A further thought: Do you have file names with "poison" characters
inside, e.g. "&", "%"?
no poison characters. I did copy and paste it. not sure how the mutilation
happened.

Thanks anyway, I'll try the line 43 fix.
 
Broons Bane said:
no poison characters. I did copy and paste it. not sure how the mutilation
happened.

Thanks anyway, I'll try the line 43 fix.

If it still does not work, delete Line30 then send c:\folder.txt
to the address below. Change every "z" to an "s" and advise
that you have sent it - the mailbox is not normally monitored.
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top