Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:23:23+00:00 2026-05-25T00:23:23+00:00

After opening a directory, I wanna check if a command (such as ls) resides

  • 0

After opening a directory, I wanna check if a command (such as ls) resides within a given directory but open returns an integer i think.. after tokenization, I’m left with some directories… so what can i do?? I was told to use only open() function :((

int       Account_Master;
    .  .  .
  Account_Master = open ("accounts.dat", O_RDONLY);
  if (Account_Master >0) {
    printf ("Open succeeded.\n");

this is the example i used.. whats the point of opening a file if no use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:23:24+00:00Added an answer on May 25, 2026 at 12:23 am

    The integer returned can be given to other functions, such as read, fstat, and close. If you just want to check whether a file exists, use stat:

    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <stdio.h>
    int main(int argc, char* argv[]) {
      struct stat statInfo;
      char* fn = argc>1 ? argv[1] : "/bin/ls";
      int res = stat(fn, &statInfo);
      if (res != 0) {
         printf("File %s does not exist.\n", fn);
         return 1;
      }
      if (statInfo.st_mode & S_IXUSR) {
         printf("Owner can execute the file %s\n", fn);
         return 0;
      }
      printf("File %s is there, but not executable.\n", fn);
      return 2;
    }
    

    If you don’t want to check a single file, but a whole directory, have a look at readdir instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm opening lots of files with fopen() in VC++ but after a while it
I've never compiled before on OS X or using g++, but after opening my
When opening a file directly its fast, but when I open a recent file
After opening a file created by root in vim , how to change the
I'm having some issues understanding how to reference new browser windows after opening them.
After some use Visual Studio 2008 when opening a solution that is checked into
Shell (explorer.exe www.google.com) is how I'm currently opening my products ad page after successful
I am having a problem after opening the notepad once I click the button
I've just taken on a new Asp.Net MVC application and after opening it up
I get this error the first time I build/compile a particular project after opening

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.