How to delete a file with invalid characters in Windows 8.1 (not even Cygwin helps)

07
2014-07
  • Kostas

    After a problem I've encountered with the Windows 8 Store I had to delete a system folder.

    Unfortunately, inside it there's a file with invalid characters (filename as it's displayed via ls or dir):

    0-FileAssociation-https∺∯∯next-services.apps.microsoft.com∯search∯6.3.9600-0∯776∯en-US_en-US.en.el∯m∯US∯c∯US∯il∯en-US∯cp∯10005001∯FileAssociation∯cid∯0∯pf∯1∯pc∯0∯pt∯x64∯af∯0∯lf∯1∯s∯0∯2∯pn∯0.dat
    

    Edit: In windows it appears as

    0-FileAssociation-https???next-services.apps.microsoft.com?search?6.3.9600-0?77‌​6?en-US_en-US.en.el?m?US?c?US?il?en-US?cp?10005001?FileAssociation?cid?0?pf?1?pc?‌​0?pt?x64?af?0?lf?1?s?0?2?pn?0?pgc?-1?phrase=sec.dat
    

    It's located at in a rather long path:

    C:\Users\Kostas\AppData\Local\Packages\winstore_cw5n1h2txyewy\LocalState\OldCache\0
    

    What I have already tried without success:

    • renaming it via either File Explorer -pressing F2 doesn't work and rightclicking doesn't show the full shell extension menu (shows only the entries Open with and Send to, instead)-
    • renaming it via elevated cmd
    • deleting via File Explorer
    • starting elevated cmd and trying the del command
    • launching Cygwin as admin and trying

    1. rm -rf *.dat 2. mv *.dat 1 3. find . -type f -delete 4. rm -- *

    and: 5. set -- 0-FileAssociation-https* echo "${#} file(s) found" (provided that the above outputs "1 file(s) found") rm -i 0-FileAssociation-https*
    All the above commands give: "cannot stat/remove/delete: No such file or directory"

  • Answers
  • Kostas

    The solution:

    • go to task manager and kill explorer.exe
    • go to File>Run new task: cmd
    • navigate to the OP path
    • use the del command
    • then re-launch explorer.

    Credit goes to user illuminÉ.


  • Related Question

    How to delete (invalid) files with colon in their name under Windows
  • hstoerr

    I've got a rather large number of files on my Windows drive that have a colon in their name. (These came from unpacking some Unix archives.)

    When I try to delete them, Windows (XP) complains that the file does not exist, and refuses to delete it. This happens when trying to delete or rename it from explorer or the command line. Still, chkdsk does not complain about those files nor fix the problem.

    Any ideas on how to get rid of them?


  • Related Answers
  • Joey

    You may be able to use this syntax (per Microsoft KB 320081):

    del "\\?\c:\path_to_file\bad:name.ext"
    

    See also this serverfault question on the same topic, "delete file containing invalid characters in windows".

    I think the old "ntfsdos" sysinternals utilities could remove/rename these files as well, but these are no longer available post-MS acquisition.

  • slhck

    You may want to try booting from an Ubuntu Live CD and deleting it from there.

  • Dave

    Another alternate that you may want to try is to bring in CygWin, a bash shell for windows. This would allow you to apply UNIX commands to your DOS folders.

  • tpbapp

    To fix this on Windows 7:

    chkdsk C:/r