
如上圖所示選擇了檔案型別后,點擊“選擇路徑”,選擇了一個檔案夾,然后在串列控制元件中顯示搜到的檔案名,想把這些檔案名后面添加一個密級,像0: 不改名;1:“公開”等,舉例:上下拉電阻的作用.pdf變成上下拉電阻的作用(公開).pdf,讓操作者在選擇了Combox 下拉串列控制元件的某一項之后,點擊“重命名”按鈕后,實作如上的操作。這里還有一個要求就是搜出來檔案后,把所有的檔案的檔案名都修改嘍,之后根據需要多選某些特定的檔案名,實作對這些檔案的檔案名的標密,請問實作這些功能應該怎么編程?
uj5u.com熱心網友回復:
CFile::Rename()uj5u.com熱心網友回復:
樓上OK的,其他的是邏輯問題了uj5u.com熱心網友回復:
MoveFile APIuj5u.com熱心網友回復:
都羅列了全部檔案了,后面就是用執行緒一個一個的修改了。
uj5u.com熱心網友回復:
為什么不直接生成一個bat批處理檔案然后執行它呢?uj5u.com熱心網友回復:
請問怎么用執行緒改啊?請指教。
uj5u.com熱心網友回復:
沒接觸過bat批處理檔案,請詳細說明一下,怎么使用,我是初學。
uj5u.com熱心網友回復:
百度搜“bat批處理改名”
uj5u.com熱心網友回復:
這樣的問題根本不用編程dir 列出檔案名
復制到excel里
用excel的文本函式
前面加上ren XXX 新檔案名,拖拉
在貼到.bat檔案里面
uj5u.com熱心網友回復:
不是有個 vector<FileInfo>fileList;uj5u.com熱心網友回復:
我的需求不是單純的改名,而是編程改名,所以需要您進一步地提示。uj5u.com熱心網友回復:
void find (LPCTSTR lpPath,std::vector<FileInfo>&FileList)
{
//std::vector<FileInfo>fileList;
std::string szFind(lpPath);
WIN32_FIND_DATA FindFileData;
szFind+=_T("\\*.*");
HANDLE hFind=::FindFirstFile(szFind.c_str(),&FindFileData); //這里用到了szFind
if(INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
do//while(1)
{
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) //判斷
{//dir 目錄在串列中可以雙擊打開,不要遞回!
if(FindFileData.cFileName[0]!='.')
{
std::string szPath(lpPath);
szPath+=_T("\\");
szPath+=FindFileData.cFileName;
TRACE1("%s\n",szPath.c_str());
find(szPath.c_str(),FileList); //自注:這里小寫的fileList不行。這一句是遞回。
}
}
else
{ std::string strFileName=FindFileData.cFileName;//檔案名
suffixStr=strFileName.substr(strFileName.find_last_of('.')+1); //這里的后綴就是所有檔案型別的后綴,下面的檔案是所有型別的檔案的顯示。
if(std::regex_match(suffixStr,suffixStr1))
{ FILETIME ft=FindFileData.ftCreationTime; //取得創建時間
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //轉換成本地時間
FileTimeToSystemTime(&ft,&st); //在這句之前加上上一句,就不用再小時那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //檔案全路徑名
FileInfo fi; //自注:結構變數不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:這句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(suffixStr==suffixStr2)
{
FILETIME ft=FindFileData.ftCreationTime; //取得創建時間
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //轉換成本地時間
FileTimeToSystemTime(&ft,&st); //在這句之前加上上一句,就不用再小時那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //檔案全路徑名
FileInfo fi; //自注:結構變數不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:這句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(std::regex_match(suffixStr,suffixStr3))
{
FILETIME ft=FindFileData.ftCreationTime; //取得創建時間
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //轉換成本地時間
FileTimeToSystemTime(&ft,&st); //在這句之前加上上一句,就不用再小時那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //檔案全路徑名
FileInfo fi; //自注:結構變數不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:這句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(std::regex_match(suffixStr,suffixStr4))
{
FILETIME ft=FindFileData.ftCreationTime; //取得創建時間
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //轉換成本地時間
FileTimeToSystemTime(&ft,&st); //在這句之前加上上一句,就不用再小時那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //檔案全路徑名
FileInfo fi; //自注:結構變數不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:這句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
else if(suffixStr==suffixStr5)
{
FILETIME ft=FindFileData.ftCreationTime; //取得創建時間
SYSTEMTIME st={0};
TCHAR buf[64]={0};
FileTimeToLocalFileTime(&(FindFileData.ftCreationTime),&ft); //轉換成本地時間
FileTimeToSystemTime(&ft,&st); //在這句之前加上上一句,就不用再小時那里+8了。
sprintf_s(buf,_T("%4d年-%02d月-%02d日%02d:%02d:%02d"),st.wYear,st.wMonth,st.wDay,st.wHour/*北京時間*/,st.wMinute,st.wSecond);
std::string strFilePath=lpPath;
strFilePath+=_T("\\");
strFilePath+=FindFileData.cFileName; //檔案全路徑名
FileInfo fi; //自注:結構變數不能代入
fi.szFileName=strFileName;
fi.szFilePath=strFilePath;
fi.szCreateTime=buf;
TRACE1("%s\n",strFileName.c_str()); //自注:這句是后加上的
FileList.push_back(fi); //自注:push_back(fi)是什么意思?
}
}
}while(::FindNextFile(hFind,&FindFileData));
// getchar();
}
是對這段程式進行修改,就可實作我前面提到的功能了嗎?還是又需要別的程式,請指教。
uj5u.com熱心網友回復:
vector<FileInfo>fileList; 是個 全域 變數 ,用于 填充 list,你用 list 也 可以 取 原檔案 名 (path+NAME)但 速度慢而讀寫 fileList 要 快得多 !
uj5u.com熱心網友回復:
vector<FileInfo>fileList; 是個 全域 變數 ,用于 填充 list,你用 list 也 可以 取 原檔案 名 (path+NAME)但 速度慢
而讀寫 fileList 要 快得多 !
這個全域變數,如何填充list,用list怎么取原檔案名(path+NAME),如何讀寫fileList?
uj5u.com熱心網友回復:
從 m_list 取
int nSelectedItem=m_list.GetSelectionMark();//獲取第幾行
CString name=m_list.GetItemText(nSelectedItem,1);
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
CString path=m_list.GetItemText(nSelectedItem,3);
CStringArray ExeName;
char fullname[MAX_PATH];
strcpy(fullname,(LPTSTR)(LPCTSTR)path);
strcat(fullname,"\\");
strcat(fullname,(LPTSTR)(LPCTSTR)name);
afxDump << fullname << "\n";
fileList see "FillList"
uj5u.com熱心網友回復:
從 m_list 取
int nSelectedItem=m_list.GetSelectionMark();//獲取第幾行
CString name=m_list.GetItemText(nSelectedItem,1);
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
CString path=m_list.GetItemText(nSelectedItem,3);
CStringArray ExeName;
char fullname[MAX_PATH];
strcpy(fullname,(LPTSTR)(LPCTSTR)path);
strcat(fullname,"\\");
strcat(fullname,(LPTSTR)(LPCTSTR)name);
afxDump << fullname << "\n";
fileList see "FillList"
這段話什么意思?
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));是得到擴展名吧?
CStringArray ExeName是干什么的?
uj5u.com熱心網友回復:
上面我參考的這部分程式應該添加到原始對話框程式的什么地方?uj5u.com熱心網友回復:
要改名 先要得到 原檔案名,通過上面代碼 得到 一個 檔案名 (選中項,全部是 i=0到 GetItemCount)然后 改名 。
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
另有它用, 注意 “機密” 在 ext 前。
uj5u.com熱心網友回復:
要改名 先要得到 原檔案名,通過上面代碼 得到 一個 檔案名 (選中項,全部是 i=0到 GetItemCount)
然后 改名 。
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));
另有它用, 注意 “機密” 在 ext 前。
得到一個還是自己任選的一批檔案名,GetItemCount在程式里沒出現啊?
CString ext=name.Right(name.GetLength()-name.ReverseFind('.'));干什么用?為什么不是“絕密”在ext前?
uj5u.com熱心網友回復:
你不是 要 讓 “絕密” 等 新名 在ext 前嗎,所以 把 檔案名 先 分成 左右 2部分 ,右邊 ext 名 不變,左邊 名 后 加 “x密”,再 合并成 新 檔案名 。
uj5u.com熱心網友回復:
下面 是 選擇 m_list 中 檔案(單選或者多選)后 ,點擊 “rename“ 按鈕
// rename
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extame=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += "機密";// 增加的
newName += extame;
AfxMessageBox(newName);
}
}
uj5u.com熱心網友回復:
dir 列出檔案名后,復制到excel假設為A列,然后在B列內用公式B1=“ren ”& A1 & “ ” & A1 & “(公開)”
復制出來,粘貼到記事本中,存為bat檔案
uj5u.com熱心網友回復:
下面 是 選擇 m_list 中 檔案(單選或者多選)后 ,點擊 “rename“ 按鈕
// rename
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extame=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += "機密";// 增加的
newName += extame;
AfxMessageBox(newName);
}
}
不用對Combox box這個控制元件編程嗎,每個選項都可能需要添加對應的密級到檔案名的后面啊。
uj5u.com熱心網友回復:
"不用對Combox box這個控制元件編程嗎"要 即 newName += "機密";// 增加的
是 m_cmb 當前 選擇項 (m_cmb。GetWindowText(),即 其 edit 的 內容)
uj5u.com熱心網友回復:
newName += "機密";// 增加的 這句寫在“重命名”按鈕的程式里,不用寫在Combo box對應的程式里嗎?Combo box程式與重命名按鈕程式邏輯是上是怎樣的聯系呢?m_cmb當前選擇項是怎么回事,編輯框edit程式應該怎么寫?請指教。uj5u.com熱心網友回復:
"m_cmb當前選擇項是怎么回事"就是用戶 選擇 密級,你那個 cmb 不要 1.。。。6 ,直接 就是 “機密“ 要不然 必須 去除 ‘1“ 。。。’
用戶 選擇 密級 后 cmb 的 edit 顯示 回應 密級 如 “機密“
newName += "機密";
變成
newName += m_cmb.GetWindowText() ;//
uj5u.com熱心網友回復:

