list file with file size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xhai
Posts: 39
Joined: 13 Jun 2013 09:33

list file with file size

#1 Post by xhai » 18 Jul 2014 07:10

Hi guys can you improve this code

Code: Select all

dir /a-d /b *.pdf>Pdflist.txt


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..

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: list file with file size

#2 Post by foxidrive » 18 Jul 2014 07:33

Does it matter how the filesizes are calculated?

1024 = 1 kB
or 1000 = 1kB
or just rounded?

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: list file with file size

#3 Post by xhai » 19 Jul 2014 03:27

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: list file with file size

#4 Post by foxidrive » 19 Jul 2014 05:16

Is rounded decimal good enough?

"Accurate" here depends on your needs.

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: list file with file size

#5 Post by Yury » 19 Jul 2014 07:40

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: list file with file size

#6 Post by foxidrive » 19 Jul 2014 08:09

Nice work Yury.

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: list file with file size

#7 Post by xhai » 19 Jul 2014 08:35

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

ShadowThief
Expert
Posts: 1162
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: list file with file size

#8 Post by ShadowThief » 19 Jul 2014 08:38

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.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: list file with file size

#9 Post by Squashman » 19 Jul 2014 09:54

Works Perfect Yury!

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: list file with file size

#10 Post by xhai » 19 Jul 2014 15:39

Squashman wrote:Works Perfect Yury!


Still no luck I can find the output Pdflist.txt in the same directory as the bat file...

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: list file with file size

#11 Post by Squashman » 19 Jul 2014 17:21

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!

xhai
Posts: 39
Joined: 13 Jun 2013 09:33

Re: list file with file size

#12 Post by xhai » 21 Jul 2014 08:53

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..

Post Reply