bidiu

Q: 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

Close

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

  • All replies
  • Helpful answers

Page 1 of 3 last Next
  • by rccharles,

    rccharles rccharles Jan 6, 2016 3:06 PM in response to bidiu
    Level 6 (8,459 points)
    Classic Mac OS
    Jan 6, 2016 3:06 PM in response to bidiu

    i would try to list to see what is going one:

    # display hidden characters as numbers

    ls -lb

    # if you have lots of files in the directory

    ls -lb | more

     

    ls -lB

     

    I have assumed you pulled out the flash drive.

     

    you can usually type a few characters then press tap to get the rest of the characters printed.

  • by bidiu,Helpful

    bidiu bidiu Jan 7, 2016 2:18 AM in response to rccharles
    Level 1 (1 points)
    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.

    Screen Shot 2016-01-07 at 17.32.55.png

    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 ::>_<::

    Screen Shot 2016-01-07 at 17.52.43.png

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

  • by Hiroto,

    Hiroto Hiroto Jan 7, 2016 4:54 AM in response to bidiu
    Level 5 (7,276 points)
    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

  • by bidiu,

    bidiu bidiu Jan 7, 2016 7:43 AM in response to Hiroto
    Level 1 (1 points)
    Jan 7, 2016 7:43 AM in response to Hiroto

    Hi, thanks for helping me, but seems not to work.

    Got this, "find: -delete: unlink(./Xiumi's Backup␀ alias): Invalid argument." Does this mean something?Screen Shot 2016-01-07 at 23.38.17.png

  • by rccharles,

    rccharles rccharles Jan 7, 2016 10:38 AM in response to bidiu
    Level 6 (8,459 points)
    Classic Mac OS
    Jan 7, 2016 10:38 AM in response to bidiu

    use disk utility to verify the disk.  Would be interesting to see if there is directory corruption.

     

    if so to fix, do a safe boot.

     

    Try a safe boot.

         Shutdown your machine.  Hold down the shift key.  Poweron.  Wait awhile; wait awhile while you harddrive

         is being checked.

         http://support.apple.com/kb/ht1455

  • by bidiu,

    bidiu bidiu Jan 7, 2016 11:04 PM in response to rccharles
    Level 1 (1 points)
    Jan 7, 2016 11:04 PM in response to rccharles

    I used disk utility to check my disk, and unfortunately no error occurred.

    Still do not know how to solve my problem.

    Very thank you anyway.

  • by Alberto Ravasio,

    Alberto Ravasio Alberto Ravasio Jan 8, 2016 6:07 AM in response to bidiu
    Level 5 (4,070 points)
    Jan 8, 2016 6:07 AM in response to bidiu

    Please make a backup before trying this.

     

    Open Terminal and cd to the Desktop directory

     

    issue

     

    vi ./

     

    move with the arrow keys on the line with the file name you can't delete. Press shift+D and confirm deletion pressing y then return. Quit vi typing

    :q!

  • by Hiroto,

    Hiroto Hiroto Jan 8, 2016 9:09 AM in response to bidiu
    Level 5 (7,276 points)
    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

  • by bidiu,

    bidiu bidiu Jan 9, 2016 8:24 PM in response to Alberto Ravasio
    Level 1 (1 points)
    Jan 9, 2016 8:24 PM in response to Alberto Ravasio

    Hi

    I've tried your suggestion, but doesn't seem to work.

    Thanks for your help anyway.

     

    Output:

    Screen Shot 2016-01-10 at 12.20.51.png

  • by bidiu,

    bidiu bidiu Jan 9, 2016 8:35 PM in response to Hiroto
    Level 1 (1 points)
    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.

    Screen Shot 2016-01-10 at 12.27.10.png

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

    Thanks for your help very much though.

  • by Hiroto,

    Hiroto Hiroto Jan 10, 2016 12:57 AM in response to bidiu
    Level 5 (7,276 points)
    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

  • by Alberto Ravasio,

    Alberto Ravasio Alberto Ravasio Jan 10, 2016 5:22 AM in response to bidiu
    Level 5 (4,070 points)
    Jan 10, 2016 5:22 AM in response to bidiu

    Desktop has Read Only permission?

     

    issue the following command in Terminal

     

    ls -lade ~/Desktop

     

    permissions should be

     

    drwx------+ 11 sunhe  staff  374 10 Gen 14:03 /Users/sunhe/Desktop

    0: group:everyone deny delete

     

    don't mind date and numbers

  • by Hiroto,

    Hiroto Hiroto Jan 10, 2016 6:42 AM in response to bidiu
    Level 5 (7,276 points)
    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

  • by bidiu,

    bidiu bidiu Jan 12, 2016 8:25 PM in response to Hiroto
    Level 1 (1 points)
    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.

Page 1 of 3 last Next