DelphiFAQ Home Search:

How to remove a file with special characters in its name (space, semicolon, backslash)

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I have a file with a semicolon in its name and cannot delete it. How can I delete a file with strange characters in its name (space, semicolon, backslash)?

Answer:

In Unix you can string commands together with semicolons, so Unix will interpret a semicolon in a filename as a separator. You can try the following:
  1. putting the filename in quotes
  2. put a \ in front of each of the special characters
  3. if the filename starts with a special character e.g. '-', put a ./ in front of it

Finally you can try using an FTP client, ftp into that directory and issue an MDELETE command (short: mde). It will offer to delete all files - say 'no' in all cases except for the chosen one. That way you do not have to specify the file name.

# for files with ;
rm "file;name"

# to remove '-filename'
rm "./-filename";


Comments:

2006-12-26, 07:37:48
anonymous from United States  
You also can use unix wild characters in this case:
rm -i file*

will remove any file that its name starts with 'file' while it does not delete without asking.
2008-07-02, 09:02:14
anonymous from United States  
Worked perfectly. Thank you !!
2008-09-17, 02:04:10
anonymous from India  
Thanks. your suggestion with the './' worked perfectly..

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.