Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code to delete a folder (not empty):
SHFILEOPSTRUCT fos = {};
                fos.wFunc = FO_DELETE;
                fos.pFrom = szTitlef;//path of folder ex: "D:\\tmp"
                fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
                int t = SHFileOperation(&fos);
                if ( t !=0)
                {
                    //send error
                }


but result is fail! i don't know where 's my code's problem.

And i want to rename a folder, i don't know any function can use.
Thanks for all help!
Posted
Updated 22-Apr-10 22:22pm
v2

Yes I understood that the first time. But us szTitlef double NULL terminated? You can double NULL terminate a string by appending "\0\0", for example;

C++
char buffer[] = "D:\\Temp";
int len = strlen(buffer);
char* folderName = new char[len+2];
strcpy(folderName, buffer);
folderName[len]   = '\0';
folderName[len+1] = '\0';


Did you checked what GetLastError returns?

-Saurabh
 
Share this answer
 
v3
Is szTitlef double null terminated? You can also use GetLastError to find out why SHFileOperation is not working.

-Saurabh
 
Share this answer
 
When i debug, szTitlef is "D:\\tmp". but i can't delete it
 
Share this answer
 
If u dont bother using File operation API then
i have a option for you MoveFileEx to rename your folder.

Eg:-
<pre>
MoveFileEx("D:\\data1", TEXT("D:\\data2"), MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
 
Share this answer
 
Thanks for your help, so i solved my problem. thank you very much!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900