Thread: [MFC] Remove(), DelteFile(), _unlink nothing works

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    [MFC] Remove(), DelteFile(), _unlink nothing works

    Hi,

    at the moment i code my little project in MFC (ok i try it, becuase it is my first time with the MFC).
    I wrote a method which search for a file and then the file should be deleted. I used similar the same method as in my DOS version..with remove().
    But the program does not delete the file. I tried DeleteFile and also _unlink..nothing works :-/
    Here my code (i removed the MessageBox things to reduce the code here)
    Code:
    void CDialog3::OnSearch() 
    {
    	UpdateData(true);        //for a edit field
    	char temp_char[20];
    	strcpy(temp_char, m_input2);  //m_input was for the edit field
    	findPath("C:", temp_char, buffer);   //call the seach function
    	
    	
    	MessageBox(temp_char, "test");	//just for the tests 
                   //(if the temp_char has really the file name)
    		if (remove(temp_char) == 0)
    		{
    		MessageBox("removed", "sucessfully deleted");
    		}
    		else
    		{
    	    	MessageBox("sorry was not able to remove file", "error");
    		}
    	}
    	
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    "This is barely large enough for a normal filename, nevermind a filename with a path in front of it - are you sure you're not overflowing the buffer?"
    -->ok maybe its to huge but at the moment it works. i can reduce the size for it..but at the moment i want to fix the problem with the remove() function

    "The comment and the code are inconsistent - are you copying from the right place?
    Does the input have any funny characters at the end, say a newline?"
    -->if i understand my code, this variable save the stuff that the user write into the edit box..typ of this variable is CString.

    "So what is buffer, and how big is it?
    Later on, you use temp_char in the remove function - did you mean to use buffer?"
    -->char buffer[40]...i use a nice search algo '(found on planet source code) for searching a file on a whole hard drive. in the variable buffer the whole path plus file will be saved. I can use instead of temp_char also "calc.exe" for example.

    "Look at the error code then
    MessageBox("sorry was not able to remove file", strerror(errno) );"
    -->The error warning is: No such file or directory or so..but why..with this code:
    MessageBox(temp_char, "test"); //just for the tests
    i see that in temp_char contains the file name.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    13
    i used _getdcwd (cause my GetCurrentDirectory didn´t work) to receive the current directory..it shows me the direcotry in which the apllications runs....wait..ehh oh oh...i see something..ohh damit noo i just use in this minute the variable buffer (which gives me the full path to the file) an voliá the file has been succesfully removed. Thanks very much for you support Salem

Popular pages Recent additions subscribe to a feed