To check and Create Folder in Win32 API
-
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC. -
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC. -
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC.#include "shlwapi.h"
TCHAR szDir[20];
_tcscpy( szDir,_T("D:\\MyNewDir\\") );
if(!PathFileExists(szDir))//the directory already exists
if( CreateDirectory(szDir,NULL) )
//MessageBox(NULL,_T("Created"),NULL,MB_OK);PS: You will need to link to shlwapi.lib for using
PathFileExists()
Nobody can give you wiser advice than yourself. - Cicero ப்ரம்மா
-
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC.See
PathFileExists
WhiteSky
-
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC.IF the directory has to exist regardless of it being there already or your having to create it, just call
::CreateDirectory(...)
! If the directory already exists, it will return an error, if it does not, it will attempt to create it. No need for all that other crap unless you really need to know if it exists beforehand. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
#include "shlwapi.h"
TCHAR szDir[20];
_tcscpy( szDir,_T("D:\\MyNewDir\\") );
if(!PathFileExists(szDir))//the directory already exists
if( CreateDirectory(szDir,NULL) )
//MessageBox(NULL,_T("Created"),NULL,MB_OK);PS: You will need to link to shlwapi.lib for using
PathFileExists()
Nobody can give you wiser advice than yourself. - Cicero ப்ரம்மா
Thank you guys CPallini , brahmma , WhiteSky , James R. Twine thanks for the examples. Now I modified the code to as follows
= "C:\\A\\B"; char *lpStr; lpStr = buf; ret = PathFileExists(lpStr); if(ret == 1) { CreateDirectory(lpStr,NULL); }How to link shlwapi.lib file to code ??? I am getting below error error LNK2001: unresolved external symbol __imp__PathFileExistsA@4 fatal error LNK1120: 1 unresolved externals -
Thank you guys CPallini , brahmma , WhiteSky , James R. Twine thanks for the examples. Now I modified the code to as follows
= "C:\\A\\B"; char *lpStr; lpStr = buf; ret = PathFileExists(lpStr); if(ret == 1) { CreateDirectory(lpStr,NULL); }How to link shlwapi.lib file to code ??? I am getting below error error LNK2001: unresolved external symbol __imp__PathFileExistsA@4 fatal error LNK1120: 1 unresolved externalsOpen property window of your project and include lib file to it(I dont have vs2003 now) but I think its on linker additional path(its first item on right panel)
WhiteSky
-
Open property window of your project and include lib file to it(I dont have vs2003 now) but I think its on linker additional path(its first item on right panel)
WhiteSky
-
Thank you guys CPallini , brahmma , WhiteSky , James R. Twine thanks for the examples. Now I modified the code to as follows
= "C:\\A\\B"; char *lpStr; lpStr = buf; ret = PathFileExists(lpStr); if(ret == 1) { CreateDirectory(lpStr,NULL); }How to link shlwapi.lib file to code ??? I am getting below error error LNK2001: unresolved external symbol __imp__PathFileExistsA@4 fatal error LNK1120: 1 unresolved externalsSuresh H wrote:
How to link shlwapi.lib file to code ???
When you include the header file simply add a pragma to link the lib
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")Lot easier than mucking around in the project settings and you will never forget it if you reuse the file in another project.
You may be right I may be crazy -- Billy Joel -- Within you lies the power for good, use it!!!
-
Hello all, I want to check for some folder in C:\ drive if that folder exists by default then no action if that folder does not exits I have to create the folder. For that I have used below code
CFileFind finder; CString szPath , szCMD; szPath = "c:\\A\\B"; if(!finder.FindFile(szPath)) { szCMD = "mkdir "; szCMD += szPath; system((LPCTSTR)szCMD); }
This code properly in MFC application , I want to know how to do it in Win32 API application?? Please help me with this problem. Thanking you, Suresh HC.Use CreateFile with OPEN_EXISTING to detect if directory exists, and, if not, use CreateDirectory(Ex) to create it.
Nuclear launch detected