windows 8 - How to delete a file with a path too long to be deleted

07
2014-07
  • Answers
  • LPChip

    Assuming you are on windows:

    What I always do is use subst to create a driveletter asccociation with part of the path.

    Then go to the new driveletter and navigate to the files that have long names. You should now be able to rename/delete/etc them. The reason this works is because the path itself is no longer containing >255 chars.

    To create a subst folder

    1. Start a commandprompt (no admin privileges needed)
    2. Use cd to navigate to the folder you want to go (you can use tab to autocomplete names
    3. type subst j: . to create the driveletter association. (instead of the . you can also type the entire path)
    4. Now in explorer you have a new letter. Go to it and do whatever you need to do to the .cache files.
    5. Go back to your cmd window and type subst /d j: to remove the drive or alternatively, restart your pc.
  • Wutnaut

    Googled: delete long filename First result

    Use Unlocker http://www.filehippo.com/download_unlocker/

    Cannot delete folder: It is being used by another person or program Cannot delete file: Access is denied There has been a sharing violation. The source or destination file may be in use. The file is in use by another program or user. Make sure the disk is not full or write-protected and that the file is not currently in use.

    Unlocker can help! Simply right-click the folder or file and select Unlocker. If the folder or file is locked, a window listing of lockers will appear. Simply click Unlock All and you are done!

  • Compro01

    Microsoft has a useful knowledge base article on deleting undeletable files. Cause #4 is of relevance to you.

    Your best bet would probably be to map a drive to the folder that file is in (resolution #3), then enter in through that drive and delete it.

  • Debra

    Your question asks how to delete a file when the filename itself is too long. If the path is too long and not just the filename itself, you can easily just rename the folders to make the path shorter.

    But to delete a file whose name is more than 255 characters:

    • Open a command prompt by running "CMD.EXE"
    • Navigate to the folder holding the file
    • Use the command DIR /X which will display the short names of files.
    • Delete using the short name.

    i.e. if the file is named "verylongfilename.fil", the shortname will display as something like "verylo~1.fil" and you can delete using that name.

    Please note that although Windows itself can handle paths far longer than 255 characters, most of the GUI -- like Windows Explorer -- is bound by the shorter limit.


  • Related Question

    How to delete a file in Windows with a too long filename?
  • user3048

    Possible Duplicate:
    Tool for deleting directories with path/names too long for normal delete

    My wife has several files and folders that somehow ended up having filenames that have caused them to be undeleteable (can't be deleted) by normal means or via the command line. I believe the filenames are too long due to the depth of the folder structures. Does anyone know of a good utility for cleaning up files like this?


  • Related Answers
  • Benoit

    When you want to completely delete a directory and it has file with long names inside it, robocopy does a VERY good job:

    mkdir empty_dir
    robocopy empty_dir the_dir_to_delete /s /mir
    rmdir empty_dir
    rmdir the_dir_to_delete
    
  • Will Eddins

    From a command prompt:

    dir /X
    

    This will list your files/folders in short name format. Then use the short name exactly as written to delete the file:

    del LONGF~1.txt
    
  • joeqwerty

    I progressivley work my way into the path, renaming each successive parent folder to "1" and attempting to delete. You're effectively shortening the path each time and I've never had to work in by more than 4 or 5 directories until I'm finally able to delete the entire directory structure (which may or may not be what you want). You could do this from the last child folder as well and work your way up or down.

  • grawity

    In some programs, including Command Prompt (cmd.exe), you can get around the file length limit by prefixing the full path with \\.\ like this:

    \\.\C:\some directory\other directory\a file with long name
  • ldigas

    Rename the directory of cut/paste the file somewhere else, then delete it. Works here.

    Or just from the command prompt, if you don't feel like going through the trouble.

  • AdamV

    A trick I have used to get round the "full path and filename" length limitation in order to move, copy or delete something is to shorten it by 'breaking in' halfway down (or more) using a mapped drive letter pointing to a folder way down the path.

    so you have c:\some\long\path...\and\foo\bar\folders\oldfiles\myoldfile.txt.

    Then map an arbitrary drive letter to somewhere along the path so that the first chunk of the path becomes only a few characters long. Pre-requisite - the folder must be in a shared folder (which it may already be if it is on a server, which is where I have needed to do this), and if it is not already then pick a folder somewhere in the path and share it. Depending on your environment and paranoia level, allow everyone modify access to the share as long as the NTFS permissions are reasonably restrictive. If you want, just allow modify rights only to your own account.

    Now go to the shared folder or one inside it and share it, or use the command line as follows. Assume you shared folder "foo" as "fooshare", then you could do

    net use x: \\mycomputername\fooshare\bar\folders /persistent:no
    

    and the X: drive now points directly to the folder "folders" inside that share, so "x:\oldfiles\myoldfile.txt" is now pretty short.

    (The "/persistent:no" means this won't survive the next reboot and confuse you later on. Don't forget to un-share your folder when done.)

    Remember, you don't have to share the folder containing the file necessarily, if it is already inside a shared folder you can just map through the share and the nested folders to a target folder near to the file and that works fine.

    I've had to use this technique doing a massive robocopy between two servers when we realised that users had mapped drives quite deep in the folder structure, so they had been able to use 255 characters from there, but that exceeded the total file path length when accessed from the local drive root.

  • Col

    The simplest way I've found is to boot from an ubuntu live CD.

    As an alternative you can create a shared folder halfway down the path and then map a network drive to that and do the delete from the mapped folder (even on the same machine)

  • William Hilsum

    Probably not the best way and I am interested to see what others come up with -

    I had this once and I tried a few things without any luck. Rather than looking for a good tool, I restarted with the Windows Disk in, went to the recovery console and just deleted it from there. Worked first time and really well!

    Also, just did a Google for you and found this - DelinvFile Looks Good but cannot vouch for it.

    Edit - Warning, just seen the above is only a trial - Maybe not as good as I first thought!

  • Bob

    You could always try Unlocker as it has delete capabilities for 'awkward' files.