Computing.Net > Forums > Disk Operating System > DOS Batch file

DOS Batch file

Reply to Message Icon

Original Message
Name: jeremas
Date: August 27, 2003 at 10:53:56 Pacific
Subject: DOS Batch file
OS: 192 MB
CPU/Ram: PIII
Comment:

Hello guys,
I need a batch file to get the size of each file in a given folder or directory. Of course I can use DIR command but from that I need only the name of file and it size in kbytes.

I will appreciate if someone can help me


Report Offensive Message For Removal

Response Number 1
Name: Brian HANLON
Date: August 29, 2003 at 04:57:22 Pacific
Subject: DOS Batch file
Reply: (edit)

At URL: http://home.mnet-online.de/horst.muc/ you'll find:

LMOD (a 12 Kb download)
Versatile line/list modification tool to generate lists of commands, set variables to anything extracted from (DOS) output, and more.. Win NT/2000 compatible.

This will allow you to do something like:


Assuming that DIR C:\WINDOWS\*.TXT /O:N /-V will give me:

Volume in drive C is GOLDNEW_0-0
Volume Serial Number is 2834-1A0C
Directory of C:\WINDOWS

active~1 txt 31,215 16/01/2003 8:27 Active Setup Log.txt
brndlog txt 10,313 04/04/2003 23:41 brndlog.txt
config txt 17,643 23/04/1999 22:22 CONFIG.TXT
display txt 20,821 23/04/1999 22:22 DISPLAY.TXT

tips txt 12,668 23/04/1999 22:22 TIPS.TXT
wplog txt 0 13/11/2002 11:51 wplog.txt
29 file(s) 503,351 bytes
0 dir(s) 160,890,880 bytes free

Then

DIR *.TXT /O:N /-V|FIND "/"|LMOD /L* [1,8 R8].[10,3 R3] is [17,10 R10] bytes long, LFN is [47]

will give me:

active~1.txt is 31,215 bytes long, LFN is Active Setup Log.txt
brndlog.txt is 10,313 bytes long, LFN is brndlog.txt
config.txt is 17,643 bytes long, LFN is CONFIG.TXT
display.txt is 20,821 bytes long, LFN is DISPLAY.TXT

tips.txt is 12,668 bytes long, LFN is TIPS.TXT
wplog.txt is 0 bytes long, LFN is wplog.txt

Which, of course could br piped to a file via

DIR *.TXT /O:N /-V|FIND "/"|LMOD /L* [1,8 R8].[10,3 R3] is [17,10 R10] bytes long, LFN is [47]>>DLIST.TXT

The Lmod.txt file provided within LMOD.ZIP explains the use of LMOD in detail.

Baldy

(Of course the screen display is monospaced.)


Report Offensive Follow Up For Removal

Response Number 2
Name: Jeremas
Date: August 29, 2003 at 10:53:46 Pacific
Subject: DOS Batch file
Reply: (edit)

In the step 1

DIR C:\WINDOWS\*.TXT /O:N /-V

I receive the next message:

Invalid switch - "V".

What for was intended such switch?


Report Offensive Follow Up For Removal

Response Number 3
Name: Brian HANLON
Date: August 31, 2003 at 05:13:02 Pacific
Subject: DOS Batch file
Reply: (edit)

If you do a DIR /? you'll get:

C:\ >dir /?
Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/P] [/W] [/A[[:]attributes]]
[/O[[:]sortorder]] [/S] [/B] [/L] [/V] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.
(Could be enhanced file specification or multiple filespecs.)
/P Pauses after each screenful of information.
/W Uses wide list format.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date & time (earliest first)
G Group directories first - Prefix to reverse order
A By Last Access Date (earliest first)
/S Displays files in specified directory and all subdirectories.
/B Uses bare format (no heading information or summary).
/L Uses lowercase.
/V Verbose mode.
/4 Displays year with 4 digits (ignored if /V also given).

Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.

So the /-V was to turn VERBOSE OFF if you had a SET DIRCMD which included the /V switch. - You want a bare, non-verbose listing from DIR to make the LMOD job a bit easier, but the switch is not essential. Just check your DIR output by redirecting the DIR command you intend using, into a .txt file and then examining that file. - Makes it easier to get accurate positioning for the LMOD calls, too.
Do a:
DIR C:\WINDOWS\*.TXT [/whatever switches you want to try] >> DLIST.TXT and then examine DLIST.TXT.

Baldy


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: DOS Batch file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software