Computing.Net > Forums > Disk Operating System > Converting bytes to Kb using dir

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Converting bytes to Kb using dir

Reply to Message Icon

Name: NinaV
Date: October 22, 2003 at 10:20:24 Pacific
OS: Windows 2000
CPU/Ram: 521,744 Kb Ram
Comment:

The dir command shows me all the files and it's sizes for a certain directory. I also output this to a .txt file. Is there any way that I can output all these file sizes in kb and not in bytes? I can't seem to find a command that will convert.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 23, 2003 at 03:35:47 Pacific
Reply:

The following batch shows the files' size in Kbytes other than in bytes; it is derived from the Dir command processing its output using the extended capabilities of Windows NT/2K/XP shell scripting.

I named it KDir and its output can be redirected to text files using the usual ">" symbol. So

KDir MyDir shows files' size onto the screen

KDir MyDir > Out.txt saves the list onto Out.txt (or whatever file you like)

The Directory name must not contain blanks (use short format if needed), but files to be listed may have any valid Windows name (with blanks too).

I hope that fits your needs; Have a nice day

@Echo Off

:: KDIR.BAT Syntax: KDir [Unit:]PathName

Set NoFile=0
Set TByte=0
Set TKByte=0

Echo.
If %1.==. (Echo Missing Directory & GoTo :EOF)
If not exist %~f1.\Nul (Echo Directory %~f1 not found & GoTo :EOF)

Echo Directory: %~f1
Echo.
For /F "skip=1 tokens=1-3*" %%A in ('Dir %1 /A:-D /-C ^| Find "."') Do (
Call :KBYTE %%A %%B %%C %%D)
Echo.
Echo %NoFile% Files %TByte% = %TKByte% Kbytes

Set TByte=
Set TKByte=
Set NoFile=
GoTo :EOF

:KBYTE
Set /A NoFile=%NoFile%+1
Set SByte=%3
Set /A TByte=%TByte%+%SByte%
Call :NORM SByte %SByte%
Set KByte=%3
Set /A KByte=%KByte%/1024
Set /A KByte=%KByte%+1
Set /A TKByte=%TKByte%+%KByte%
Call :NORM KByte %KByte%
:LOOP
Set FName=%FName% %4
Shift /4
If not "%4"=="" GoTo :LOOP
Echo %1 %2 %SByte% = %KByte% Kb %FName%
Set FName=
Set KByte=
Set SByte=
GoTo :EOF

:NORM
Set KTemp=%2
If %2 lss 100000000 Set KTemp=.%KTemp%
If %2 lss 10000000 Set KTemp=.%KTemp%
If %2 lss 1000000 Set KTemp=.%KTemp%
If %2 lss 100000 Set KTemp=.%KTemp%
If %2 lss 10000 Set KTemp=.%KTemp%
If %2 lss 1000 Set KTemp=.%KTemp%
If %2 lss 100 Set KTemp=.%KTemp%
If %2 lss 10 Set KTemp=.%KTemp%
Set %1=%KTemp%
Set KTemp=
GoTo :EOF


0
Reply to Message Icon

Related Posts

See More


Rename the file name to %... Need To Recover Files in ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Converting bytes to Kb using dir

Use DIR to list temp internet files www.computing.net/answers/dos/use-dir-to-list-temp-internet-files/14338.html

Batch: convert HEX to DEC and vice-versa www.computing.net/answers/dos/batch-convert-hex-to-dec-and-viceversa/10007.html

convert .bat to exe or com files???? www.computing.net/answers/dos/convert-bat-to-exe-or-com-files/10173.html