//建立多层目录
BOOL CreatePath(LPCSTR lpszFullPathName)
{
CString dd;
dd=lpszFullPathName;
HANDLE fFile; // File Handle
WIN32_FIND_DATA fileinfo; // File Information Structure
CStringArray m_arr; // CString Array to hold Directory Structures
BOOL tt; // BOOL used to test if Create Directory was successful
int x1 = 0; // Counter
CString tem = ""; // Temporary CString Object fFile = FindFirstFile(dd,&fileinfo); // if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return FALSE;
}
m_arr.RemoveAll(); for(x1 = 0; x1 < dd.GetLength(); x1++ ) // Parse the supplied CString Directory String
{
if(dd.GetAt(x1) != '\\') // if the Charachter is not a \
tem += dd.GetAt(x1); // add the character to the Temp String
else
{
m_arr.Add(tem); // if the Character is a \
tem += "\\"; // Now add the \ to the temp string
}
if(x1 == dd.GetLength()-1) // If we reached the end of the String
m_arr.Add(tem);
} // Close the file
FindClose(fFile); // 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);
tt = CreateDirectory(tem,NULL); // If the Directory exists it will return a false
if(tt)
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(dd,&fileinfo); m_arr.RemoveAll();
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
else
{
// For Some reason the Function Failed Return FALSE
FindClose(fFile);
return FALSE;
}
}
BOOL CreatePath(LPCSTR lpszFullPathName)
{
CString dd;
dd=lpszFullPathName;
HANDLE fFile; // File Handle
WIN32_FIND_DATA fileinfo; // File Information Structure
CStringArray m_arr; // CString Array to hold Directory Structures
BOOL tt; // BOOL used to test if Create Directory was successful
int x1 = 0; // Counter
CString tem = ""; // Temporary CString Object fFile = FindFirstFile(dd,&fileinfo); // if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return FALSE;
}
m_arr.RemoveAll(); for(x1 = 0; x1 < dd.GetLength(); x1++ ) // Parse the supplied CString Directory String
{
if(dd.GetAt(x1) != '\\') // if the Charachter is not a \
tem += dd.GetAt(x1); // add the character to the Temp String
else
{
m_arr.Add(tem); // if the Character is a \
tem += "\\"; // Now add the \ to the temp string
}
if(x1 == dd.GetLength()-1) // If we reached the end of the String
m_arr.Add(tem);
} // Close the file
FindClose(fFile); // 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);
tt = CreateDirectory(tem,NULL); // If the Directory exists it will return a false
if(tt)
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(dd,&fileinfo); m_arr.RemoveAll();
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
else
{
// For Some reason the Function Failed Return FALSE
FindClose(fFile);
return FALSE;
}
}
解决方案 »
- 动态创建的控件,怎么销毁
- CXTOutBarCtrl的旷世难题,怎样得到Folder和Item的名称及其索引,它们是如何唯一标识的?
- 问问inet_系列函数需要什么头文件啊?
- 有做nap(network access protection)开发的吗?一起探讨些问题!
- 怎么判断完成端口接收数据完成?
- 再问CEDIT问题!
- 问个问题 关于如何在CList Ctrl的控件里添加Combo Box控件
- 为何我的VC在家与在单位做的工程不兼容?继续编写时打点不出提示????????
- vc6中的std::vector<int> 是什么意思?和普通的int类型有何差别?
- 请问有什么函数把int转化为cstring?
- 谁会用WinPcap?
- 我自己创建了一个类,怎样添加消息映射?
Copies, moves, renames, or deletes a file system object. int SHFileOperation(
LPSHFILEOPSTRUCT lpFileOp
);
BOOL CreateDirectory(
LPCTSTR lpPathName, // pointer to a directory path string
LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
2。目录改名:
BOOL MoveFile(
LPCTSTR lpExistingFileName, // address of name of the existing file
LPCTSTR lpNewFileName // address of new name for the file
);
但MoveFile不能跨驱动器更改目录名。