Hello,
I am trying to write data in an existing file and also create a file that should be located in the Micro SD card on the Ixora board.
The problem is that when I try to write in a file I get an error that the file can’t be open and when I try to create a file I get an error that a file cannot be created.
These are the functions that I wrote:
#define PATH_FILES "/media/A68C-7007"
void createFile(const string& dirPath, const string& fileName) {
string filePath = dirPath + "/" + fileName;
ofstream file(filePath.c_str());
if (!file) {
cout << "Error: could not create file " << filePath << endl;
} else {
cout << "File " << filePath << " created successfully." << endl;
file.close();
}
}
void write_to_file(const string& filePath, const string& newLine) {
ofstream file;
file.open(filePath.c_str(), ios::out | ios::app);
if (file.is_open()) {
file << newLine << endl;
file.close();
cout << "New line added to file." << endl;
} else {
cout << "Error: could not open file." << endl;
}
}
void save_new_file(){
string extention_str = ".txt";
//check if this file already exists
string filename = getCurrentDate() + extention_str;
int fileExists = fileExistsInDir(PATH_FILES, filename);
if (fileExists) {
cout << "File " << filename << " exists in directory " << PATH_FILES << endl;
} else {
cout << "File " << filename << " does not exist in directory " << PATH_FILES << endl;
cout << "Creating file" << PATH_FILES << endl;
createFile(PATH_FILES, filename);
}
write_to_file("/media/A68C-7007/zdr.txt", "ZDR.");
read_file("/media/A68C-7007/zdr.txt");
}
I can read the existing file with no problems.
Because of this I think that the problem might be with some of the permission configurations on the drive but I am not sure what I need to do to allow the writing and creating of files.