The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to check if a direcorty exists? SunnyK Shell Programming and Scripting 2 11-08-2007 10:47 AM
how to check the actual path instead of link path reldb UNIX for Advanced & Expert Users 4 10-04-2006 09:55 AM
check if directory exists jerardfjay Shell Programming and Scripting 2 06-13-2005 02:26 PM
check if exists a .ZIP file and unzip it using ftp DebianJ Shell Programming and Scripting 1 05-05-2005 04:46 PM
perl ftp check file exists methos Shell Programming and Scripting 2 06-18-2003 08:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2008
MartyIX MartyIX is offline
Registered User
  
 

Join Date: May 2008
Posts: 68
How to check if all directories of file's path exists?

I wonder if the script below is possible to write somehow more efficiently. It seems to me the problem is very common..

CreateFolders() # parameter: name of file with relative path with regard to directory $project_root
{
echo $1 | awk '{ n=split($1, array, "/");
for (i=1;i<n;i++) {
print array[i]
}
} ' >"$project_root/createDirectory.tmp"

if [ -s "$project_root/createDirectory.tmp" ]; then

folder=$project_root

while read subdir; do

if [ ! -d "$folder/$subdir" ];then
mkdir "$folder/$subdir"
fi

cd "$folder/$subdir"

folder="$folder/$subdir"

done<"$project_root/createDirectory.tmp"

fi

rm "$project_root/createDirectory.tmp";
}

Thank you for help
  #2 (permalink)  
Old 08-19-2008
amsct amsct is offline
Registered User
  
 

Join Date: Aug 2008
Location: Amsterdam, The Netherlands
Posts: 33
I'm not sure I understand what you exactly are trying to do.
You can use mkdir -p <directory tree> to create the whole tree in one go
e.g.:
folder=${project_root}/local/pub/etc
mkdir -p $folder
  #3 (permalink)  
Old 08-19-2008
MartyIX MartyIX is offline
Registered User
  
 

Join Date: May 2008
Posts: 68
thanks you! it's pretty faster way
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0