230409
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
ASKER
script_name.sh and run,
can i use like bourne shell scripts or how can i execute at may system unix solaris 10
thanks