古い回答を使用してtclでファイルを検索する: https ://stackoverflow.com/a/435094/984975
まず、私が今何をしているのかを話し合いましょう:この関数の使用:(Jacsonへのクレジット)
# findFiles
# basedir - the directory to start looking in
# pattern - A pattern, as defined by the glob command, that the files must match
proc findFiles { basedir pattern } {
# Fix the directory name, this ensures the directory name is in the
# native format for the platform and contains a final directory seperator
set basedir [string trimright [file join [file normalize $basedir] { }]]
set fileList {}
# Look in the current directory for matching files, -type {f r}
# means ony readable normal files are looked at, -nocomplain stops
# an error being thrown if the returned list is empty
foreach fileName [glob -nocomplain -type {f r} -path $basedir $pattern] {
lappend fileList $fileName
}
# Now look for any sub direcories in the current directory
foreach dirName [glob -nocomplain -type {d r} -path $basedir *] {
# Recusively call the routine on the sub directory and append any
# new files to the results
set subDirList [findFiles $dirName $pattern]
if { [llength $subDirList] > 0 } {
foreach subDirFile $subDirList {
lappend fileList $subDirFile
}
}
}
return $fileList
}
そして、次のコマンドを呼び出します。
findFiles some_dir_name *.c
現在の結果:
bad option "normalize": must be atime, attributes, channels, copy, delete, dirname, executable, exists, extension, isdirectory, isfile, join, lstat, mtime, mkdir, nativename, owned, pathtype, readable, readlink, rename, rootname, size, split, stat, tail, type, volumes, or writable
さて、実行すると:
glob *.c
たくさんのファイルを取得しますが、それらはすべて現在のディレクトリにあります。
目標は、マシン上のすべてのサブフォルダー内のすべてのファイルとそのパスを取得することです。助けてくれる人はいますか?
私が本当にやりたいのは、*。cファイルの数が最も多いディレクトリを見つけることです。ただし、すべてのファイルとそのパスを一覧表示できれば、各ディレクトリにあるファイルの数を数えて、数が最も多いファイルを取得できます。