| View previous topic :: View next topic |
| Author |
Message |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2221
|
Posted: Mon Jun 16, 2008 10:00 pm Post subject: What am I doing wrong here with the DeleteFile API? |
|
|
| Code: | #include <iostream>
#include <windows.h>
int main()
{
signed int x;
std::cout << "Welcome to Negi_trainer\n";
DeleteFile("C:\\New Folder");
system("pause");
std::cout << "Please enter some numbers\n";
std::cin >> x;
std::cout << "The number(s) you entered are " << x << "\n";
system("pause");
return 0;
}
|
|
|
| Back to top |
|
 |
STN I post too much
Reputation: 43
Joined: 09 Nov 2005 Posts: 2676
|
Posted: Mon Jun 16, 2008 11:45 pm Post subject: |
|
|
You can't use DeleteFile() for removing directories, it will fail. Use RemoveDirectory() instead to delete a directory. Also note that the directory you are trying to delete must be empty otherwise RemoveDirectory() will fail.
Hope it helps
_________________
|
|
| Back to top |
|
 |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2221
|
Posted: Tue Jun 17, 2008 1:10 pm Post subject: |
|
|
| STN wrote: | You can't use DeleteFile() for removing directories, it will fail. Use RemoveDirectory() instead to delete a directory. Also note that the directory you are trying to delete must be empty otherwise RemoveDirectory() will fail.
Hope it helps  | Thanks, but I'm not trying to delete a directory, the folder known as "new folder" is located inside the C:\ directory
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jun 17, 2008 2:19 pm Post subject: |
|
|
| Didn't you end up asking this a long ass time ago only to end up posting a version that deleted windows files in random spam?
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Tue Jun 17, 2008 2:26 pm Post subject: |
|
|
Folder == directory
_________________
|
|
| Back to top |
|
 |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2221
|
Posted: Mon Jun 23, 2008 11:15 pm Post subject: |
|
|
| Wiccaan wrote: | | Negima wrote: | | STN wrote: | You can't use DeleteFile() for removing directories, it will fail. Use RemoveDirectory() instead to delete a directory. Also note that the directory you are trying to delete must be empty otherwise RemoveDirectory() will fail.
Hope it helps  | Thanks, but I'm not trying to delete a directory, the folder known as "new folder" is located inside the C:\ directory |
| Code: | | DeleteFile("C:\\New Folder"); |
Your code clearly states it's trying to delete a folder. You might need to reword what you are asking as it doesn't seem you are coming across clearly. | Problem is the script wont even compile
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jun 24, 2008 12:03 am Post subject: |
|
|
It looks like it should compile fine
Post the error.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Jun 24, 2008 5:35 am Post subject: |
|
|
I assume it doesn't compile because you are using the default character set, Unicode, while the code posted above is Multibyte. You can either use the Unicode version of the same code and functions, or, switch the character set in the project properties.
Unicode version of what is posted above. (Not fixing code just recoding it to be Unicode..)
| Code: | #include <iostream>
#include <windows.h>
int main()
{
signed int x;
std::wcout << L"Welcome to Negi_trainer\n";
DeleteFile(L"C:\\New Folder");
system("pause");
std::wcout << L"Please enter some numbers\n";
std::wcin >> x;
std::wcout << L"The number(s) you entered are " << x << L"\n";
system("pause");
return 0;
} |
_________________
- Retired. |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Tue Jun 24, 2008 5:40 am Post subject: |
|
|
Try this:
| Code: | #include <windows.h>
#include <tchar.h>
#include <stdio.h>
BOOL main( void )
{
BOOL DFile = DeleteFile(_T("Video.avi"));
_tprintf(_T("%d\n"), DFile); //0 = failed or file does not exists, 1 = success
DFile == 1 ? printf("Success\n") : printf("Fail\n");
return DFile;
} |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Jun 24, 2008 5:45 am Post subject: |
|
|
You can find a detailed, commented, useful example of how do use the API here:
http://msdn.microsoft.com/en-us/library/aa365204(VS.85).aspx
It has some basic checking to determine if you are able to delete the given file or not to prevent unwanted errors and such.
_________________
- Retired. |
|
| Back to top |
|
 |
|