1

I am developing a C++ application for win32 console

I need to get list of files in my application directory

(for example if my application had been started in C:\arash\app\ I need list of files in this folder)

I searched and find FindFirstFile function in windows.h header , But this function need a directory path .

Can I use this function for getting list of files in my application running directory?

Thanks

Peter Wood
  • 23,859
  • 5
  • 60
  • 99
Arashdn
  • 691
  • 3
  • 11
  • 25
  • I have edited your title. Please see, ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/), where the consensus is "no, they should not". – default Jan 15 '13 at 13:12
  • @Default Funny, I can remember ["How do I write a good title?"](http://meta.stackexchange.com/a/10648/153990) to suggest the opposite. – Kos Jan 15 '13 at 13:14
  • @Kos interesting.. Although, I'd have to agree with Jeff Atwood on that "I think it is fine to duplicate the tags in the title, but only when they can be worked into the titles organically and conversationally." Here, it was not. – default Jan 15 '13 at 13:18
  • You are right , I am sorry – Arashdn Jan 15 '13 at 13:25
  • possible duplicate of [Find what directory the running process EXE is stored in](http://stackoverflow.com/questions/3364589/find-what-directory-the-running-process-exe-is-stored-in) – Raymond Chen Jan 15 '13 at 17:15

2 Answers2

4

Use GetModuleFileName() with a NULL module handle to get the path and filename of the .exe file. You can then strip off the filename portion, and use the remaining path as needed.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
1

The current working directory is '.'.

As noted in comments, this isn't necessarily the directory you want.

Peter Wood
  • 23,859
  • 5
  • 60
  • 99
  • 1
    That is the Current Working Directory, which can change dynamically during the process's lifetime, and is not guaranteed to always reflect the folder that the app is running from. – Remy Lebeau Jan 15 '13 at 16:39
  • 1
    `.` and `..` are relative to the process's CWD, not the actual .exe file. Things like OS file dialogs and desktop shortcuts can change the CWD, as well as code calling the `SetCurrentDirectory()` function. – Remy Lebeau Jan 15 '13 at 16:51