Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Cannot delete/rename/move a file from Windows with a special character

Not long ago, I used a portable hard drive to switch some data between my PC and MacBook (Running OS X 10.11.1).

Unfortunately, I was stupid to make an alias for my hard drive on my Mac's desktop by accident, right after my portable hard drive was mounted.

The question is that I can't even delete/rename/move it. Restarting system doesn't work, and commands (sudo rm/mv ..) from the Terminal doesn't work either.


When I was trying to remove/move the alias file, I got what's like this, "The operation can’t be completed because an unexpected error occurred (error code -50)."

And when trying to rename it with filename "a", I got what's like this, "Try using a name with fewer characters, or with no punctuation marks.''


I think this probably has to do with the hard drive's name, which has a weird character "NUL", one character. Maybe this character is legal in Windows, but illegal in OS X? Or maybe there're some differences between Windows and Mac interpreting a filename?


Any help, thanks!

MacBook Pro with Retina display, OS X El Capitan (10.11.1)

Posted on Jan 5, 2016 11:19 PM

Reply
43 replies

Jan 7, 2016 2:18 AM in response to rccharles

Hi, thanks for your reply!

It seems that this character is a printable one - "Xiumi's Backup NUL alias" is my flash drive's name, as shown in the picture below.

User uploaded file

Now I'm really suspicious of the name of my portable hard drive as the reason why I can't remove it.

Because when I changed my flash drive's name to simply "aaa" with my PC, plugged it into my Mac and made a alias of it, I can delete the alias without any problem.


So, any idea?

---

PS. This won't work ::>_<::

User uploaded file

I used TAB to help me completing my flash drive's name automatically.

Jan 7, 2016 4:54 AM in response to bidiu

Hello


You may try deleting the file by inode number. To do that, first get the inode number of the file by ls(1):


#!/bin/bash cd ~/Desktop ls -il



And then delete the file by inode number using find(1):


#!/bin/bash # e.g., delete file of inode number = 5873013 in ~/Desktop cd ~/Desktop find . -depth 1 -type f -inum 5873013 -delete



Good luck,

H

Jan 8, 2016 9:09 AM in response to bidiu

Hello


This seems to be tough one...


By the way, the NULL character shown in the name "Xiumi's Backup␀ alias" is ␀ U+2400 GRAPHIC FOR NULL, which is a sort of replacement character. I thought it is just for display purpose and actual character in HFS Plus name is U+0000 but possibly actual character in HFS Plus name could be U+2400 for some reason, in which case you might try the following command.



#!/bin/bash rm ~/Desktop/"Xiumi's Backup"$'\342\220\200'" alias"




Good luck,

H

Jan 9, 2016 8:35 PM in response to Hiroto

Hi ~

Maybe I'm too amateur, not quite understand your explanation about this character. And I'm also not quite sure whether it is the cause or something else.

Have tried your solution, still not to work - getting same message.

User uploaded file

Yeah, this seems to be tough and daunting one..

Thanks for your help very much though.

Jan 10, 2016 12:57 AM in response to bidiu

Hello


As far as I can tell, I can delete file with null chararcter in name under OS X 10.6.8.


To test it, I created file name with null chararcter in it, e.g., "abc\0xyz.txt", under (Classic) OS 9, put it in a HFS Plus disk image and mount it under OS X 10.6.8. Under 10.6.8, the file name is displayed as "abc␀xyz.txt" where null character is replaced with ␀ U+2400 GRAPHIC FOR NULL in both Finder and Terminal. I can delete the file via Finder by normal delete operation and via Terminal using name "abc␀xyz.txt" or $'abc\342\220\200xyz.txt' in bash. I even created alias file of this file and confirmed I can delete it as well.


So it might be new problem of later OSes or unidentified problem specific to your disk volume.


If you have OS X 10.6.8 machine, you might connect your MBP in Target Disk Mode to that machine and manipulate the file from OS X 10.6.8.


Ultimately you may initialise the volume to clear the problematic file.


Good luck,

H

Jan 10, 2016 6:42 AM in response to bidiu

Hello


Here's an AppleScript script you might try, which is a mere wrapper of pyobjc script using NSFileManager's method. To use it, copy the code into new window of Script Editor.app, run the script and it will ask you to choose the file in question and then try to remove it.



set f to (choose file)'s POSIX path do shell script "/usr/bin/python <<'EOF' - " & f's quoted form & " # coding: utf-8 import sys from Foundation import * for f in [ a.decode('utf-8') for a in sys.argv[1:] ]: b, err = NSFileManager.defaultManager().removeItemAtPath_error_(f, None) if not b: print(err.description().encode('utf-8')) EOF"




Briefly tested with pyobjc 2.2b3 and python 2.6.1 under OS X 10.6.8.


Regards,

H

Jan 12, 2016 8:25 PM in response to Hiroto

Hi


Thanks for your help, so many times!

I can't tell why you can‘t replicate my situation, but for now I believe this character '␀' definitely is the cause of my problem. Because if I create a completely new file (an ordinary text file) with a filename including this character, I can't delete this new file either.

And the script you provide cannot solve my problem - from the output is the same message, 'Invalid Argument'. Really appreciate your help though.

For these days, I've done some searches. Here is what I found analogous to my circumstances: Re: Can't delete a file.

According to the post provided by Niel, the character '' probably prevents the system-level call from targeting the file for deletion and I may not be able to delete the illegal file via any conventional OS X-based method. I think this might explain why your multiple solutions here just lead to the same outcome, 'Invalid Argument'.


From the Niel's post, and so many others, I've found some potential solutions. However, none of them works for me. Some say connecting to the machine running OS X 9 can solve the problem, but I don't have any machine running OS X 9. Also I might be able to solve the problem by manipulating the enclosing folder. But when I tried to do so, I was prohibited by the system, since the enclosing folder is /Users/xxx/Desktop, which is required by the system. And some suggest to erase the entire disk, which is too costly for me. I don't want to do that.

Still, I wonder why you can delete the file with filename including legal characters smoothly.

And thank you a lot.

Cannot delete/rename/move a file from Windows with a special character

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.