File deletion problem...

This is a discussion on File deletion problem... within the C++ Programming forums, part of the General Programming Boards category; I'm using the c++ remove() function but it will not delete the file for some reason =( Ideas?...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    File deletion problem...

    I'm using the c++ remove() function but it will not delete the file for some reason =(

    Ideas?
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    Could it be some kind of permission problem? Perhaps you could post the smallest and simplest compilable code that demonstrates the problem.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Okay... im actually having another problem coupled with this but i'll post that one seperately.

    Code:
    void deleteSnakeFile(string file)
    {
    	string rem= "/snakes/"+file+".dea";
    	remove(rem.c_str());
    	//remove from list
    	vector<string> rnames;
    	vector<string> rums;
    	loadSnakeList(rums, rnames);
    	//Search
    	int pos;
    	for(int i=0; i < rums.size(); i++)
    	{
    		if(rums.at(i) == file)
    		{
    			pos = i;
    		}
    	}
    	//Rewrite file
    	ofstream fout2("snakes/main_list.txt");
    	for(int i=0; i<rums.size(); i++)
    	{
    		if(i != pos)
    		{
    			fout2<<rums.at(i)<<"-"<<rnames.at(i)<<"\n";
    		}
    	}
    	fout2.close();
    	//Done
    }
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    Are you sure the current directory is correct? It isn't always the same as your executable directory, so when you use relative paths they are sometimes not what you expect. Test it with the full path and see if that works.

    If the path is right, be sure that any fstreams that you have used with that file have been closed.
    Last edited by Daved; 07-12-2007 at 11:35 PM.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,547
    One path is absolute, and the other is relative ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Expanding on Salem's idea, I would guess that you meant to use a relative path here, like you did lower down:
    Code:
    string rem= "/snakes/"+file+".dea";
    ->
    Code:
    string rem= "snakes/"+file+".dea";
    Unless you've created a folder on the root of your drive, c:\snakes, for example. In which case it'd be the other way around.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read from file problem
    By Martin Kovac in forum C Programming
    Replies: 1
    Last Post: 04-13-2009, 08:33 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. File I/O problem
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 12
    Last Post: 09-03-2005, 12:14 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Rename file problem
    By Emporio in forum C Programming
    Replies: 2
    Last Post: 06-05-2002, 09:36 AM

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