Files
EgtGeneral/FileUtils.cpp
T
Dario Sassi 043554c05d EgtGeneral 1.6e2 :
- aggiornamenti per cambio nome include di base
- modifiche a LuaManager per direttorio librerie lua e ultima Require
- FromString e ToString per STRVECTOR
- corrette FromString per INTVECTOR e DBLVECTOR
2015-05-11 20:57:52 +00:00

132 lines
3.6 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : FileUtils.cpp Data : 11.12.13 Versione : 1.4a5
// Contenuto : Funzioni di utilità sui file.
//
//
//
// Modifiche : 11.12.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "\EgtDev\Include\EgnFileUtils.h"
#include "\EgtDev\Include\EgnStringUtils.h"
#include "\EgtDev\Include\EgtStringConverter.h"
#include <io.h>
using namespace std ;
//----------------------------------------------------------------------------
bool
ExistsFile( const string& sFile)
{
// leggo gli attributi del file
DWORD dwAttr = ::GetFileAttributesW( stringtoW( sFile)) ;
// se non esiste
if ( dwAttr == INVALID_FILE_ATTRIBUTES ||
dwAttr == INVALID_FILE_SIZE)
return false ;
// se è un direttorio
if ( dwAttr & FILE_ATTRIBUTE_DIRECTORY)
return false ;
return true ;
}
//-----------------------------------------------------------------------------
bool
EraseFile( const string& sFile)
{
return ( ::DeleteFileW( stringtoW( sFile)) != 0) ;
}
//-----------------------------------------------------------------------------
bool
FileExtensionMatches( const string& sFile, const string& sExt)
{
string sFileTitle ;
string sFileExt ;
SplitLast( sFile, ".", sFileTitle, sFileExt) ;
ToUpper( sFileExt) ;
string sExtUp = sExt ;
ToUpper( sExtUp) ;
return ( sFileExt == sExtUp) ;
}
//-----------------------------------------------------------------------------
bool
FindFirstFileEgt( const string& sFileSpec, string& sFileName)
{
wstring sFileSpecW ;
wstring sFileW ;
_wfinddata_t c_file ;
intptr_t hFile ;
sFileSpecW = stringtoW( sFileSpec) ;
// cerco il primo file che soddisfa le specifiche
if ( ( hFile = _wfindfirst( sFileSpecW.c_str(), &c_file)) != -1L) {
do {
if ( c_file.attrib != _A_SUBDIR) {
sFileName = LPSTR( WtoA( c_file.name)) ;
_findclose( hFile) ;
errno = 0 ;
return true ;
}
} while( _wfindnext( hFile, &c_file) == 0) ;
_findclose( hFile) ;
errno = 0 ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
ExistsDirectory( const string& sDir)
{
// leggo gli attributi del direttorio
DWORD dwAttr = ::GetFileAttributesW( stringtoW( sDir)) ;
// se non esiste
if ( dwAttr == INVALID_FILE_ATTRIBUTES)
return false ;
// se è un direttorio
return ( (dwAttr & FILE_ATTRIBUTE_DIRECTORY) != 0) ;
}
//-----------------------------------------------------------------------------
bool
EmptyDirectory( const string& sDir)
{
wstring sDirW ;
wstring sFileW ;
_wfinddata_t c_file ;
intptr_t hFile ;
sDirW = stringtoW( sDir) ;
sFileW = sDirW + L"\\*.*" ;
// ciclo su tutti i file del direttorio
if ( ( hFile = _wfindfirst( sFileW.c_str(), &c_file)) != -1L) {
do {
if ( c_file.attrib != _A_SUBDIR) {
sFileW = sDirW + L"\\" + c_file.name ;
::DeleteFileW( sFileW.c_str()) ;
}
} while( _wfindnext( hFile, &c_file) == 0) ;
_findclose( hFile) ;
errno = 0 ;
}
return true ;
}