|
I picked up a function RecursiveDelete on the internet, as I needed to erase all files and folders on an SD card (as part of a larger project). I was having problems insofar as the function would fail on removing the folders after CFileDialog DoModal - there were two nested folders, the deepest failing with code 32 ("in use by another proicess") and the shallowest with 145 ("folder not empty" - expected !)
However, if I call the function BEFORE the DoModal, then everything works fine.
I have extracted the relevent code into a simpler project and it still fails
Perhaps some kind soul can throw some light on why this is so !!
CFileDialog dlgFileBrowse(true);
UINT uiFileBrowseDlgRC;
RecursiveDelete("F:");
uiFileBrowseDlgRC = dlgFileBrowse.DoModal();
void CDeleteFolderTestDlg::RecursiveDelete(CString szPath)
{
CFileFind ff;
BOOL bResult;
CString path = szPath;
if(path.Right(1) != '\\')
path += '\\';
path += "*.*";
bResult = ff.FindFile(path);
BOOL bItemDelete;
DWORD dwLastError;
CString szFilePath;
while(bResult)
{
bResult = ff.FindNextFile();
if (!ff.IsDots() && !ff.IsDirectory())
{
szFilePath = ff.GetFilePath();
bItemDelete = DeleteFile(szFilePath);
if(!bItemDelete)
dwLastError = GetLastError();
}
else if (ff.IsDirectory() && !ff.IsDots())
{
path = ff.GetFilePath();
RecursiveDelete(path);
bItemDelete = RemoveDirectory(path);
if(!bItemDelete)
dwLastError = GetLastError();
}
}
}
Doug
modified 16-Jun-15 3:39am.
|
|
|
|
|
I assume that the CFileDialog object contains a handle to the directory once it's opened and that the handle is freed when the dialog object is destroyed. You could try the following:
CFileDialog * dialog = new CFileDialog(true);
dialog->DoModal();
delete dialog;
RecursiveDelete("F:");
Alternatively you could try:
{
CFileDialog dialog(true);
dialog.DoModal();
}
RecursiveDelete("F:");
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Snap.
You beat me by seconds with the solution.
|
|
|
|
|
Freak30 wrote: CFileDialog * dialog = new CFileDialog(true);
dialog->DoModal();
delete dialog;
RecursiveDelete("F:");
Hi Freak30,
Tried the dynamic allocation of the CFileDialog (and deletion before the call to RecursiveDelete)as you suggested, but still get the same result (files deleted, but deepest folder gets RC=32 and shallowest gets RC=145.
Very confused !!
Doug
|
|
|
|
|
When dlgFileBrowse.DoModal() returns, the dialog window has been closed but the object itself still exists and may have open file handles. These should be closed by the destructor of the browse dialog. I have not tested this but it seems a probable reason.
So you should try to call your delete function after the browse dialog object is destroyed:
UINT uiFileBrowseDlgRC;
{
CFileDialog dlgFileBrowse(true);
uiFileBrowseDlgRC = dlgFileBrowse.DoModal();
}
RecursiveDelete("F:");
Alternatively you can create the dialog using new and delete it before calling RecursiveDelete .
|
|
|
|
|
Apologies for the double posting - thought that the original hadn't worked !!
Tried dynamic allocation of dialog and subsequent deletion before calling RecursiveDelete as Freak32 suggested, but get exactly the same result. Wierd !!
Could someone else run this and see if they can reproduce this behaviour ? (Driving me mad !)
Doug
|
|
|
|
|
A quick web research brought some more infomation.
CFileDialog will change the current working directory which may lead to the locked directory. So you may try to also set the current working directory to something else (e.g. to another drive) before calling your delete function:
SetCurrentDirectory(_T("C:\\"));
|
|
|
|
|
Hi Jochen,
Just done a quick check (I actually used _chdir) and that SEEMS to have fixed it. Hopefully, when I migrate these changes to my REAL code, it will stay fixed !
Many thanks to everybody who helped with this - wierd problem, eh ?
Doug
|
|
|
|
|
Thank you for your feedback. _chdir will internally call SetCurrentDirectory .
A directory that is selected as current directory is treated like a file in use and can't be deleted. It seems that the file dialog selects the actually shown directory as the current one and does not change it back. There is an OFN_NOCHANGEDIR file dialog option to restore the original directory but that is ignored for opening files (only supported for the Save as dialog).
|
|
|
|
|
Still learning how to code wrote: I picked up a function RecursiveDelete on the internet, as I needed to erase all files and folders on an SD card... Why not just use SHFileOperation() with the FO_DELETE operation?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
So I have a video stream of known resolution and I have a VR headset via HDMI at a known resolution.
Is there an existing library to create the slight fisheye and side-by-side layout for these headsets?
Target: Win 7/8/10
|
|
|
|
|
I have a csv file. I want to load the csv fil to a database.
I tried by using CDAOSatabase instance with 'Microsoft Text Writer' jet enine.
( One Problem I found that when I execute a query to ceate a new table, the file equivalent to the new table is created in physical disk, even though I didn't commit the transaction)
Also I heard that in windows there will not be a 64bit 'Microsoft Text Writer' in winows 64 bit.
( In my spec there is no MSOffice installed separately on this winows 64 bit machine )
Could ou please let me know is there any solution to use 'Microsoft Text Writer' in Windows64 bit machine without Microsoft office installed.
aks
|
|
|
|
|
|
Hello eeryone, I am Mark, am attending Foothill College in SOCAL and I am cmpletely new to all of this. I am having trouble with my first assignment, I will show you. I am on DEV C++ :
#include
using namespace std;
int main()
{
cout<< "Tran says this is her first computer program.";
}
{ -----------------------------------------
intmain()
cout<< "Tran says that.";
cout<< "this is her first computer program.";
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that,";
cout<< "this is her first computer program.";
cout<< "Tran said that, "This is my first computer program."";
cout<< "Train said that,.";
cout<< ""this is my first computer program."";
cout<< "Tran said that,.";
""this is my first computer program."";
cout<< "Tran said that.";
cout<< ""this is my first computer program."";
}
This is what My teacher said :
Hi Mark,
You can only have "int main()" once in your program. Once you put the close curly brace to end it, you can't have any more code below that. If you take another look through the lesson and the textbook reading, you'll see that all of the examples follow that pattern.
The solution is to put all of the cout statements inside the first set of curly braces, so you don't need any additional curly braces.
Dave
Now, I did this here and this is what happened :
#include
using namespace std;
int main()
{
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that.";
cout<< "this is her first computer program.";
cout<< "Tran says this is her first computer program.";
cout<< "Tran says that,";
cout<< "this is her first computer program.";
cout<< "Tran said that, "This is my first computer program."";
cout<< "Train said that,.";
cout<< ""this is my first computer program."";
cout<< "Tran said that,.";
""this is my first computer program."";
cout<< "Tran said that.";
cout<< ""this is my first computer program."";
}
This is what my computer said :
( I want to post the Pic, I cannot copy and paste it down.Can somone show me how topost pics on here ? Thanks, If I cannot then I will privately email you. )
So I did what the teacher said to do and then I compile and got more lines all messed up. I am confused...
Thanks
|
|
|
|
|
Start simple. First have only one statement within main() :
#include <iostream>
using namespace std;
int main()
{
cout << "Tran says this is her first computer statement." << endl;
return 0;
}
The above is the complete program. No other statements above and below these.
Then, upgrade the program to have two statements:
#include <iostream>
using namespace std;
int main()
{
cout << "Tran says this is her first computer statement." << endl;
cout << "Tran says this is her second computer statement." << endl;
return 0;
}
And then, go on progressively increasing the complexity.
Some compilers need the return 0 statement since your main is returning int .
|
|
|
|
|
I get it, lets try that.
Nope it still wont compile..
Ill keep in touch and sow the tutor tommorow.
Thanks
|
|
|
|
|
Looking at the actual source code in your question you have:
#include
using namespace std;
int main()
...
But the #include statement is incomplete. You must use that statement to include header files which define the various external classes/methods/functions etc, that you wish to use in your program. So, to use the cout command, you must include the header that defines the basic I/O stream classes thus:
#include <iostream>
See https://msdn.microsoft.com/en-us/library/zh80x809(v=vs.100).aspx[^] for more details.
|
|
|
|
|
Hi
I have a method namely CAsyncSocket::OnSend and OnConnect that initially when I start my conversation get called in the context of the main thread
In the notification I do a Detach and PostThreadMessage to a CWinThread which does an attach of the socket
Now the notification routine return the same value for AfxGetApp and AfxGetThread when clearly the notification is received in the context of a UI CWinThread worker thread
|
|
|
|
|
I have a CPropertysheet with several CPropertypage pages. Those normally look like:
job_update.png (18.9 KB)
libl_update.png (30.6 KB)
sched_update.png (18.1 KB)
However, on one specific system, the buttons on the right side of each page are missing:
job_update_2.png (14.6 KB)
libl_update_2.png (14.1 KB)
sched_update_2.png (13.9 KB)
I'm at a loss as to why. The machine has plenty of RAM, has been rebooted, and no other user programs are running. Since it looks fine on hundreds of other machines around the world, what could possibly be up with this one machine? I can't imagine it being a code issue, but that's not something you can tell a customer when they are the one it is happening to.
Thanks for any help.
DC
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
looks like the list control is sizing itself too large and is overdrawing the buttons. maybe that's related to the increased font size on the list control?
try changing your Windows font size?
|
|
|
|
|
Why the compiler take
<h1>pragma comment(lib, "glut32.lib")</h1>
bot not
<h1>pragma comment(lib, "gl/glut32.lib")</h1>
it get me (on second trial):
LINK : fatal error LNK1104: cannot open file "glut32.lib"
It is not possible to have libs in other folders than main one ?
P.S. Of course that I have glut32.lib file on the right path, the problem become that is not recognize gl\glut32.lib path (however glut32.lib is there) !
modified 10-Jun-15 8:17am.
|
|
|
|
|
You are using a relative path vs. an absolute path. A better approach is to just use "glut32.lib" in the #pragma statement, and have the linker configured to search the proper directory for the .lib file with the Additional Library Directories setting.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes, had worked. Thanks !
|
|
|
|
|
class test
{
public:
CString str;
}
test oTest;
oTest.str = "abc";
When I try to write the above object 'oTest' to a simple file using fwrite and CFile and then try to read using fread, I am getting bad pointer in oTest.str
But when I replace the CString member with char array as "char str[50]" and try to write and read file, its working
So I want to know how to write and read a class object with CString member to and from a file
|
|
|
|
|