TCL- script to output a file which contains size of all the files in the directry and subdirectories -
please me script outputs file contains names of files in subdirectories , memory in bytes, arguement program folder path .output file should file name in 1st column , memory in second column
note:folder contains subfolders...inside subfolders there files
.i tried way
set fp [open files_memory.txt w] set file_names [glob ../design_data/*/*] foreach file $file_names { puts $fp "$file [lindex [exec du -sh $file] 0]" } close $fp
result sample:
../design_data/def/ip2.def.gz 170m ../design_data/lef/tsmc13_10_5d.lef 7.1m
but want file name printed ip2.def.gz , tsmc13_10_5d.lef ..etc(not entirepath) , file memorry should aligned
tcl
the fileutil package in tcllib defines command fileutil::find
, can recursively list contents of directory. can use foreach
iterate on list , sizes of each of them file size
, before producing output puts
, perhaps this:
puts "$filename\t$size"
the $filename
name of file, , $size
how large is. have obtained these values earlier (i.e., in line or 2 before!). \t
in middle turned tab character. replace spaces or comma or virtually else like; call.
to last part of filename, i'd do:
puts $fp "[file tail $file] [file size $file]"
this stuff full information file size, not abbreviated form, if want 4k
instead of 4096
, keep using (slow) incantation exec du
. (if consumer program, or programmer, writing out size in full better.)
Comments
Post a Comment