Saturday 15 September 2012

How to delete and rename files in C on windows -


I am working on a program that renames or removes files in the file system. I am using C and it works well on Linux machine but fails in windows. I use the GCC compiler suite and the following is a code that does not remove files from my file system

Thank you in advance

  #include    

There are many problems with your code.

  four fds lete [25];   

It may have been acceptable for at least 20 years, but nowadays more than 25 characters have the potential for a file name. You probably want to use FILENAME_MAX .

  stdin;   

It gives undetermined behavior (calls fflush with the file opened to input as its code). Just do not do that.

  becomes (fdelete);   

becomes is a serious source of security problems, never use it instead use fgets .

  Four franem [25]; Similar problem with   

fdelete

  stdin; Becomes frename;   

Problems like the above.

Everyone has said that, Remove should be deleted by a file that there are no other links to that file and the name you pass is the actual file name.

No comments:

Post a Comment