Page 1 of 1
list file with file size
Posted: 18 Jul 2014 07:10
by xhai
Hi guys can you improve this code
1. I would like to list the pdf files + the size of the pdf + with no.
simulate
1. Make-me-smile.pdf [20MB]
2. Make-me-cry.pdf [950kb]
etc.
2. Now that i have a list of pdf file with size I want to add my .doc files
simulate
1. Make-me-smile.pdf [20MB]
2. Make-me-cry.doc [950kb]
etc.
Thank You.. It may sound simple but it's hard for me to code..
Re: list file with file size
Posted: 18 Jul 2014 07:33
by foxidrive
Does it matter how the filesizes are calculated?
1024 = 1 kB
or 1000 = 1kB
or just rounded?
Re: list file with file size
Posted: 19 Jul 2014 03:27
by xhai
foxidrive wrote:Does it matter how the filesizes are calculated?
1024 = 1 kB
or 1000 = 1kB
or just rounded?
Thanks Foxi for fast reply.. any method as long it is acurate
Re: list file with file size
Posted: 19 Jul 2014 05:16
by foxidrive
Is rounded decimal good enough?
"Accurate" here depends on your needs.
Re: list file with file size
Posted: 19 Jul 2014 07:40
by Yury
Code: Select all
@echo off
set "folder=."
set "extensions=*.pdf *.doc"
for /f "delims=" %%i in ('
mshta "javascript:new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write('\t')&close()"
') do (
set TAB=%%i
)
(
for /f "tokens=* delims=%TAB% " %%i in ('
robocopy "%folder%" %random% %extensions% /nc /ndl /njh /njs /l
') do (
set /a n+=1
for /f "tokens=1,2 delims=%TAB%" %%j in ("%%i") do (
for /f "tokens=1,2" %%l in ("%%j") do (
if "%%m"=="" (
if %%j lss 1024 (
call echo %%n%%. %%~nxk [%%j B]
) else (
set /a x=%%j0/1024
call echo %%n%%. %%~nxk [%%x:~,-1%%.%%x:~-1%% kB]
)
) else (
if %%m==m (
call echo %%n%%. %%~nxk [%%l MB]
)
if %%m==g (
call echo %%n%%. %%~nxk [%%l GB]
)
)
)
)
)
)>"list.txt"
exit /b
Re: list file with file size
Posted: 19 Jul 2014 08:09
by foxidrive
Nice work Yury.
Re: list file with file size
Posted: 19 Jul 2014 08:35
by xhai
HI Yury Why so happen the code doesn't work with me... it give me black screen after a few minutes it close.. My OS is window 7
Re: list file with file size
Posted: 19 Jul 2014 08:38
by ShadowThief
xhai wrote:Yury wrote:<code>
HI Yury Why so happen the code doesn't work with me... it give me black screen after a few minutes it close.. My OS is window 7
You see no text on the screen because the output is being put in a file.
Re: list file with file size
Posted: 19 Jul 2014 09:54
by Squashman
Works Perfect Yury!
Re: list file with file size
Posted: 19 Jul 2014 15:39
by xhai
Squashman wrote:Works Perfect Yury!
Still no luck I can find the output Pdflist.txt in the same directory as the bat file...
Re: list file with file size
Posted: 19 Jul 2014 17:21
by Squashman
xhai wrote:Squashman wrote:Works Perfect Yury!
Still no luck I can find the output Pdflist.txt in the same directory as the bat file...
What are you talking about. The code clearly shows that the output is list.txt!
Re: list file with file size
Posted: 21 Jul 2014 08:53
by xhai
Squashman wrote:xhai wrote:Squashman wrote:Works Perfect Yury!
Still no luck I can find the output Pdflist.txt in the same directory as the bat file...
What are you talking about. The code clearly shows that the output is list.txt!
Ya Thanks Yuri code work.. I was so dumb I'm looking at the wrong output..