Thread: How can I delete a file

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    How can I delete a file

    How can I delete a file? I'm making a windows program so I can't use any dos functions.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    How can I delete a file? I'm making a windows program so I can't use any dos functions.
    Yes you can.

    remove( filename );
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Ok, that works except the file I'm try to delete has spaces in it, and there are forward slashes in it for the folder it is in. Anyone know how I can delete this file without changing the filename?

  4. #4
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    That shouldn't matter. What is the filename?

  5. #5
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by pinkcheese
    Ok, that works except the file I'm try to delete has spaces in it, and there are forward slashes in it for the folder it is in. Anyone know how I can delete this file without changing the filename?
    You shouldn't have to change the filename. I've deleted files with spaces in the name before with no trouble. For the slashes for the path just use double-slashes.

    ie:

    The file you want to delete is:
    backup\back up.txt

    use:
    Code:
    remove("backup\\back up.txt");

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    The file I am trying to delete it: "C:\Downloaded Music\Bjork - Unravel.mp3".

    I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.

    If I rename the file to "Bjork-Unravel.mp3" and then put the program in the Downloaded Music folder and use remove("Bjork-Unravel.mp3") it does work.

  7. #7
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.
    I wonder why? Change that to remove("C:/Downloaded Music/Bjork - Unravel.mp3")

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    99
    I've tried remove("C:\Downloaded Music\Bjork - Unravel.mp3") and it doesn't work.
    Maybe I'm wrong but I though it was:
    remove("C://Downloaded Music//Bjork - Unravel.mp3");
    Or something similar.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    Sorry guys, remove("c:/Will's/Etcetera MP3 source/Downloaded Music/Bjork - Unravel.mp3") does work. It appers that my problem is somewhere else.

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    13
    Does this method work only for Windows or will it work for Linux too?

  11. #11
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Well, as far as I know stdio.h is a standard header... so I would think it would work with Linux. Go search the man pages for it, I'm sure you'll come across it or something similar.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It appers that my problem is somewhere else.
    Yeah. Your problem was that when you include a single backslash in a string, it treats it as an escape code. Thus:

    "c:\program files"

    Actually means:

    "c:[ESCAPE-P]rogram files"

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    13
    you should go
    Code:
    remove("C:\\Downloaded Music\\Bjork - Unravel.mp3");
    To put a '\' char into a string literal, you must go "\\".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM