CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2008
    Posts
    161

    [RESOLVED] Deleting Files from a diffrent location?

    How can i make an .exe remove 4 files from a location other than the folder the executable is located in?

    EG. Delete C:\Program Files\Delete This\Deletethis.txt

    Thanks,

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Deleting Files from a diffrent location?

    I don't understand what the problem is.
    You can use _unlink or SHShellOperation and specify the full path of the file you want to delete.
    Last edited by Marc G; May 22nd, 2008 at 03:28 AM.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Deleting Files from a diffrent location?

    C++ remove()

    WinAPI DeleteFile()
    Har Har

  4. #4
    Join Date
    Mar 2008
    Posts
    161

    Re: Deleting Files from a diffrent location?

    Can you show me an example of this for the file:

    C:\Program Files\MyFolder\MyFile.txt

    All i want the code to do is delete that without even popping up a window or anything.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Deleting Files from a diffrent location?

    You can use DeleteFile. It does not pop anything.

    If you're using SHFileOperation make sure the flags parameter includes FOF_SILENT.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Mar 2008
    Posts
    161

    Re: Deleting Files from a diffrent location?

    Code:
    #include <windows.h>
    #include <winbase.h>
    
    int main () {
    	BOOL WINAPI DeleteFile(
      __in  LPCTSTR test.txt
    );
    }
    i get the error: error C2143: syntax error : missing ',' before '.'

    I don't want it to delete just one file in the same dir as the .exe, i want it to delete for files from a folder not on the desktop.

    Please show me an example.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Deleting Files from a diffrent location?

    Code:
    DeleteFile("C:\\some directory\\some kind of file.txt");
    Do you understand how functions work?

  8. #8
    Join Date
    Mar 2008
    Posts
    161

    Re: Deleting Files from a diffrent location?

    Thanks

  9. #9
    Join Date
    May 2008
    Posts
    24

    Re: Deleting Files from a diffrent location?

    Sounds like someone is try to pull a nasty trick on someone else
    If that's the case, I would also use some bash scripting, use ls to get all the file names, put this in a new file, put that new file name at the end and then delete them all!

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Deleting Files from a diffrent location?

    Quote Originally Posted by johnnyboldt
    Sounds like someone is try to pull a nasty trick on someone else
    If that's the case, I would also use some bash scripting, use ls to get all the file names, put this in a new file, put that new file name at the end and then delete them all!
    Huh???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured