私は初心者で、TCL のファイル名のリストから取得したいくつかのファイルに .skip 拡張子を追加しようとしています。fileName.skip のファイルが既に存在する場合は、エラーをキャッチし、独自のメッセージを画面に表示して、次のファイルに進みたいと思います。私が使用しているコードは次のとおりです。
set i 0
foreach fileName [glob -nocomplain -type f [file join $basedir *.wav]] {
foreach line $fileData {
if { [regexp $line $fileName] == 1 } {
if { [catch {file rename $fileName "$fileName.skip"}] } {
puts "Error skipping $fileName skipped file already exists"
continue
} else {
puts "Skipping $fileName..."
file rename [file join $basedir $fileName] [file join $basedir "$fileName.skip"]
incr i
}
}
}
}
私のフォルダには、テストしている 3 つのファイルがあります。
test21.wav
test21.wav.skip
test22.wav
このコードは、ファイルの名前を変更する (または名前を変更しない) ところまで実行されますが、次のように画面に出力されます。
Error skipping C:/xxx/test21.wav file already exists
Skipping C:/xxx/test22.wav...
error renaming "C:/xxx/test22.wav": no such file or directory
while executing
"file rename $fileName "$fileName.skip""
スクリプトが機能するため、このエラーが何であるかを理解できないようです。私の使い方catch
が間違っているのでしょうか?それとも別物なのかしら……。
よろしくお願いします。