Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

batch script to list files and sizes 1

Status
Not open for further replies.

glyrocks

Technical User
Nov 16, 2006
57
0
0
US
Hello all,

I'm in need of some batch script help. I need to create a formatted text file that looks like this:

Code:
ROOT

l_comm_info.e00			3,939
l_mt1_lomc.e00			7,985


ROOT/SUBFOLDER1/

l_stn_start.e00			2,677
l_wtr_nm.e00			8,845
study_info.e00			4,608


ROOT/SUBFOLDER2/

s_base_index.e00		6,923
s_bfe.e00			64,696
s_firm_pan.e00			17,239

and so on... with the left column being the file name, the right the file size in KB (only they're better aligned).

I've written a couple light-duty batch scripts before so I'm mildly familiar with them, but I don't know how to go about the formatting. I can get all the information I need using DIR /S>list.txt. This, however, gives me more information than I need so even being able to remove extraneous lines of text would be a good start for us.

Any help would be very appreciated! Thanks!

dylan
 
Code:
@ECHO OFF
PUSHD "%~f1"
SETLOCAL
SET FOO=%~f1
ECHO %FOO:\=/%/
ENDLOCAL
ECHO.
FOR /F "usebackq tokens=4-5" %%A IN (`DIR /A-D 2^>NUL ^| FINDSTR /R "^[0-9]"`) DO ECHO %%B		%%A
ECHO.
FOR /F "usebackq tokens=4*" %%A IN (`DIR /AD ^| FINDSTR /R "^[0-9]" ^| FINDSTR /V /R "\.*\.$"`) DO PUSHD "%%B" & CALL %~fs0 .
POPD
POPD
ECHO.
 
Huh, well that's cool! I have a vague idea of how it's doing that, but there are a few things in there I'm clueless on. I really appreciate the code.

One thing I didn't specify clearly is how the ROOT should actually display. We don't need it to return the path all the way back to the label. So if the folder it's searching is C:\ws\database\export I only need to see the folder it's in

Code:
export

file0  123


export\folder1

file1   123
file2   123


export\folder2

file3   123
file4   123

as opposed to:

Code:
C:\ws\database\export

file0   123

C:\ws\database\export\folder1

...


How do you suggest I remove the extra directory information?

Thanks again!

dylan
 
well you could look at using the SET command for substrings
(see "set /?")
might need "delayed environment variable expansion" too
(see same reference above)
and instead of the batch file recursively calling itself,
you could look at "CALL :label arguments"
(see "call /?")

I was just messing around with the batch file
this would of course be much easier using VBScript
 
WinDirStat is a graphical application that is tiny and does the same thing:


It gives you a to-scale image of your file system. Neat!

Tony

Users helping Users...
 
Right on, I'll check into that. I jumped on a .bat just because it was the first thing I thought of... Your script gets us plenty close, thanks again!

dylan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top