in reply to Re: problem in checking if directory exists
in thread problem in checking if directory exists
[denzil_cactus]: unless(-d $dir){ `mkdir $dir`;}is this code correct i +f I want to check the directory exists or not? [moritz]: use if (-d $dir) [ysth]: no, the -d could fail if you don't have access (but then you p +robably wouldn't be able to do the mkdir either [ysth]: and use perl's mkdir, not the shell [ysth]: mkdir [ysth]: err, I mean the -d could fail but the directory already exist [moritz]: yes, then use -e instead [moritz]: or whatever test you're feeling lucky with ;-) [ysth]: if you may need to create multiple levels of directory (say, c +reate foo/bar/baz where only foo exists), use File::Path::mkpath (in +an eval {} )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem in checking if directory exists
by moritz (Cardinal) on Mar 31, 2008 at 09:17 UTC | |
by denzil_cactus (Sexton) on Mar 31, 2008 at 13:18 UTC |