Pages: [1]
  Print  
Author Topic: file_delete  (Read 1444 times)
Offline (Unknown gender) luiscubal
Posted on: December 30, 2010, 07:46:53 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
This one looks so easy that it is a shame that ENIGMA doesn't have it already.

Code: (C++) [Select]
#include <stdio.h>
#include <string>

using namespace std;

inline void file_delete(string filename) {
    remove(filename.c_str());
}
Logged
Offline (Male) Josh @ Dreamland
Reply #1 Posted on: December 30, 2010, 09:11:10 PM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2946

View Profile Email
It's implemented somewhere. It probably hasn't been included because its set isn't complete.

Most GM functions are easy to implement.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) luiscubal
Reply #2 Posted on: December 31, 2010, 09:25:04 AM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
I just came across this one for a GM project I was trying to port to ENIGMA. Besides this function was file_exists and user events.

Anyway, besides file_exists, which functions of this "set" are still TODO?
Logged
Offline (Unknown gender) TGMG
Reply #3 Posted on: December 31, 2010, 09:50:53 AM

Developer
Joined: Jun 2008
Posts: 107

View Profile WWW Email
All of them it looks like since this is what file_manip.cpp looks like:
Code: [Select]
int file_exists(std::string fname);           
int file_delete(std::string fname);           
int file_rename(std::string oldname,std::string newname);
int file_copy(std::string fname,std::string newname);     
int directory_exists(std::string dname);     
int directory_create(std::string dname);     

std::string file_find_first(std::string mask,int attr);   

enum {
  fa_readonly  = 1,
  fa_hidden    = 2,
  fa_sysfile   = 4,
  fa_volumeid  = 8,
  fa_directory = 16,
  fa_archive   = 32
};

std::string file_find_next();                 
void file_find_close();               
bool file_attributes(std::string fname,int attr);

std::string filename_name(std::string fname);             
std::string filename_path(std::string fname);             
std::string filename_dir(std::string fname);               
std::string filename_drive(std::string fname);             
std::string filename_ext(std::string fname);               
std::string filename_change_ext(std::string fname,std::string newext);

void export_include_file(std::string fname);                   
void export_include_file_location(std::string fname,std::string location);
void discard_include_file(std::string fname);                 

extern unsigned game_id;
extern std::string working_directory;
extern std::string program_directory;
extern std::string temp_directory;


int parameter_count();
std::string parameter_string(int n);

std::string environment_get_variable(std::string name);
Logged
me
GMbed 2.0 :: Embed you gm games in websites.
Offline (Unknown gender) luiscubal
Reply #4 Posted on: December 31, 2010, 10:45:10 AM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
Code: [Select]
#include <stdio.h>
#include <string>

using namespace std;

int file_delete(string filename) {
    return remove(filename.c_str());
}
int file_rename(string oldname, newname) {
   return rename(oldname.c_str(), newname.c_str());
}

Not sure if the return code is correct, though.
As for file_exists and file_copy, I think there's no standard way to do it. Different solutions for different platforms will have to be used.
Logged
Pages: [1]
  Print