帶點的波浪線顯示了,這是什么錯誤?如果帶著0~5的標號,應該怎么編?
uj5u.com熱心網友回復:
向導要 add 變數 mComboBox (即 IDC_CMB)控制元件“帶著0~5的標號” 要么用 0到5,要么用 "x密“ , 你的 處理 一下 !
uj5u.com熱心網友回復:
寫在選項里的時候是兩個都要,即0: 不更改;1: 公開;2: 內部;3: ......等等,真正改名時只要改成XXX(內部).pdf; XXX(機密).docx這種格式的標密檔案就行了,應該怎么改?uj5u.com熱心網友回復:
0: 不更改0: 有什么用 ?
不更改 又有 什么用 ?
"1: 公開"
分 左右 2部分 ,取 右部 即可, 分割 標記 是 tab (09)或者 空格 (0x20)
uj5u.com熱心網友回復:
0: 不更改
0: 有什么用 ?
不更改 又有 什么用 ?
"1: 公開"
分 左右 2部分 ,取 右部 即可, 分割 標記 是 tab (09)或者 空格 (0x20)
是啊,您說的對,這一項的確是沒用啊。但分割標記是怎么回事tab(09)或空格(0x20)寫在哪里,怎么寫?
uj5u.com熱心網友回復:
分割 標記 是 tab (09)在 cmb 的 list 中 不可見 使用 空格 (0x20)吧,即 “1:“ 與 “公開“ 間 用 空格 分開用 Find (“ ”)或 ReverseFind (' ')
uj5u.com熱心網友回復:
分割 標記 是 tab (09)在 cmb 的 list 中 不可見 使用 空格 (0x20)吧,即 “1:“ 與 “公開“ 間 用 空格 分開
用 Find (“ ”)或 ReverseFind (' ')
用 Find (“ ”)或 ReverseFind (' ') 是怎么個用法,具體寫成代碼是什么樣子?
uj5u.com熱心網友回復:
CString GetSecurityLevel(){
CString cmbName="1: 公開";// 5 spaces !
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
呼叫
CString sl=GetSecirityLevel();
uj5u.com熱心網友回復:
我把我的程式發給您郵箱了,您幫我看看,具體應該怎么改,多謝了。uj5u.com熱心網友回復:
對不起 我只用 vc6uj5u.com熱心網友回復:
CString GetSecurityLevel()
{
CString cmbName="1: 公開";// 5 spaces !
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
呼叫
CString sl=GetSecirityLevel();
CString GetSecurityLevel()是得到密級對吧?int at=cmbName.ReverseFind(' ');是什么意思?接下來兩句是什么意思?呼叫的sl又是什么意思?請指教。除了“公開”以外的其他密級怎么辦?寫在哪兒?
uj5u.com熱心網友回復:
CString cmbName="1: 公開";// 5 spaces !其他 密級 就是 CString cmbName=m_cmb.GetWindowText() ;// "1: 公開";// 5 spaces !
int at=cmbName.ReverseFind(' ');// c從 右到左 找到 第一個 空格 的 位置 at。
CString sl=GetSecirityLevel();
newName += sl ;// "機密";
uj5u.com熱心網友回復:

這個錯誤怎么消除?
uj5u.com熱心網友回復:
CString GetSecurityLevel()
{
CString cmbName="1: 公開";// 5 spaces !
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
呼叫
CString sl=GetSecirityLevel();
要想得到其他的密級只需要把程式由
CString cmbName="1: 公開";// 5 spaces !
改為CString cmbName=m_cmb.GetWindowText() ;即可,是吧?
uj5u.com熱心網友回復:
// rename
CString CShowdirDlg::GetSecurityLevel()
{
CString cmbName;
m_Cmb1.GetWindowText(cmbName);//"1: 公開";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
//
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CString sl=GetSecurityLevel();
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extname=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += sl;// "機密";// 增加的
newName += extname;
AfxMessageBox(path + "\\"+ name + " To " + newName);
// CFile::Rename(path + "\\"+ name, newName );
}
}
uj5u.com熱心網友回復:
// renameCString CShowdirDlg::GetSecurityLevel()
{
CString cmbName;
m_Cmb1.GetWindowText(cmbName);//"1: 公開";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
//這個函式是不是就是應該寫到我VC2010程式的void XXXDlg:: OnCbnselchangeCombo()處呢?
uj5u.com熱心網友回復:
不必,這是取當前選擇項,與 當前選擇項改變 無關。因為 CString sl=GetSecurityLevel(); 是第一句 (不在while內),以后所有list的多選項 會用同一個 密級 改名
uj5u.com熱心網友回復:
那我自動生成的 void XXXDlg:: OnCbnselchangeCombo()宣告{
//ToD:在此添加控制元件通知處理程式代碼
}
這里針對我需要實作的功能,需要寫些什么呢?
uj5u.com熱心網友回復:
// rename
CString CShowdirDlg::GetSecurityLevel()
{
CString cmbName;
m_Cmb1.GetWindowText(cmbName);//"1: 公開";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
//
void CShowdirDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CString sl=GetSecurityLevel();
POSITION pos = m_list.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos != NULL)
{
nSelectedItem = m_list.GetNextSelectedItem(pos);
CString name = m_list.GetItemText(nSelectedItem,1);
CString path = m_list.GetItemText(nSelectedItem,3);
CString extname=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += sl;// "機密";// 增加的
newName += extname;
AfxMessageBox(path + "\\"+ name + " To " + newName);
// CFile::Rename(path + "\\"+ name, newName );
}
}
點Combox box 控制元件的下拉框選項,對應這里m_Cmb1.GetWindowText(cmbName);,m_Cmb1中的GetWindowText的內容為1: 公開;2: 內部;3: 秘密........。等
還有請問:while以下的陳述句是什么意思,看不懂啊。
uj5u.com熱心網友回復:
while (pos != NULL) 是 檢查 m_list 有多少 選擇 項, 取出 選擇項的 id。m_list 屬性應該 是 多選。
用戶 操作 如下 , 移動 滑鼠 在 list 界面中 選擇 任意多 項,(或 再改變 密級),點擊 “Rename”, 那么 這批 檔案就 同時 改名 到 一個 密級。
uj5u.com熱心網友回復:

這里的三個錯誤應該如何改,請指教。
uj5u.com熱心網友回復:
void CremarksecretDlg::ListShow(int pageNo)
{
UINT nCount=fileList.size(); //得到控制元件的行數 總的檔案個數。
UINT i;
//int pageNo=1;
Start=pageSize*(pageNo-1);
End=pageSize*pageNo;
CString empty; //難道是這里定義錯了?
CString name;
CString time;
CString fpath;
mlist.LockWindowUpdate();
mlist.DeleteAllItems(); //要想實作翻頁效果這句必不可少。
for(i=Start;i<End;i++) //改成i=0;i<50也還是不行,這里不是邏輯出了問題,而是其它的問題。
{
if(i>=nCount)break;
empty.Format(_T("%d"),i+1);
int nRow=mlist.InsertItem(i,empty); //這句話什么意思?
afxDump<<nRow<<"\n"; //這句對翻頁沒有影響
name.Format(_T("%s\n"),fileList[i].szFileName.c_str());
mlist.SetItemText(nRow,1,name); //插入列 自注:從這里開始程式就不對了,這句還是對的
time.Format(_T("%s\n"),fileList[i].szCreateTime.c_str());
mlist.SetItemText(nRow,2,time);
fpath.Format(_T("%s\n"),fileList[i].szFilePath.c_str()); //不影響翻頁
mlist.SetItemText(nRow,3,fpath);
}
mlist.UnlockWindowUpdate();
// getchar();
}
void CremarksecretDlg::OnCbnSelchangeCombo()
{
// TODO: 在此添加控制元件通知處理程式代碼
}
CString CremarksecretDlg::GetSecurityLevel()
{
CString cmbName;
mComeboBox.GetWindowText(cmbName);//"1: 公開";
int at=cmbName.ReverseFind(' ');
return cmbName.Right(cmbName.GetLength()-at-1);
}
void CremarksecretDlg::OnBnClickedButton4()
{
// TODO: 在此添加控制元件通知處理程式代碼
CString sl=GetSecurityLevel();
POSITION pos = mlist.GetFirstSelectedItemPosition();
int nSelectedItem = -1;
while (pos!=NULL)
{
nSelectedItem = mlist.GetNextSelectedItem(pos);
CString name = mlist.GetItemText(nSelectedItem,1);
CString path = mlist.GetItemText(nSelectedItem,3);
CString extname=name.Right(name.GetLength()-name.ReverseFind('.'));
CString pureName=name.Left(name.ReverseFind('.'));
CString newName=path;
newName += "\\";
newName += pureName;
newName += sl;// "機密";// 增加的
newName += extname;
AfxMessageBox(path + "\\"+ name + " To " + newName);
// CFile::Rename(path + "\\"+ name, newName );
}
}
這兩段程式中都有CString變數,變數相同,有沒有沖突啊?我這些程式這么寫被證實有問題,因為沒有在檔案名后面添加(公開),(內部),(秘密)等密級,請問是怎么回事。
uj5u.com熱心網友回復:
"這兩段程式中都有CString變數,變數相同,有沒有沖突啊"概念錯誤 !
CString變數 ! CString 是 某變數 的 型別,不是 變數 , 如 int 是 整數 型別, 不是 整數 變數 !
mComeboBox.GetWindowText(cmbName);
檢查 cmbName 是否 空 : if(cmbName.IsEmpty()) return CString(錯誤);
在 rename 前 要 選擇 mComeboBox
uj5u.com熱心網友回復:
對,您說的對,CString是變數型別,我就是想知道這兩段程式中的同樣變數型別的同名變數,用起來有沒有沖突?rename前,我選擇mComeboBox的下拉框的選項了,但是Rename后就是沒顯示XXX(公開).pdf,XXX(秘密).doc等類似的標密檔案。
檢查 cmbName 是否 空 : if(cmbName.IsEmpty()) return CString(錯誤);有什么用?
uj5u.com熱心網友回復:
這兩段程式中的同樣變數型別的同名變數這是 變數的作用域的 問題 ,某段程式 中 的變數 ,只在 該 程式 有用 (通常 變數在 堆疊 中!), 出 這個 程式 就
沒用了 , 單 同一段 函式中 ,變數不能 同名 ! 這是 變數的唯一性 (編譯器 會報警)
uj5u.com熱心網友回復:
CString time; time 是 預定義 型別 。改為CString tm;
uj5u.com熱心網友回復:
請指點,多謝了。uj5u.com熱心網友回復:
好壓軟體似乎自帶批處理改名功能。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/60986.html
標籤:基礎類
上一篇:請問MFC+VS2017怎么做出來這樣的圖片瀏覽功能
下一篇:0x80004003 無效指標
