When using the tcsh shell, how do I check if a folder does NOT exist?
I can check if it exists by
if ( -d /folder ) then
but I want the if statement to work for folders that don't exist.
Just use
if (! -d /folder ) then
#run some code here, if the folder does not exist
One thing you could do is use an else
:
#!/usr/bin/tcsh
if ( -d folder) then
else
echo no
endif
Alternatively, you can do a negative check:
#!/usr/bin/tcsh
if (! -d folder) then
echo "No such folder"
The following script will check for the existence of the directory. If the directory does not exist, it is going to be created
#!/usr/bin/tcsh
if ( -e directory_name ) then
echo 'Directory "directory_name" exists'
else
mkdir directory_name
echo 'Directory "directory_name" created'
endif
/folder
is present, but a file? Or a link? Or some other type?