69de0d5f78
- agg. funzione FindFirstFileEgt.
119 lines
3.2 KiB
C++
119 lines
3.2 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
|
|
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
|
|
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 ;
|
|
}
|