CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: delete file

  1. #1
    Join Date
    Dec 2005
    Posts
    127

    delete file

    Dear all
    what's the function name in c++ if i want use this function to delete my file

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

    Re: delete file

    DeleteFile

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: delete file

    Quote Originally Posted by GCDEF
    DeleteFile
    I love M$ for this, it's so intuitive.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Feb 2002
    Posts
    5,757

    Re: delete file

    also _wremove()

    Kuphryn

  5. #5
    Join Date
    Dec 2005
    Posts
    127

    Re: delete file

    Quote Originally Posted by kuphryn
    also _wremove()

    Kuphryn
    that's best one

    if( remove( "test.dat" ) == -1 )
    perror( "Could not delete 'test.dat'" );
    else
    printf( "Deleted 'test.dat'\n" );

    system("pause");

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

    Re: delete file

    Well, I would still go for DeleteFile, since it's underlaying WinAPI.
    Marius Bancila
    Home Page
    My CodeGuru articles

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

  7. #7
    Join Date
    May 2005
    Posts
    4,954

    Re: delete file

    I would use ::SHFileOperation() with FO_DELETE since DeleteFile()/ remove() would fail to delete read only file.

    Code:
      SHFILEOPSTRUCT fo={0};
      fo.wFunc  = FO_DELETE;
      fo.pFrom  = "C:\\delme.txt";  
      fo.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;
    
      ::SHFileOperation(&fo);
    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

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

    Re: delete file

    Hehe, the beauty of the IT world: event the simplest problem has 5 solutions that do not work 100% of the time and 1 that works for the time being but you never now in the future. These are the moments I feel the IT really makes the world a better place to live. ROFLMAO
    Har Har

  9. #9
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: delete file

    Quote Originally Posted by PadexArt
    Hehe, the beauty of the IT world: event the simplest problem has 5 solutions that do not work 100% of the time and 1 that works for the time being but you never now in the future. These are the moments I feel the IT really makes the world a better place to live. ROFLMAO


    unlink() - would be another option
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  10. #10
    Join Date
    Dec 2005
    Posts
    127

    Re: delete file

    how about if i want to delete one of folder all file , what's method i can do it

  11. #11
    Join Date
    Aug 2004
    Location
    Chennai, India.
    Posts
    380

    Talking Re: delete file

    Quote Originally Posted by PadexArt
    Hehe, the beauty of the IT world: event the simplest problem has 5 solutions that do not work 100% of the time and 1 that works for the time being but you never now in the future. These are the moments I feel the IT really makes the world a better place to live. ROFLMAO

    I Love to use WinAPIs DeleteFile..

    Hey PadexArt here I got you a more joy..... I got one more solution...

    CFile::Remove(fileName)....

    ..
    so now will u feel IT makes the BEST place.......

    ha ha ha..

  12. #12
    Join Date
    Nov 2005
    Location
    NC, USA
    Posts
    99

    Re: delete file

    Quote Originally Posted by roger5089
    how about if i want to delete one of folder all file , what's method i can do it
    Does (or can) the folder contain folders?

  13. #13
    Join Date
    Aug 2004
    Location
    Chennai, India.
    Posts
    380

    Talking Re: delete file

    Quote Originally Posted by roger5089
    how about if i want to delete one of folder all file , what's method i can do it

    go through the below link...
    Hope it helps you.

    http://www.codeguru.com/forum/showthread.php?t=239271

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: delete file

    One more:
    Code:
    system("del myfile.txt");
    Regards,

    Paul McKenzie

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: delete file

    Quote Originally Posted by dwurity
    Hey PadexArt here I got you a more joy..... I got one more solution...

    CFile::Remove(fileName)....

    ..
    so now will u feel IT makes the BEST place.......

    ha ha ha..
    No, It is the same as DeleteFile. Just look at the source code:
    Code:
    void PASCAL CFile::Remove(LPCTSTR lpszFileName)
    {
    	if (!::DeleteFile((LPTSTR)lpszFileName))
    		CFileException::ThrowOsError((LONG)::GetLastError());
    }

Page 1 of 2 12 LastLast

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