Link to home
Start Free TrialLog in
Avatar of 230409
230409Flag for Türkiye

asked on

check existence and attributes of multiple files on unix solaris

i have to parse , and ftp some files, the number of files is unknown but their names are
like *afc*, before starting to work, i want to check if these files exists, and their permisions on the unix system .
can someone help me ? it can be a c source file , or a shell script
i saw this solution,
#include  <stdio.h>
#include  <stdlib.h>
#include <unistd.h>

char *CONFIG_FILE = "user_config";

int main( void )
{
      /* Check for existence */
   if( (access(CONFIG_FILE, F_OK)) != -1 )
   {
      printf( "File exists\n" );

         /* Check for read permission */
      if( (access(CONFIG_FILE, R_OK)) != -1 )
         printf( "File has read permission\n" );

         /* Check for write permission */
         if( (access(CONFIG_FILE, W_OK)) != -1 )
             printf( "File has write permission\n" );
             
         /* Check for write permission */
            if( (access(CONFIG_FILE, X_OK)) != -1 )
                printf( "File has execute permission\n" );
     
   }
   else
   {
      printf( "File does not exists\n" );
   }
}
but i could not understand , where i should write the file names for this program to check, or does it work for multiple files

SOLUTION
Avatar of sugarfreeless
sugarfreeless

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 230409

ASKER

is it ok to save these scripts as

script_name.sh and run,

can i use like bourne shell scripts or how can i execute at may system unix solaris 10

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 230409

ASKER

thanks