DWORD GetFileAttributes( LPCTSTR lpFileName // name of file or directory ); if( 返回值 & FILE_ATTRIBUTE_DIRECTORY ) var C: Cardinal; begin C := GetFileAttributes('d:\a'); if C = $FFFFFFFF then ShowMessage('文件或文件夹不存在!') else if C and FILE_ATTRIBUTE_DIRECTORY <> 0 then ShowMessage('是文件夹!') else ShowMessage('是文件!') end; function FileSize(FileName: string): Int64; 判断某文件是文件夹还是文件
1 //头文件 2 #include "stdio.h" 3 #include "stdlib.h" 4 #include <sys/stat.h> 5 //代码 6 int main() 7 { 8 char* fileName = "aa.txt"; 9 struct _stat buf; 10 int result; 11 result = _stat( fileName, &buf ); 12 if(_S_IFDIR & buf.st_mode){ 13 printf("folder\n"); 14 }else if(_S_IFREG & buf.st_mode){ 15 printf("file\n"); 16 } 17 18 return 0; 19 } |
|