|
Hello George_George, I'll tell u the exact problem u r having and how to rectify it.
Your Code:-------------------------------------------------
int remove_non_empty_directory (const char* path)<br />
{<br />
<br />
WIN32_FIND_DATA FindFileData;<br />
HANDLE hFind;<br />
int rtn;<br />
<br />
hFind = FindFirstFile(path, &FindFileData);<br />
if (hFind == INVALID_HANDLE_VALUE)<br />
{<br />
FindClose(hFind);<br />
return -1;<br />
}<br />
else<br />
{<br />
rtn = <pre>DeleteFile(&(FindFileData.cFileName));</pre><br />
<code>if (0 == rtn)<br />
{<br />
ErrorExit (NULL);<br />
}<br />
<br />
while (FindNextFile(hFind, &FindFileData) != 0)<br />
{<br />
rtn = <pre>DeleteFile(&(FindFileData.cFileName));</pre><br />
<code>}<br />
<br />
FindClose(hFind);<br />
}
----------------------------------------------------------
The problem lies in the highlighted lines. FindFileData.cFileName contains only the FILE NAME, NOT PATH. So the problem. Rectify it by replacing the highlighted lines by DeleteFile(path);
Come online at:-
jubinc@skype
|
|
|
|
|
Don Box wrote: Rectify it by replacing the highlighted lines by DeleteFile(path);
That won't work as he is most likely passing in just a folder name, or a folder name with a wildcard attached.
He should take the original path (excluding wildcard) and then add the filename from FindFileData.cFileName and then Delete that.
regards,
|
|
|
|
|
You are always right, Jonathan!
regards,
George
|
|
|
|
|
George_George wrote: You are always right, Jonathan!
Only most of the time
best wishes,
|
|
|
|
|
Thanks Don!
It works! Cool!
regards,
George
|
|
|
|
|
Hi
I was just looking at your problem and why not try someting completely different.
You could create a batch file which deletes the files within a folder.
1. Create a new text file for writing to (say on your c:\) with the extension of ".BAT"
2. Write to that file the path of the directory you want to delete, fprintf(cfile,"del %s\*.*",pathname)
3. Close the file
4. Using the SPOOL command run the file.
Just a quick solution to your problem.
Bry.
|
|
|
|
|
Thanks Bryster,
I need to implement through Windows API to be more efficient.
regards,
George
|
|
|
|
|
Are you sure that those files are not read only.
As once i wasalso facing the same problem but after checking out read only attribute. it was working fine...
Who am I?
Do you know me....
|
|
|
|
|
George_George wrote: I am using the following program to delete all files in a specified directory.
Why not just use SHFileOperation() ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Sure, gvisgr8. I have enough privilege.
regards,
George
|
|
|
|
|
Because I suspect on Windows Mobile it is not supported -- I need to write program for both Windows desktop and Window CE.
regards,
George
|
|
|
|
|
George_George wrote: Sure, gvisgr8.
I'm not gvisgr8.
George_George wrote: I have enough privilege.
I was not concerned with privileges. I was simply suggesting replacing dozens of lines of code with a single one.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How?
DavidCrow wrote: I was simply suggesting replacing dozens of lines of code with a single one.
regards,
George
|
|
|
|
|
George_George wrote: How?
By using SHFileOperation() instead.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
This function is convenient to use, but I am not sure whether we can use it on Windows CE.
regards,
George
|
|
|
|
|
Hello,
I am using the command getline() to get the line of a text file.. But i think i have a problem with this command.
Here is how i used it in my programme:
getline(list,s1);
list is
fstream list;<br />
list.open("listfile.txt",ios::in);
and s1 is string s1;
The included libraries of my programme are :
#include <cstdlib><br />
#include <iostream><br />
using namespace std;<br />
#include<fstream><br />
#include<stdio.h> <br />
#include <time.h><br />
#include <sstream><br />
#include<string>
I was wondering if getline() had a limit of character by line, and if it is so, how can i know its limit and change it.
Thank you
|
|
|
|
|
I am not sure at 100% but I think the getline () works buffering, so it is supposed to get the text until it founds an "\n" to change line.
About your includes... write the lines with a space between "<" and ">" I mean... you have to write i.e. #include < math.h > because if not, the web trys to use it as < pre > and so on...
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
ok thank you very much for this answer.
|
|
|
|
|
garfaoui wrote: #include
#include
using namespace std;
#include
#include
#include
#include
#include
Is it so hard to go back and preview your post to make sure it reads exactly as you expect?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hum ...
|
|
|
|
|
The Preview button works regardless of whether you are humming or singing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
OKKKKKKKKK....
i didnt know that such a button exist... sorryyyyyyyyy
what should i do kneeing at your foot? i apologise, it s not enough?
|
|
|
|
|
garfaoui wrote: i didnt know that such a button exist... sorryyyyyyyyy
It's right next to the Post Message button.
garfaoui wrote: what should i do kneeing at your foot? i apologise, it s not enough?
Sarcasm and apologies are not necessary. I was merely letting you know a way of increasing your chances of receiving help.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: garfaoui wrote:
i didnt know that such a button exist... sorryyyyyyyyy
It's right next to the Post Message button.
I have been posting message since a week. I didn´t take time to look at every button... That´s all.
DavidCrow wrote:
Sarcasm and apologies are not necessary.
I thought that too, but a simple " hum..." seemed not to be enough because you felt posting a new message...
However you didn´t "merely letting [me] know a way of increasing [my] chance of receiving help. "
I "paid" for each person who did that. You didn´t need to say "is it so hard to..." just give me the information. That´s all. There is no need of being haughty with me.
|
|
|
|
|
garfaoui wrote: I thought that too, but a simple "hum..." seemed not to be enough because you felt posting a new message...
The word "hum" is meaningless when no context is provided.
garfaoui wrote: However you didn´t "
merely letting [me] know a way of increasing [my] chance of receiving help.
Why would you expect to receive help when over half of your code snippet cannot be read? Format your code properly, and double-check your grammar, before committing your posts. You'll receive much more help as a result.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|