Exemplo n.º 1
0
static bool cleanOut(const char* dir) {
	printf("cleanOut(%s)\n", dir);
	MAHandle list = maFileListStart(dir, "*");
	MAT(list);
	char buf[2048];
	int dirLen = strlen(dir);
	strcpy(buf, dir);
	int freeBufSpace = sizeof(buf) - dirLen;
	while(1) {
		int res;
		MAHandle fh;
		char* fileName = buf + dirLen;
		res = maFileListNext(list, fileName, freeBufSpace);
		MAT_CUSTOM(res, (_res < 0 || _res >= freeBufSpace));
		if(res == 0)
			return true;
		if(fileName[res-1] == '/') {
			if(!cleanOut(buf))
				return false;
		}
		MAT(fh = maFileOpen(buf, MA_ACCESS_READ_WRITE));
		res = maFileDelete(fh);
		MAASSERT(maFileClose(fh) == 0);
		MAT(res);
	}
	MAASSERT(maFileListClose(list) == 0);
	return true;
}
Exemplo n.º 2
0
	/**
	 * Delete a file or directory. If the file is a
	 * directory it must me empty.
	 */
	static int FileDeleteFile(const String& pathParam)
	{
		String path = pathParam;

		if (FileIsDirectory(path))
		{
			FileMakeDirectoryPath(path);
		}

		MAHandle file = maFileOpen(path.c_str(), MA_ACCESS_READ_WRITE);
		if (file < 0)
		{
			return -1;
		}

		int result = maFileDelete(file);
		maFileClose(file);
		return result;
	}
Exemplo n.º 3
0
static bool deleteIfExist(const MAUtil::String& path) {
	MAHandle file = maFileOpen(path.c_str(), MA_ACCESS_READ_WRITE);
	if(file < 0) {
		printf("Error %i\n", file);
		return false;
	}
	int res = maFileExists(file);
	MAASSERT(res >= 0);
	if(res) {
		printf("File exists.\n");
		res = maFileDelete(file);
		if(res < 0) {
			printf("Error %i\n", res);
			return false;
		}
		printf("Deleted.\n");
	} else {
		printf("File doesn't exist.\n");
	}
	return true;
}