Adding directory name to filename

hippie dream tonightsthenight at gmail.com
Fri Mar 5 18:22:00 UTC 2010





That is a bit dangerous because it doesn't check if there is a file with 
the new name. This would be better:

for f in A/*/*.txt;do
  fn=$(basename "$f")
  d=$(dirname "$f")
  dn=$(basename "$d")
  n="$d/$dn$fn"
  test -e "$n" && echo "not renaming $f - $n exists" || mv "$f" "$n" 
done


Nils


Thanks so much Nils! I was being careful so the first script work just fine
for me. Still I appreciate you being careful and thorough. 

Could "f" be any letter or does that specifically refer to a file? In fact
for the whole scripts do you just assignment with variable names or are they
arbitrary? Thanks so much!

Sam



-- 
View this message in context: http://old.nabble.com/Adding-directory-name-to-filename-tp27788509p27797435.html
Sent from the ubuntu-users mailing list archive at Nabble.com.





More information about the ubuntu-users mailing list