ENIGMA Forums

Contributing to ENIGMA => Function Peer Review => Topic started by: luiscubal on December 30, 2010, 07:46:53 PM

Title: file_delete
Post by: luiscubal on December 30, 2010, 07:46:53 PM
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());
}
Title: Re: file_delete
Post by: Josh @ Dreamland on December 30, 2010, 09:11:10 PM
It's implemented somewhere. It probably hasn't been included because its set isn't complete.

Most GM functions are easy to implement.
Title: Re: file_delete
Post by: luiscubal on December 31, 2010, 09:25:04 AM
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?
Title: Re: file_delete
Post by: TGMG on December 31, 2010, 09:50:53 AM
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);
Title: Re: file_delete
Post by: luiscubal on December 31, 2010, 10:45:10 AM
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.