|
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; <br />
CString szPath , szCMD; <br />
szPath = "c:\\A\\B";<br />
if(!finder.FindFile(szPath)) <br />
{ <br />
szCMD = "mkdir "; <br />
szCMD += szPath; <br />
system((LPCTSTR)szCMD); <br />
}<br />
<br />
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.
|
|
|
|
|
You may use FindFirstFile API.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
#include "shlwapi.h"
TCHAR szDir[20];
_tcscpy( szDir,_T("D:\\MyNewDir\\") );
if(!PathFileExists(szDir))<font color=green>
if( CreateDirectory(szDir,NULL) )
<font color=green>
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
<br />
int ret;<br />
<br />
char buf[ ] = "C:\\A\\B"; <br />
char *lpStr;<br />
lpStr = buf;<br />
ret = PathFileExists(lpStr);<br />
if(ret == 1)<br />
{<br />
CreateDirectory(lpStr,NULL); <br />
}
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
|
|
|
|
|
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)
|
|
|
|
|
Thanks WhiteSky i did the changes its working now.
Thank you very much.
|
|
|
|
|
Suresh 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!!!
|
|
|
|
|
|
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!<HR> 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
|
|
|
|
|
Use CreateFile with OPEN_EXISTING to detect if directory exists, and, if not, use CreateDirectory(Ex) to create it.
Nuclear launch detected
|
|
|
|
|
Hi gents,
I want to retrieve image (jpg) file from access database using VC++,
Class:
CDaoDatabase and CDaoRecordset class.
In mdb file. the image stored in Long binary data format.
Sample Code:
COleVariant var;
var = m_recordset.GetFieldValue ( "AF_Photo" );
if ( var.vt == ( VT_ARRAY | VT_UI1 ) )
{
str1.Empty ( );
BYTE* pBytes = new BYTE[var.parray->rgsabound[0].cElements];
void HUGEP *pvData;
HRESULT hr = SafeArrayAccessData(var.parray, &pvData);
for ( int ncount = 0 ; ncount < (var.parray->rgsabound[0].cElements);
ncount++ )
{
pBytes[ncount ] = ( ( BYTE* ) (pvData) ) [ ncount ] ;
}
hr = SafeArrayUnaccessData(var.parray);
outfile.open ( "D:\\Vichu\\Vichu.jpg", ios::out );
for ( int i = 0; i < size; i++ )
outfile << pBytes [ i ];
outfile.close ( );
delete [] pBytes;
Is this code correct or not ?
If correct, that file is not open.
What is the exact solution for this problem ?
I am waiting for your response.
Thanks & Regards,
K.Vishvanathan.
Vichu
|
|
|
|
|
You never check returned values, does you?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
hi,
Yes pallini,But the file pointer wrote some bianry string into that jpg file.
Are the program statments correct ?
Please give clear solution for this issue.
Thanks and Regards,
K.Vishvanathan.
Vichu
|
|
|
|
|
Why do I get "undeclared identifier" error when I try to use "GET_X_LPARAM" Macro? . In the requirement(MSDN), they have specified :
<br />
Header Declared in Winuser.h, include Windows.h <br />
Minimum operating systems Windows 95, Windows NT 3.1 <br />
I have XP.
*
|
|
|
|
|
ca you show a piece of the code around, + the exact error message/code please ?
also, what version of MFC do you use ?
|
|
|
|
|
On my env (Visual Studio 6), I can find the macro defined in windowsx.h header.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hallo,
I have a thread that use object , when I end the thread the object used into the thread do not call the destructor and the let me some leak !
Why the object m_OPCServer & m_OPCStock are not destructed when I stop the thread ?
What can I change into my code that those object will be destructed!
The code:
CWinThread* newthread=NULL;
stop=false;
newthread=AfxBeginThread(ThreadAddOpcServer,LPVOID(&stop),THREAD_PRIORITY_BELOW_NORMAL ,0,CREATE_SUSPENDED );
newthread->ResumeThread();
UINT ThreadAddOpcServer(LPVOID nparam)
{
bool* sstop=static_cast<bool*>(nparam);
static int i=10;
OPCServer m_OPCServer;
StockIOWINCC m_OPCStock(&m_OPCServer);
double movevalue=0;
while(!*sstop) {
m_OPCStock.ChangeStatus("INTERN\\test_opc2",movevalue++);
m_OPCStock.ChangeStatus("INTERN\\test_opc1",10*movevalue);
}
AfxEndThread(0,true);
return 0;
}
Thank for help
AutreChien
|
|
|
|
|
First, when you post code, please use the 'code' tag above the emoticons, it will make your code much more readable.
Second point: why using AfxEndThread ? Your function is finished so your thread will exit. Thus why calling AfxEndThread ?
Third point: you have a loop which check for a flag. But are you setting this flag to false in another thread ? If yes, how are you doing that ? Can you post some code ?
|
|
|
|
|
Cedric Moonen wrote: First, when you post code, please use the 'code' tag above the emoticons
no Cedric, he should use the 'pre' tag ! lol
|
|
|
|
|
Yes I set from button click the variable stop (global variable) as true
void CTestOPCServerDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
stop=true;
OnOK();
}
Thank you for your help!
AutreChien
|
|
|
|
|
I strongly advise you to read Joe Newcomer's article on how to use worker threads to understand how they are supposed to be used and to avoid common pitfalls regarding multithreading.
You'll find it here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Hi everybody,
i have a problem with fullpath file names containing back slashes. The file names are saved in a CString array. The problem are the singel back slashes for ex.
"C:\dir1\dir2\file.txt". Is there an easy way to substitute each "\" with "\\"?
Thanks in advance
|
|
|
|
|
im79 wrote: Is there an easy way to substitute each "\" with "\\"?
CString::Replace()
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
CString has the Replace method, but \ must be properly escaped, for instance:
str.Replace("\\","\\\\")
Sure do you need this?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
don't !!!
'\\' is only the representation in "design mode" (when coding) of the character \ .
when you type a path in windows explorer, you type with a single \ , don't you ?
|
|
|
|