I am writing a script to create a list of subdirectories contained in a given directory. I start the list with the top level directory and lappend any directories that it finds. I am having a problem getting it to continue past the first level down. What I would like the script to do is read the list as it is updated and continue through until there are no more subdirectories. The code i came up with is this:
proc dirlist { } {
global dirlong
global basedir
global subdir
foreach name $dirlong {
cd $basedir
set current [pwd]
set unsorted [glob -nocomplain *]
if {$unsorted != ""} {
set files [lsort $unsorted]
foreach filename $files {
if {[file isdirectory $filename] != 0} {
set newdir [concat $basedir/$filename]
puts "Appended $newdir"
lappend dirlong $newdir
} else {
lappend filelist $filename
}
}
}
puts "Directory list is\n $dirlong"
}
return
}
proc dirlist { } {
global dirlong
global basedir
global subdir
foreach name $dirlong {
cd $basedir
set current [pwd]
set unsorted [glob -nocomplain *]
if {$unsorted != ""} {
set files [lsort $unsorted]
foreach filename $files {
if {[file isdirectory $filename] != 0} {
set newdir [concat $basedir/$filename]
puts "Appended $newdir"
lappend dirlong $newdir
} else {
lappend filelist $filename
}
}
}
puts "Directory list is\n $dirlong"
}
return
}