Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


What am I doing wrong here with the DeleteFile API?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Mon Jun 16, 2008 10:00 pm    Post subject: What am I doing wrong here with the DeleteFile API? Reply with quote

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
View user's profile Send private message Visit poster's website
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Mon Jun 16, 2008 11:45 pm    Post subject: Reply with quote

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 Smile

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Tue Jun 17, 2008 1:10 pm    Post subject: Reply with quote

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 Smile
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
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 17, 2008 1:35 pm    Post subject: Reply with quote

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 Smile
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.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jun 17, 2008 2:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue Jun 17, 2008 2:26 pm    Post subject: Reply with quote

Folder == directory
_________________
Back to top
View user's profile Send private message
Negima
I post too much
Reputation: 6

Joined: 22 May 2007
Posts: 2221

PostPosted: Mon Jun 23, 2008 11:15 pm    Post subject: Reply with quote

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 Smile
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
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Jun 24, 2008 12:03 am    Post subject: Reply with quote

It looks like it should compile fine

Post the error.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 24, 2008 5:35 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Jun 24, 2008 5:40 am    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 24, 2008 5:45 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites