0

I'm aware of the PHP file_exists function, & is_dir.

I saw about a month ago, a process where you can test BOTH in one search. But I can't find it now.

$file = "/directory/dir2/dir3/filename";

Is there a command based on the filename only - to test if the DIRECTORY exists? (without using 2-3 lines of code)

If the directory does not exist - mkdir (recursive). But if the directory does exist, there's no need to use MKDIR.

I can't find it in the mkdir information

Ps: I do know the mkdir recursive function.

0x5C91
  • 3,360
  • 3
  • 31
  • 46
sarah
  • 102
  • 2
  • 10
  • 1
    you need 2-3 lines of code. – Karoly Horvath Feb 28 '14 at 10:18
  • so your question is you can't find the mkdir function http://nz2.php.net/mkdir right ? check php version – F25rT Feb 28 '14 at 10:20
  • note: can directories be deleted? if so, checking for existence is probably futile. just try to create it. – Karoly Horvath Feb 28 '14 at 10:21
  • http://www.php.net/manual/en/function.mkdir.php It is the third parameter... If you're having trouble, you can use shell_exec with the mkdir-p command, but it is unclear whether or Linux. Se você está com dificuldades, pode usar o shell_exec com o comando mkdir -p, mas isso é claro se or Linux. http://www.php.net/manual/en/function.shell-exec.php http://unixhelp.ed.ac.uk/CGI/man-cgi?mkdir –  Feb 28 '14 at 10:27
  • @sarah: Welcome to Stack Overflow! Your question is interesting, but in the future a little more attention to the formatting (use `code` and [links](http://google.com) where appropriate, and double check grammar at least in the title) will help making your questions more clear. – 0x5C91 Feb 28 '14 at 10:31

2 Answers2

1

Not sure there's a good way of doing this in a particularly short block of code - but you'd struggle to get a more resilient solution than Phazei's recursive directory creation on:

Create a folder if it doesn't already exist

Community
  • 1
  • 1
steve
  • 2,469
  • 1
  • 23
  • 30
0
if (!is_dir(foldername with path)) { 
  mkdir();

}
Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
D-2020365
  • 82
  • 1
  • 11