0

I have been looking at many tutorials but a lot of it doesn't make sense to me. I am not that new to cplusplus, but when it comes to managing directories it becomes rather overwhelming.

What I have been trying to do is get the current path that the executable is in.

D:\Users\Me\Documents\Project\MGen\MGen.exe

Then I want to create a folder that is back one folder from the executable if that folder does not exist.

D:\Users\Me\Documents\Project\NewFolder

Finally, I want to insert a text file into that new folder

D:\Users\Me\Documents\Project\NewFolder\new.txt

I have been scratching my head all night and day but haven't figured out anything. I have been seeing a lot of this

LPCWSTR lpFileName DWORD nBufferLength LPWSTR lpBuffer, LPWSTR *lpFilePart

But not of these things mean anything to me. I don't know what they want, what they mean, what they do. What inputs do they take? I see them in almost every set of parameters that deal with directories.

Jaedon KLB
  • 67
  • 1
  • 1
  • 6
  • Those look like parameters to the functions. Win32 API uses lots of typedefs. For example, `DWORD` is an `unsigned long`. See: [Windows Data Types](https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types) – 001 Apr 06 '20 at 20:12
  • The current directory of a process is unrelated to the location of the executable. So the first piece, finding the directory of the executable, is already non-trivial. https://stackoverflow.com/q/1528298/1216776 – stark Apr 06 '20 at 20:27

1 Answers1

0

You didn't list the functions you were using so I'll use fopen as a example.

fopen("thisfile.txt",'r'); will target the directory the .exe is running out of. If the thisfile.txt exist in that directory it will open it for reading.

fopen("../thisfile.txt",'r'); will look in the directory underneath the one the .exe is running in. for example if the exe is in D:\Users\Me\Documents\Project\MGen\ the command will look in D:\Users\Me\Documents\Project for the txt file.

if you wanted to find the file in D:\Users\Me\Documents\Project\NewFolder then put this. fopen("../NewFolder/thisfile.txt",'r');

you can also navigate several directories back by adding multiple ../../

Also: LPCWSTR is a pointer to a const wchar array. DWORD is a 32 bit value (you put a number here). LPWSTR is a pointer to a wchar array.

If you provide some code and more specifics I can give you a better answer of what you should be putting there.

user2076574
  • 166
  • 3
  • 12