remove(const char* ) only with extension?

This is a discussion on remove(const char* ) only with extension? within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, It seams that I have a problem with deleting files with remove(const char* filename) from a c++ program. ...

  1. #1
    Registered User mosu''s Avatar
    Join Date
    Jul 2006
    Location
    Cluj Napoca - Romania
    Posts
    10

    remove(const char* ) only with extension?

    Hello everyone,

    It seams that I have a problem with deleting files with remove(const char* filename) from a c++ program.
    If the file has an extension (any extension) it does deletes the file but if the file didn't have one (for example temp000 ) it does not delete it.
    Am I doing something wrong or it is suposed to work only with files with extension ???

    Thank you!

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    What does this say for you?

    Code:
    #include <iostream>
    #include <fstream>
    
    int main( void )
    {
    	std::ofstream out ( "thing.txt" );
    	out.close();
    
    	std::remove( "thing.txt" );
    
    	std::ifstream in ( "thing.txt" );
    
    	if ( in ) std::cout<< "EXISTS" << '\n';
    	else std::cout<< "DOES NOT EXIST!" << '\n';
    
    	in.close();
    
    	return 0;
    }

  3. #3
    Registered User mosu''s Avatar
    Join Date
    Jul 2006
    Location
    Cluj Napoca - Romania
    Posts
    10

    Smile

    Quote Originally Posted by twomers
    What does this say for you?

    Code:
    #include <iostream>
    
    int main( void )
    {
    	std::ofstream out ( "thing.txt" );
    	out.close();
    
    	remove( "thing.txt" );
    
    	std::ifstream in ( "thing.txt" );
    
    	if ( in ) std::cout<< "EXISTS" << '\n';
    	else std::cout<< "DOES NOT EXIST!" << '\n';
    
    	in.close();
    
    	return 0;
    }

    It tells me that I forgat to close the file ...

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Never forget to close files. Especially if you're going to be opening it a number of times within the same program. It's like when you allocate memory, with every new, you have do delete. I pretty much write one after another. With every file stream, you need a .close()!

  5. #5
    Registered User mosu''s Avatar
    Join Date
    Jul 2006
    Location
    Cluj Napoca - Romania
    Posts
    10
    Quote Originally Posted by twomers
    Never forget to close files. Especially if you're going to be opening it a number of times within the same program. It's like when you allocate memory, with every new, you have do delete. I pretty much write one after another. With every file stream, you need a .close()!
    Yep, you're right and I usually do this
    Probably I should sleep and leave this for tommorow
    Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Renaming file extension
    By mike_g in forum Tech Board
    Replies: 7
    Last Post: 07-10-2007, 08:27 PM
  2. Installing Thumbnail shell extension ?
    By glennpierce in forum Windows Programming
    Replies: 0
    Last Post: 07-20-2006, 09:38 AM
  3. Language extension
    By Prelude in forum Contests Board
    Replies: 48
    Last Post: 06-25-2004, 06:21 AM
  4. get file extension
    By Nada in forum C Programming
    Replies: 3
    Last Post: 12-22-2001, 08:12 AM
  5. sprintf, extension of files??
    By Gades in forum C Programming
    Replies: 10
    Last Post: 11-17-2001, 10:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21