mkdir

Recursive mkdir() system call on Unix

拥有回忆 提交于 2019-11-27 03:10:33
After reading the mkdir(2) man page for the Unix system call with that name, it appears that the call doesn't create intermediate directories in a path, only the last directory in the path. Is there any way (or other function) to create all the directories in the path without resorting to manually parsing my directory string and individually creating each directory ? Carl Norum There is not a system call to do it for you, unfortunately. I'm guessing that's because there isn't a way to have really well-defined semantics for what should happen in error cases. Should it leave the directories that

C faster way to check if a directory exists

我是研究僧i 提交于 2019-11-27 02:36:10
问题 I'm using opendir function to check if a directory exists. The problem is that I'm using it on a massive loop and it's inflating the ram used by my app. What is the best (fastest) way to check if a directory exists in C? What is the best (fastest) way to create it if doesn't exists? 回答1: You could call mkdir() . If the directory does not exist then it will be created and 0 will be returned. If the directory exists then -1 will be returned and errno will be set to EEXIST . 回答2: Consider using

File.mkdir or mkdirs return false - Reason?

非 Y 不嫁゛ 提交于 2019-11-27 02:02:29
问题 Why file.mkdir is returning false? Google indicates that there could be several reasons (e.g. security, permissions, pathname, etc). My questions: How to find the exact reason of returning false? If security/permissions is a reason, then why is SecurityException not thrown? 回答1: If security/permissions is a reason, then why is SecurityException NOT thrown (which is mentioned in javadoc)? A SecurityException is thrown when you don't have JVM-level permission to do something, not OS-level Is

One command to create and change directory

帅比萌擦擦* 提交于 2019-11-27 01:34:31
问题 I'm searching for just one command — nothing with && or | — that creates a directory and then immediately changes your current directory to the newly-created directory. (This is a question someone got for his exams of "linux-usage", he made a new command that did that, but that didn't give him the points.) This is on a debian server if that matters. 回答1: I believe you are looking for this: mkdir project1 && cd "$_" 回答2: define a bash function for that purpose in your $HOME/.bashrc e.g.

How to find a reason when mkdir fails from PHP?

馋奶兔 提交于 2019-11-26 21:10:49
问题 PHP's mkdir function only returns true and false. Problem is when it returns false. If I'm running with error reporting enabled, I see the error message on the screen. I can also see the error message in the Apache log. But I'd like to grab the text of the message and do something else with it (ex. send to myself via IM). How do I get the error text? Update: Following Ayman's idea, I came to this: function error_handler($errno, $errstr) { global $last_error; $last_error = $errstr; } set_error

Why can't PHP create a directory with 777 permissions?

坚强是说给别人听的谎言 提交于 2019-11-26 19:41:38
I'm trying to create a directory on my server using PHP with the command: mkdir("test", 0777); But it doesn't give full permissions, only these: rwxr-xr-x The mode is modified by your current umask , which is 022 in this case. The way the umask works is a subtractive one. You take the initial permission given to mkdir and subtract the umask to get the actual permission: 0777 - 0022 ====== 0755 = rwxr-xr-x. If you don't want this to happen, you need to set your umask temporarily to zero so it has no effect. You can do this with the following snippet: $oldmask = umask(0); mkdir("test", 0777);

Bash mkdir and subfolders [duplicate]

走远了吗. 提交于 2019-11-26 18:58:42
问题 This question already has answers here : How to create nonexistent subdirectories recursively using Bash? (4 answers) Closed 3 years ago . Why I can't do something like this? mkdir folder/subfolder/ in order to achive this I have to do: mkdir folder cd folder mkdir subfolder Is there a better way to do it? 回答1: You can: mkdir -p folder/subfolder The -p flag causes any parent directories to be created if necessary. 回答2: To create multiple sub-folders mkdir -p parentfolder/{subfolder1

How do I include parameters in a bash alias? [duplicate]

霸气de小男生 提交于 2019-11-26 18:13:21
问题 This question already has an answer here: Make a Bash alias that takes a parameter? 13 answers Trying to create: alias mcd="mkdir $1; cd $1" Getting: $ mcd foo usage: mkdir [-pv] [-m mode] directory ... -bash: foo: command not found What am I doing wrong? 回答1: An alias can only substitute the first word of a command with some arbitrary text. It can not use parameters. You can instead use a shell function: mcd() { test -e "$1" || mkdir "$1" cd "$1" } 来源: https://stackoverflow.com/questions

How to mkdir only if a dir does not already exist?

旧城冷巷雨未停 提交于 2019-11-26 18:02:30
I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that the directory does not exist, or suppress the "File exists" error that mkdir throws when it tries to create an existing directory. Any thoughts on how best to do this? Try mkdir -p : mkdir -p foo Note that this will also create any intermediate directories that don't exist; for instance, mkdir -p foo/bar/baz will create directories foo , foo/bar ,

How to mkdir only if a dir does not already exist?

久未见 提交于 2019-11-26 08:53:52
问题 I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that the directory does not exist, or suppress the \"File exists\" error that mkdir throws when it tries to create an existing directory. Any thoughts on how best to do this? 回答1: Try mkdir -p: mkdir -p foo Note that this will also create any