Files
EgtGeneral/FileUtils.cpp
T
Dario Sassi cf134d36d7 EgtGeneral 1.5f1 :
- agg. funzioni sui file (Exists e MatchExt).
2014-06-03 13:13:58 +00:00

89 lines
2.4 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\EgnStringConverter.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
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 ;
}