You are here:

C++/File Names Command Line Arguments


I took a filename as a command line argument, now I want to check the presense of any file with same filename in the current directory. How do I do that?

Rakesh , Thank you for your question.

1. Open the file for reading, using CreateFile with the GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, and FILE_ATTRIBUTE_NORMAL flags.

2. Close the file.

3. If the result of the Open was FALSE, the file or folder does not exist.

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.