Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. renaming files

renaming files

Scheduled Pinned Locked Moved ATL / WTL / STL
c++question
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khomeyni
    wrote on last edited by
    #1

    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??

    C M 2 Replies Last reply
    0
    • K khomeyni

      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??

      C Offline
      C Offline
      Cool_Dev
      wrote on last edited by
      #2

      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.

      K P 2 Replies Last reply
      0
      • C Cool_Dev

        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.

        K Offline
        K Offline
        khomeyni
        wrote on last edited by
        #3

        can you write the code of it here?

        L 1 Reply Last reply
        0
        • K khomeyni

          can you write the code of it here?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If you took the trouble to go and look at the links that Cool_Dev provided you would see some sample code to help you.

          Just say 'NO' to evaluated arguments for diadic functions! Ash

          1 Reply Last reply
          0
          • C Cool_Dev

            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.

            P Offline
            P Offline
            pasztorpisti
            wrote on last edited by
            #5

            Note that people sometimes forget about FindClose() thus leaking a handle. Another important thing is that when FindFirstFile() returns INVALID_HANDLE_VALUE and when FindNextFile() returns FALSE you may want to check if GetLastError() returns ERROR_NO_MORE_FILES or something more brutal.

            1 Reply Last reply
            0
            • K khomeyni

              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??

              M Offline
              M Offline
              mbue
              wrote on last edited by
              #6

              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

              K 1 Reply Last reply
              0
              • M mbue

                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

                K Offline
                K Offline
                khomeyni
                wrote on last edited by
                #7

                thanks a lot.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups