Quick question: recursive touch?

Charles G Waldman cgw at fnal.gov
Wed Oct 6 04:20:59 EDT 1999


Preston Landers writes:
 > Anyone know of a function equilivent in concept to a 'recursive
 > touch?'
 > 
 > Where if I say:
 > 
 > touch foo/bar/baz.txt
 > 
 > If the directories foo and bar don't exist, create them, then create
 > baz.txt inside of bar.
 > 
 > An equivilent unix command would suffice.


I'd use something like the following Bourne-shell function:

touch() {
  mkdir -p `dirname $1`
  touch $1
}

then "xtouch foo/bar/baz.txt"  will do what you want.





More information about the Python-list mailing list