Ubuntu: check if folder does not exist in tcsh


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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »