# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLMISC::CFile Struct Reference

Utility class for file manipulation. More...

#include <path.h>

List of all members.

Static Public Methods

std::string getFilename (const std::string &filename)
 Retrieve the associated file name. More...

std::string getPath (const std::string &filename)
 Retrieve the associated file path with the trailing slash. More...

bool isDirectory (const std::string &filename)
 Just to know if it is a directory. More...

bool fileExists (const std::string &filename)
 Return true if the file exists. More...

bool isExists (const std::string &filename)
 Return true if the file OR directory exists. More...

std::string findNewFile (const std::string &filename)
 Return a new filename that doesn't exists. More...

int getLastSeparator (const std::string &filename)
 Return the position between [begin,end[ of the last separator between path and filename ('/' or '\'). More...

std::string getFilenameWithoutExtension (const std::string &filename)
std::string getExtension (const std::string &filename)
uint32 getFileSize (const std::string &filename)
 Return the size of the file (in bytes). More...

uint32 getFileModificationDate (const std::string &filename)
 Return Time of last modification of file. More...

uint32 getFileCreationDate (const std::string &filename)
 Return creation Time of the file. More...

void addFileChangeCallback (const std::string &filename, void(*)(const std::string &filename))
 Add a callback that will be call when the content file, named filename, changed. More...

void checkFileChange (TTime frequency=1000)
 You have to call this function evenly (each frame for example) to enable the file change callback system. More...

bool copyFile (const char *dest, const char *src, bool failIfExists=false)
 Copy a file NB this keeps file attributes. More...

bool moveFile (const char *dest, const char *src)
 Move a file NB this keeps file attributes. More...

bool createDirectory (const std::string &dirname)
 create a directory. More...


Detailed Description

Utility class for file manipulation.

Author:
Vianney Lecroart , Nevrax France
Date:
2001

Definition at line 215 of file path.h.


Member Function Documentation

void NLMISC::CFile::addFileChangeCallback const std::string &    filename,
void(*   )(const std::string &filename)
[static]
 

Add a callback that will be call when the content file, named filename, changed.

The system use the file modification date. To work, you need to call evenly the function checkFileChange(), this function only checks every 1s by default (you can change the default time)

ie: void cb (const std::string &filename) { nlinfo ("the file s changed", filename.c_str()); } CFile::addFileChangeCallback ("myfile.txt", cb);

Definition at line 1149 of file path.cpp.

References NLMISC::FileToCheck, and nlinfo.

void NLMISC::CFile::checkFileChange TTime    frequency = 1000 [static]
 

You have to call this function evenly (each frame for example) to enable the file change callback system.

If the file not exists and is created in the run time, the callback will be called. If the file exists and is removed in the run time, the callback will be called.

Parameters:
frequency  the time in millisecond that we wait before check another time (1s by default).

Definition at line 1155 of file path.cpp.

References NLMISC::FileToCheck, and NLMISC::TTime.

bool NLMISC::CFile::copyFile const char *    dest,
const char *    src,
bool    failIfExists = false
[static]
 

Copy a file NB this keeps file attributes.

Parameters:
failIfExists  If the destination file exists, nothing is done, and it returns false.
Returns:
true if the copy succeeded

Definition at line 1194 of file path.cpp.

References NLMISC::CopyMoveFile, and src.

bool NLMISC::CFile::createDirectory const std::string &    dirname [static]
 

create a directory.

Returns:
true if succes

Definition at line 1205 of file path.cpp.

bool NLMISC::CFile::fileExists const std::string &    filename [static]
 

Return true if the file exists.

Warning: this test will also tell that the file does not exist if you don't have the rights to read it (Unix).

Definition at line 1024 of file path.cpp.

string NLMISC::CFile::findNewFile const std::string &    filename [static]
 

Return a new filename that doesn't exists.

It's used for screenshot filename for example. example: findNewFile("foobar.tga"); will try foobar001.tga, if the file exists, try foobar002.tga and so on until it finds an unexistant file.

Definition at line 1030 of file path.cpp.

References num, and NLMISC::smprintf.

string NLMISC::CFile::getExtension const std::string &    filename [static]
 

Definition at line 974 of file path.cpp.

Referenced by NL3D::CAnimationSet::loadFromFiles.

uint32 NLMISC::CFile::getFileCreationDate const std::string &    filename [static]
 

Return creation Time of the file.

0 if not found.

You have to provide the full path of the file (the function doesn't lookup)

Definition at line 1110 of file path.cpp.

uint32 NLMISC::CFile::getFileModificationDate const std::string &    filename [static]
 

Return Time of last modification of file.

0 if not found.

You have to provide the full path of the file (the function doesn't lookup)

Definition at line 1084 of file path.cpp.

Referenced by loadForm.

string NLMISC::CFile::getFilename const std::string &    filename [static]
 

Retrieve the associated file name.

An empty string is returned if the path is invalid

Definition at line 955 of file path.cpp.

Referenced by getFilenameWithoutExtension.

string NLMISC::CFile::getFilenameWithoutExtension const std::string &    filename [static]
 

Definition at line 964 of file path.cpp.

References getFilename.

Referenced by NL3D::CAnimationSet::loadFromFiles.

uint32 NLMISC::CFile::getFileSize const std::string &    filename [static]
 

Return the size of the file (in bytes).

You have to provide the full path of the file (the function doesn't lookup)

Definition at line 1055 of file path.cpp.

int NLMISC::CFile::getLastSeparator const std::string &    filename [static]
 

Return the position between [begin,end[ of the last separator between path and filename ('/' or '\').

If there's no separator, it returns string::npos.

Definition at line 941 of file path.cpp.

string NLMISC::CFile::getPath const std::string &    filename [static]
 

Retrieve the associated file path with the trailing slash.

Returns an empty string if the path is invalid

Definition at line 983 of file path.cpp.

bool NLMISC::CFile::isDirectory const std::string &    filename [static]
 

Just to know if it is a directory.

_FileName empty and path not !!!

Definition at line 992 of file path.cpp.

References nlwarning, and res.

bool NLMISC::CFile::isExists const std::string &    filename [static]
 

Return true if the file OR directory exists.

Warning: this test will also tell that the file does not exist if you don't have the rights to read it (Unix).

Definition at line 1014 of file path.cpp.

bool NLMISC::CFile::moveFile const char *    dest,
const char *    src
[static]
 

Move a file NB this keeps file attributes.

Definition at line 1199 of file path.cpp.

References NLMISC::CopyMoveFile, and src.


The documentation for this struct was generated from the following files: