下面的代码错在哪里 为何建立不成功呢? int curdrive;int te=0; char path[80];for(int t=0;t<80;t++)path[t]=0; CString path1=""; curdrive = _getdrive();// Save current drive. if the current driver is g:,the curdiive is 7,of course 1 stand for a: /* if(_getdcwd(curdrive, path, 80) != NULL )//path保存着路径 { path1=path; } path1+="\\temp"; HANDLE fFile; WIN32_FIND_DATA fileinfo; CStringArray m_arr; // CString Array to hold Directory Structures BOOL tt1; // BOOL used to test if Create Directory was successful int x1 = 0; // Counter CString tem = ""; fFile = FindFirstFile(path1,&fileinfo); if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { FindClose(fFile); te=1; } m_arr.RemoveAll(); for(x1 = 0; x1 < path1.GetLength(); x1++ ) // Parse the supplied CString Directory String { if(path1.GetAt(x1) != '\\') // if the Charachter is not a \ tem += path1.GetAt(x1); // add the character to the Temp String else { m_arr.Add(tem); // if the Character is a \ ,Add the Temp String to the CString Array tem="\\"; // tem += "\\"; // Now add the \ to the temp string } if(x1 == path1.GetLength()-1) // If we reached the end of the String // add the remaining string m_arr.Add(tem); } FindClose(fFile); int r1=0; r1=m_arr.GetSize();
// Create each level of the Directory Structure // Now lets cycle through the String Array and create each directory in turn for(x1 = 1; x1 < m_arr.GetSize(); x1++) { tem = m_arr.GetAt(x1); tt1 = CreateDirectory(tem,NULL);
// If the Directory exists it will return a false if(tt1)SetFileAttributes(tem,FILE_ATTRIBUTE_NORMAL); // If we were successful we set the attributes to normal } // Now lets see if the directory was successfully created fFile = FindFirstFile(path1,&fileinfo);
m_arr.RemoveAll(); if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // Directory Exists close file and return FindClose(fFile); te=1; } else { // For Some reason the Function Failed Return FALSE FindClose(fFile); te=1; } */
为何建立不成功呢?
int curdrive;int te=0;
char path[80];for(int t=0;t<80;t++)path[t]=0;
CString path1="";
curdrive = _getdrive();// Save current drive. if the current driver is g:,the curdiive is 7,of course 1 stand for a:
/* if(_getdcwd(curdrive, path, 80) != NULL )//path保存着路径
{
path1=path;
}
path1+="\\temp";
HANDLE fFile;
WIN32_FIND_DATA fileinfo;
CStringArray m_arr; // CString Array to hold Directory Structures
BOOL tt1; // BOOL used to test if Create Directory was successful
int x1 = 0; // Counter
CString tem = "";
fFile = FindFirstFile(path1,&fileinfo);
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
FindClose(fFile);
te=1;
}
m_arr.RemoveAll();
for(x1 = 0; x1 < path1.GetLength(); x1++ ) // Parse the supplied CString Directory String
{
if(path1.GetAt(x1) != '\\') // if the Charachter is not a \
tem += path1.GetAt(x1); // add the character to the Temp String
else
{
m_arr.Add(tem); // if the Character is a \ ,Add the Temp String to the CString Array
tem="\\";
// tem += "\\"; // Now add the \ to the temp string
}
if(x1 == path1.GetLength()-1) // If we reached the end of the String
// add the remaining string
m_arr.Add(tem);
}
FindClose(fFile);
int r1=0;
r1=m_arr.GetSize();
// Create each level of the Directory Structure
// Now lets cycle through the String Array and create each directory in turn
for(x1 = 1; x1 < m_arr.GetSize(); x1++)
{
tem = m_arr.GetAt(x1);
tt1 = CreateDirectory(tem,NULL);
// If the Directory exists it will return a false
if(tt1)SetFileAttributes(tem,FILE_ATTRIBUTE_NORMAL);
// If we were successful we set the attributes to normal
}
// Now lets see if the directory was successfully created
fFile = FindFirstFile(path1,&fileinfo);
m_arr.RemoveAll();
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
te=1;
}
else
{
// For Some reason the Function Failed Return FALSE
FindClose(fFile);
te=1;
}
*/
char m_curDir[_MAX_PATH];
GetCurrentDirectory(_MAX_PATH,m_curDir);CreateDirectory()
BOOL CreateDirectory(
LPCTSTR lpPathName, // pointer to directory path string
LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
);