获取当前路径
bool
GetCurrentDir(
char
*
fileName )
{
char filename[ 512 ];
GetModuleFileName( NULL , filename , 512 );
(strrchr(filename, ' / ' ))[ 1 ] = 0 ;
filename[strlen(filename) - 1 ] = 0 ;
strcpy( fileName , filename );
return 0 ;
}
{
char filename[ 512 ];
GetModuleFileName( NULL , filename , 512 );
(strrchr(filename, ' / ' ))[ 1 ] = 0 ;
filename[strlen(filename) - 1 ] = 0 ;
strcpy( fileName , filename );
return 0 ;
}
文件拷贝
int
FileCopy
( const char * src,
const char * dst )
{
#define BUFSZ 16000
char * buf;
FILE * fi;
FILE * fo;
unsigned amount;
unsigned written;
int result;
buf = new char [BUFSZ];
fi = fopen( src, " rb " );
fo = fopen( dst, " wb " );
result = COPY_OK;
if ((fi == NULL) || (fo == NULL) )
{
result = COPY_ERROR;
if (fi != NULL) fclose(fi);
if (fo != NULL) fclose(fo);
}
if (result == COPY_OK)
{
do
{
amount = fread( buf, sizeof ( char ), BUFSZ, fi );
if (amount)
{
written = fwrite( buf, sizeof ( char ), amount, fo );
if (written != amount)
{
result = COPY_ERROR; // out of disk space or some other disk err?
}
}
} // when amount read is < BUFSZ, copy is done
while ((result == COPY_OK) && (amount == BUFSZ));
fclose(fi);
fclose(fo);
}
delete [] buf;
return (result);
}
( const char * src,
const char * dst )
{
#define BUFSZ 16000
char * buf;
FILE * fi;
FILE * fo;
unsigned amount;
unsigned written;
int result;
buf = new char [BUFSZ];
fi = fopen( src, " rb " );
fo = fopen( dst, " wb " );
result = COPY_OK;
if ((fi == NULL) || (fo == NULL) )
{
result = COPY_ERROR;
if (fi != NULL) fclose(fi);
if (fo != NULL) fclose(fo);
}
if (result == COPY_OK)
{
do
{
amount = fread( buf, sizeof ( char ), BUFSZ, fi );
if (amount)
{
written = fwrite( buf, sizeof ( char ), amount, fo );
if (written != amount)
{
result = COPY_ERROR; // out of disk space or some other disk err?
}
}
} // when amount read is < BUFSZ, copy is done
while ((result == COPY_OK) && (amount == BUFSZ));
fclose(fi);
fclose(fo);
}
delete [] buf;
return (result);
}
获取指定目录下的文件名:
void
GetFilesOfPath(
char
*
path , CStringArray
&
straPathes ){
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
CString strPath;
straPathes.SetSize( 0 , 10 );
char m_pLayerFilePath[MAX_PATH];
char FileToFindPatten[MAX_PATH];
strcpy( m_pLayerFilePath , path );
strcat( m_pLayerFilePath , " / " );
// strcat( m_pLayerFilePath , "*.TAB" );
strcpy( FileToFindPatten , m_pLayerFilePath );
strcat( FileToFindPatten , " *.TAB " ) ;
hFindFile = FindFirstFile(FileToFindPatten, & FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
return ;
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
straPathes.Add(strPath);
}
while (FindNextFile(hFindFile, & FindData))
{
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
straPathes.Add(strPath);
}
}
FindClose(hFindFile);
return ;
}
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
CString strPath;
straPathes.SetSize( 0 , 10 );
char m_pLayerFilePath[MAX_PATH];
char FileToFindPatten[MAX_PATH];
strcpy( m_pLayerFilePath , path );
strcat( m_pLayerFilePath , " / " );
// strcat( m_pLayerFilePath , "*.TAB" );
strcpy( FileToFindPatten , m_pLayerFilePath );
strcat( FileToFindPatten , " *.TAB " ) ;
hFindFile = FindFirstFile(FileToFindPatten, & FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
return ;
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
straPathes.Add(strPath);
}
while (FindNextFile(hFindFile, & FindData))
{
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
straPathes.Add(strPath);
}
}
FindClose(hFindFile);
return ;
}
获取指定目录下的文件名(不含路径)
void
GetFileTitlesOfPath(
char
*
path , CStringArray
&
straPathes)
{
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
CString strPath;
straPathes.SetSize( 0 , 10 );
char m_pLayerFilePath[MAX_PATH];
char FileToFindPatten[MAX_PATH];
strcpy( m_pLayerFilePath , path );
strcat( m_pLayerFilePath , " / " );
// strcat( m_pLayerFilePath , "*.TAB" );
strcpy( FileToFindPatten , m_pLayerFilePath );
strcat( FileToFindPatten , " *.TAB " ) ;
hFindFile = FindFirstFile(FileToFindPatten, & FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
return ;
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
strPath = GetFileTitleFromFileName(strPath,FALSE);
straPathes.Add(strPath);
}
while (FindNextFile(hFindFile, & FindData))
{
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
strPath = GetFileTitleFromFileName(strPath,FALSE);
straPathes.Add(strPath);
}
}
FindClose(hFindFile);
return ;
}
{
HANDLE hFindFile;
WIN32_FIND_DATA FindData;
CString strPath;
straPathes.SetSize( 0 , 10 );
char m_pLayerFilePath[MAX_PATH];
char FileToFindPatten[MAX_PATH];
strcpy( m_pLayerFilePath , path );
strcat( m_pLayerFilePath , " / " );
// strcat( m_pLayerFilePath , "*.TAB" );
strcpy( FileToFindPatten , m_pLayerFilePath );
strcat( FileToFindPatten , " *.TAB " ) ;
hFindFile = FindFirstFile(FileToFindPatten, & FindData);
if (hFindFile == INVALID_HANDLE_VALUE)
return ;
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
strPath = GetFileTitleFromFileName(strPath,FALSE);
straPathes.Add(strPath);
}
while (FindNextFile(hFindFile, & FindData))
{
if (FindData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY)
{
strPath.Format( " %s%s " , m_pLayerFilePath , FindData.cFileName);
strPath = GetFileTitleFromFileName(strPath,FALSE);
straPathes.Add(strPath);
}
}
FindClose(hFindFile);
return ;
}
CString GetFileTitleFromFileName(CString FileName, BOOL Ext)
{
int Where;
Where = FileName.ReverseFind( ' / ' );
if (Where == - 1 )
Where = FileName.ReverseFind( ' / ' );
CString FileTitle = FileName.Right(FileName.GetLength() - 1 - Where);
if ( ! Ext)
{
int Which = FileTitle.ReverseFind( ' . ' );
if (Which != - 1 )
FileTitle = FileTitle.Left(Which);
}
return FileTitle;
}
{
int Where;
Where = FileName.ReverseFind( ' / ' );
if (Where == - 1 )
Where = FileName.ReverseFind( ' / ' );
CString FileTitle = FileName.Right(FileName.GetLength() - 1 - Where);
if ( ! Ext)
{
int Which = FileTitle.ReverseFind( ' . ' );
if (Which != - 1 )
FileTitle = FileTitle.Left(Which);
}
return FileTitle;
}
CString GetFilePathFromFileName(CString FileName)
{
int Where;
Where = FileName.ReverseFind( ' / ' );
if (Where == - 1 )
Where = FileName.ReverseFind( ' / ' );
CString FilePath = FileName.Left(Where);
return FilePath + ' / ' ;
}
{
int Where;
Where = FileName.ReverseFind( ' / ' );
if (Where == - 1 )
Where = FileName.ReverseFind( ' / ' );
CString FilePath = FileName.Left(Where);
return FilePath + ' / ' ;
}
//判断是否为数字或字母
//Output:
//return false,true
bool IsAlphaNumeric(char* charp,int len){
char *c;
c=charp;
for(int i=0;i<len;i++){
if(*c==NULL || *c=='/0')
return true;
if(isalnum(*c)==0)
return false;
c++;
}
return true;
}
char *c;
c=charp;
for(int i=0;i<len;i++){
if(*c==NULL || *c=='/0')
return true;
if(isalnum(*c)==0)
return false;
c++;
}
return true;
}
判断是否为数字
bool
IsNumeric(
char
*
charp,
int
len){
char * c;
c = charp;
for ( int i = 0 ;i < len;i ++ ){
// printf("%d",isdigit(*c));
if ( * c == NULL || * c == '
char * c;
c = charp;
for ( int i = 0 ;i < len;i ++ ){
// printf("%d",isdigit(*c));
if ( * c == NULL || * c == '