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. C / C++ / MFC
  4. How to search and delete a file

How to search and delete a file

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
5 Posts 4 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.
  • S Offline
    S Offline
    Shirani
    wrote on last edited by
    #1

    Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.

    Regards: Xohaib Shirani

    _ V 2 Replies Last reply
    0
    • S Shirani

      Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.

      Regards: Xohaib Shirani

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Use FindFirstFile()/FindFirstFileEx() to find a file with a specifc name. DeleteFile() to delete it

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      1 Reply Last reply
      0
      • S Shirani

        Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.

        Regards: Xohaib Shirani

        V Offline
        V Offline
        vijay_aroli
        wrote on last edited by
        #3

        If you already know the path of the file to be deleted, then you don't have to search for it. You can use PathFileExists() function to see if the file exists. you can also use the function PathIsDirectory() to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.

        TCHAR szFilePath[MAX_PATH];
        _tcscpy(szFilePath, _T("C:\\file.txt") );

        //Check if the file with the given path really exists and is not a directory.
        if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
        DeleteFile(szFilePath);//delete the file 'C:\file.txt'

        Regards, Vijay.

        S 1 Reply Last reply
        0
        • V vijay_aroli

          If you already know the path of the file to be deleted, then you don't have to search for it. You can use PathFileExists() function to see if the file exists. you can also use the function PathIsDirectory() to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.

          TCHAR szFilePath[MAX_PATH];
          _tcscpy(szFilePath, _T("C:\\file.txt") );

          //Check if the file with the given path really exists and is not a directory.
          if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
          DeleteFile(szFilePath);//delete the file 'C:\file.txt'

          Regards, Vijay.

          S Offline
          S Offline
          Shirani
          wrote on last edited by
          #4

          error C2065: 'PathFileExists' : undeclared identifier error C2065: 'PathIsDirectory' : undeclared identifier

          Regards: Xohaib Shirani

          E 1 Reply Last reply
          0
          • S Shirani

            error C2065: 'PathFileExists' : undeclared identifier error C2065: 'PathIsDirectory' : undeclared identifier

            Regards: Xohaib Shirani

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            Header shlwapi.h Import library shlwapi.lib


            OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

            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