Hi evryone
I using MVC++ and built my project using Win32 app.
My program do not have any interfaces. it reads files and it put the output in another file. ( I do not mind put interface only to enter the path)

the thing is I made my program read the input file from specific directory and put the output in the specify directory. the probelm now is that I would like the user to inter the dirctory of the input file and the output file is this possible if yes, please tell me how to do it, I do not have any idea.

"C:\\Wadi\\In\\Log_01.csv" my in file directory
"C:\\Wadi\\Out\\Daily_Summary_%d.csv" my out file directory

now I would like to enable the user to enter his path for the input file and the output file.

Dani AI

Generated

Short practical plan that answers 's "remember the path" question and ties together 's and 's good points:

  1. Decide precedence: command-line args (if present) → saved user setting → built-in default → prompt the user. That lets scripts/advanced users use @kon_t's argv approach, while interactive users get a dialog (as @dandan suggested) only when needed.
  2. Persist the choice per-user (not in Program Files). Two common, simple options are an INI under the user's AppData folder or a registry key under HKCU\Software\YourCompany\YourApp. Prefer AppData for portability and easier troubleshooting.

Example workflow you can implement quickly:

  • On startup, check argc/argv for paths.
  • If none, read settings from %APPDATA%\YourApp\settings.ini (or HKCU).
  • If no saved path, call your file/folder dialog for the user to pick input/output.
  • Validate the chosen path (exists, writable). If OK, save it and continue; if not, show an error and re-prompt.

Minimal C++ sketch (INI method):

// assume iniPath contains "%APPDATA%\\YourApp\\settings.ini"
WritePrivateProfileStringA("Paths","Input",  inputPath.c_str(),  iniPath.c_str());
WritePrivateProfileStringA("Paths","Output", outputPath.c_str(), iniPath.c_str());

char buf[512]={0};
GetPrivateProfileStringA("Paths","Input","",buf,sizeof(buf),iniPath.c_str());
std::string savedInput = buf;

Troubleshooting notes:

  • Make sure the settings directory exists (CreateDirectory) and you have write permission.
  • Normalize/validate paths (check GetFileAttributes != INVALID_FILE_ATTRIBUTES).
  • Handle spaces in paths (wrap in quotes when using command-line).
  • If your app can run headless, require command-line args or a preconfigured INI/registry — don’t show GUI dialogs in that case.

This keeps the UI minimal (only on first-run or manual change), supports automation, and makes the choice persistent and per-user.

Recommended Answers

All 3 Replies

Look in MSDN for GetOpenFileName and SetSaveFileName functions.

Look in MSDN for GetOpenFileName and SetSaveFileName functions.

Hi have this

LPTSTR CommonD_OpenFile()


    {
    
		char* lpszFileName;
    		OPENFILENAME ofn; // common dialog box structure
    	char szFile[260]; // buffer for file name
    	HWND hwnd; // owner window
		hwnd = 0;
		// Initialize OPENFILENAME
    	ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFile = szFile;
    	//
    	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
    	// use the contents of szFile to initialize itself.
    	//
    	ofn.lpstrFile[0] = '\0';
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "Bitmap Files\0*.csv\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
		// Display the Open dialog box. 
		if (GetOpenFileName(&ofn)==TRUE) //Or use GetSaveFileName, same work


        	{
        		int i = (int)strlen(ofn.lpstrFile);
        		lpszFileName = new char[i+10];//init buffer to size needed
        		strcpy(lpszFileName,ofn.lpstrFile); //copy over the file name
        		return(lpszFileName); 
        	}
        	else


            	{
            		lpszFileName = new TCHAR[2];
            		lpszFileName[0]= __TEXT('\0');
            		return (lpszFileName);
		}
        }

then I call it in main
what I would like to do is. I going to post my program to the user. so I would like to enable the user to enter the path for the input file and the output file for the first time and then the system suppose to remember the path and work upon it.

Why not have your program use cmd line arguments. Then your user can specify the output directiry when invoking the prog.

Eg:

prog "D:\output Dir1"

would inform the program to write the output to:
"D:\output Dir1\Daily_Summary_%d.csv"

You could even have then specify the output file name as well.

The advantages of using cmd line args include:
- no gui components required (smaller exe0
- can be called as part of automated scripts without user intervention.
- the code can be compatible with windows & unix

Just look up 'argc & argv' arguments to main() to see how to use cmd line args in your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.