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
    So did it work that way? If not, what's your current code, what's the error message, and how does the directory look like?
      I dont know what is the reason may be it was some privilege problem but the following code is working fine now

      $dir = "/usr/spool/uucppublic/book_prod"; unless(-d $dir){ `mkdir $dir`; }
      Thanks