renaming files
-
hello i want to see all files in directory dir that have .txt and rename them to directory dir2 with suffix .cpp how i can do this??
You may use FindFirstFile and FindNextFile APIs (or CFileFind MFC class) to see all fles in directory dir1. If file is having extension .txt ( you can use PathFindExtension), use CopyFile function to copy that file to dir2 with extension changed to .cpp.
-
You may use FindFirstFile and FindNextFile APIs (or CFileFind MFC class) to see all fles in directory dir1. If file is having extension .txt ( you can use PathFindExtension), use CopyFile function to copy that file to dir2 with extension changed to .cpp.
-
You may use FindFirstFile and FindNextFile APIs (or CFileFind MFC class) to see all fles in directory dir1. If file is having extension .txt ( you can use PathFindExtension), use CopyFile function to copy that file to dir2 with extension changed to .cpp.
Note that people sometimes forget about
FindClose()
thus leaking a handle. Another important thing is that whenFindFirstFile()
returnsINVALID_HANDLE_VALUE
and whenFindNextFile()
returnsFALSE
you may want to check ifGetLastError()
returnsERROR_NO_MORE_FILES
or something more brutal. -
hello i want to see all files in directory dir that have .txt and rename them to directory dir2 with suffix .cpp how i can do this??
void txt2cpp(const TCHAR* path) { TCHAR full[_MAX_PATH+_MAX_FNAME]; TCHAR move[_MAX_PATH+_MAX_FNAME]; unsigned int flen; unsigned int mlen; HANDLE hf; WIN32_FIND_DATA fd; _tcscpy(full,path); flen = _tcslen(full); _tcscpy(full+flen,_T("\\*.txt")); hf = FindFirstFile(full); if(INVALID_HANDLE_VALUE!=hf) { do { if(!(FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes)) { _tcscpy(full+flen+1,fd.cFileName); _tcscpy(move,full); mlen = _tcslen(move); for(;(0
-
void txt2cpp(const TCHAR* path) { TCHAR full[_MAX_PATH+_MAX_FNAME]; TCHAR move[_MAX_PATH+_MAX_FNAME]; unsigned int flen; unsigned int mlen; HANDLE hf; WIN32_FIND_DATA fd; _tcscpy(full,path); flen = _tcslen(full); _tcscpy(full+flen,_T("\\*.txt")); hf = FindFirstFile(full); if(INVALID_HANDLE_VALUE!=hf) { do { if(!(FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes)) { _tcscpy(full+flen+1,fd.cFileName); _tcscpy(move,full); mlen = _tcslen(move); for(;(0