create a directory in gawk
Hi,
I tried to create a directory in my gawk script using mkdir but it is not working. Does someone know how to do it? Thank you so much. Duparcmeur |
Hi,
From OReilly's Sed&Awk book: Quote:
|
I did
BEGIN { if (system("mkdir dale") != 0) command but I don't what to create the directory if it doesn't exist. is there a command to do that? Thanks, Duparcmeur |
did
BEGIN { if (system("mkdir dale") != 0) command but I don't want to create the directory if it doesn't exist. is there a command to do that? Thanks, Duparcmeur |
Hi,
I probably don't understand what it is you want to do: - You do _not_ want to create the dir if it does _not_ exist. What is the point in creating it if it does exist? |
mkdir -p dir will only create dir if it does not exist; if dir exists this command will do nothing. Alternatively you can create shell logic with a statement containing something like if ![ -d $directory ]; then mkdir $directory; fi --- double check me on the location of that negation (!) - basically this reads "If the directory defined by the variable $directory does not exist, then run the command mkdir $directory.
If I messed up the syntax, double check me on that, but from an algorithm standpoint, this is the idea. You have a couple choices. The mkdir -p sidesteps the entire issue, as long as you are confident of the name of the directory you are creating, because with -p you will not get any feedback whether the command worked or not. With the if logic, you could put in some diagnostic print statements to let you know if the directory got created or not, plus you could insert an ls statement to list your directories to see what you have - either the specific directory you are interested in or anything around it in the directory hierarchy. Hope this is useful. |
Quote:
|
All times are GMT -5. The time now is 02:55 AM. |