root/trunk/cs_filefunctions.cpp

Revision 5, 2.7 kB (checked in by qbert, 6 years ago)

Initial ( and last :( ) commit

Line 
1 #include "stdafx.h"
2 #include "cs_filefunctions.h"
3 #include <windows.h>
4
5 void GetMyFiles(const string& dir, vector<string> &files)
6 {
7     WIN32_FIND_DATA fdat;
8     char x[500];
9     GetCurrentDirectory(500,x);
10     if (!SetCurrentDirectory(dir.c_str())) MessageBox(0,"Couldnt set directory",dir.c_str(),0);
11     HANDLE hfind=FindFirstFile("*",&fdat);
12
13     while (hfind!=INVALID_HANDLE_VALUE)
14     {
15         if ((strcmp(fdat.cFileName, ".") == 0) || (strcmp(fdat.cFileName,"..") ==0)) ; //if it is . or .. dont push it on
16         else {
17             if ( FileExtension(fdat.cFileName) == "d" ) files.push_back(fdat.cFileName);           
18         }
19         if (!FindNextFile(hfind,&fdat)) {FindClose(hfind); hfind=INVALID_HANDLE_VALUE;}
20     }
21
22     if (!SetCurrentDirectory(x)) MessageBox(0,"Couldnt set directory",x,0);
23     FindClose(hfind);
24 }
25 void GetMyDirs(const string& dir, vector<string> &files)
26 {
27     WIN32_FIND_DATA fdat;
28     char x[500];
29     GetCurrentDirectory(500,x);
30     if (!SetCurrentDirectory(dir.c_str())) MessageBox(0,"Couldnt set directory",dir.c_str(),0);
31  
32     HANDLE hfind=FindFirstFile("*",&fdat);
33     while (hfind!=INVALID_HANDLE_VALUE)
34     {
35         DWORD Code = GetFileAttributes(fdat.cFileName);
36         if ((Code != -1) && (Code & FILE_ATTRIBUTE_DIRECTORY )) {
37             if ((strcmp(fdat.cFileName, ".") == 0) || (strcmp(fdat.cFileName,"..") ==0)) ; //if it is . or .. dont push it on
38             else files.push_back(fdat.cFileName);
39    
40         }
41
42         if (!FindNextFile(hfind,&fdat)) {
43             FindClose(hfind);
44             hfind=INVALID_HANDLE_VALUE;
45         }
46      
47     }
48     if (!SetCurrentDirectory(x)) MessageBox(0,"Couldnt set directory",x,0);
49     FindClose(hfind);
50 }
51
52
53  
54 int GetMyVersion(){
55
56     DWORD dwWindowsMajorVersion, dwWindowsMinorVersion;
57     DWORD dwVersion = GetVersion();
58  
59     // Get major and minor version numbers of Windows
60     dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
61     dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
62     // Get build numbers for Windows NT or Win32s
63     if (dwVersion < 0x80000000)                // Windows NT
64         //dwBuild = (DWORD)(HIWORD(dwVersion));
65         return 2;
66     else if (dwWindowsMajorVersion < 4)        // Win32s
67         //dwBuild = (DWORD)(HIWORD(dwVersion) & ~0x8000);
68         return 1;
69     else return 0; // Windows 95 -- No build numbers provided
70
71 }; 
72
73
74 BOOL EmptyDirectory(CString &sPath)
75 {
76     CFileFind finder;
77
78     CString  sWildCard = sPath + "\\*.*";
79
80     BOOL bFound;
81     BOOL bWorking = finder.FindFile(sWildCard);
82
83     bFound = bWorking;
84
85     while (bWorking)
86     {
87         bWorking = finder.FindNextFile();
88
89         if (finder.IsDots()) continue;
90
91         if (finder.IsDirectory())
92         {
93             CString s = finder.GetFilePath();
94             EmptyDirectory(s);
95             RemoveDirectory(finder.GetFilePath());
96             continue;
97         }
98         _unlink( finder.GetFilePath() );
99
100     }
101
102     return bFound;
103 }
Note: See TracBrowser for help on using the browser.