Closed

deleting file whose path is already too long

Archived from groups: microsoft.public.win2000.file_system (More info?)

Not sure how it happened, but a user created a file in an
NTFS LAN folder whose path is longer than 256 characters.

How to delete or rename it to something shorter?

I can't even get its properties from cmd.exe or Windows
Explorer.

thx,

John
9 answers Last reply
More about deleting file path long
  1. Archived from groups: microsoft.public.win2000.file_system (More info?)

    One simple method I've used in the past to manage folder trees longer than
    MAX_PATH is to break the trees into chunks. So..
    Traverse the directory as deep as you can within Explorer or the command
    shell. Then move all the contents below it to the root of the drive (or a
    folder under the root) so you now have a second directory tree. If the new
    tree is still greater than MAX_PATH, repeat until you get a manageable tree.
    What you do with the multiple directory trees is your business, but at least
    they're manageable :).

    --
    Brian [MSFT]

    Disclaimer: This posting is provided "AS IS" with no warranties, and confers
    no rights. Please do not send e-mail directly to this alias. This alias is
    for newsgroup purposes only.

    "John Monroe" <anonymous@discussions.microsoft.com> wrote in message
    news:2de8401c46aa7$f4cced50$a501280a@phx.gbl...
    > Not sure how it happened, but a user created a file in an
    > NTFS LAN folder whose path is longer than 256 characters.
    >
    > How to delete or rename it to something shorter?
    >
    > I can't even get its properties from cmd.exe or Windows
    > Explorer.
    >
    > thx,
    >
    > John
  2. Read this article and try use the "\\?\UNC\" prefix:
    http://msdn2.microsoft.com/en-us/library/aa365247.aspx
  3. If you know how to use Java....

    I did this under Windows XP

    Install a recent Java JDK (http://java.sun.com). I used 1.6.0_11 (change the batch file as needed)

    I put my work files in C:/JavaStuff/DeleteTree, so all the instructions here assume you will do the same.

    Create a Blackscreen batch file - DeleteTree.bat
    ----
    @echo off
    echo Using jdk Java 1.6 with xp

    SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_11
    SET PATH=C:\Program Files\Java\jdk1.6.0_11\bin;c:\JavaStuff;c:\JavaStuff;
    SET CLASSPATH=%CLASSPATH%;.;c:\JavaStuff;c:\JavaStuff\DeleteTree;
    SET CLASSPATH=%CLASSPATH%;c:\JavaStuff\DeleteTree\commons-io-1.4.jar;

    c:
    cd c:\JavaStuff\DeleteTree
    c:\windows\system32\cmd.exe
    ----
    NOTE: On some Windows platforms the last line will be
    'c:\winnt\system32\cmd.exe'


    Download and unzip Jakarta IO from http://commons.apache.org/io/ - I used V1.4

    Copy the commons-io-1.4.jar file to c:\JavaStuff\DeleteTree\

    ---

    The subdirectory I wanted to delete and everything in it was 'E:\xlook\ads-old'

    It was created by an error in an Eclipse file I was trying (probably 100,000 or so subdirectories were created).

    Change the Following Java file to use the file path you need to remove:
    ---

    // DeleteTree.java

    import java.io.*;
    import java.util.*;
    import org.apache.commons.io.FileUtils;

    class DeleteTree{
    public static void main(String args[]) {
    try {
    File rm = new File("E:/xlook/ads-old");
    FileUtils.deleteDirectory(rm);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    ----

    Double click on the DeleteTree.bat file - this will give you a Blackscreen. if your Java is setup right, you will have access to a Java Compiler and the Java Run time.

    Enter the following commands to compile and run the application:

    C:\JavaStuff\DeleteTree>javac DeleteTree.java

    C:\JavaStuff\DeleteTree>java DeleteTree

    ----

    In my case, it took quite a while for the program to finish (6 minutes or so), it was a very deep tree.

    You can use notepad for the editor. If you use the same setup I used, It should only take 15 minutes or so to create and compile everything.

    I did not allow you to pass in a path to the program - I considered this a dangerous thing to do - that is why I force you to hard code the exact path name in.

    This is all free.
  4. I tried the \\?\ trick as posted above and it worked great. I looked up the volume name of my C: drive using mountvol.exe (I'm on win2k). Just type 'mountvol' on the command prompt and hit enter. It tells you the volume names of you drives in \\?\ format.

    For example... when I typed mountvol on the command prompt, it reported my C: drive as the following:
    \\?\Volume{b7aad3c6-f6c0-11dd-916c-806d6172696f}\

    Then I used that as the first part of the path to the problematic long-named item. Mine was a folder that was named too long.

    So I did this:
    rmdir "\\?\Volume{b7aad3c6-f6c0-11dd-916c-806d6172696f}\folder1\problematic folder"

    Then pressed enter and the folder was deleted. Yay!

    I used quotes around the entire path since there were some spaces in the path.

    Hope this works for you.
  5. Similar to the "\\?\" trick, but easier in practice. Share a folder some way down the directory tree and open it as a share (from Network Neighbourhood). You should then have no problems as the path will be much shorter.
  6. No you haven't. You're trying to sell me some useless bit of software. No sale!
  7. Ijack said:
    Similar to the "\\?\" trick, but easier in practice. Share a folder some way down the directory tree and open it as a share (from Network Neighbourhood). You should then have no problems as the path will be much shorter.


    Map a drive letter to any folder deep within your directory tree. This replaces, for example, "\\obrtw23\Business\BusinessPlanning\2009Plans\PurchasingPlan" with "L:\".

    You do this by right-clicking on "My computer" and selecting "Map network drive" . Whatever you put in for the path, that will be equivalent to the new drive letter. Just keep the mapped path short enough to work.

    In fact, that's how people often manage to create those files with so many characters in the past in the first place. They PUT the files there using a mapped drive letter, and therefore the path was short enough. Later, when someone tries to browse there the long way, using the full path, they have problems.

    I don't understand why Microsoft hasn't changed this... it's been a problem for a decade or more!
  8. dOSMs tool goes into the old technician toolkit. Free, useful, and simply works as advertised.
  9. This topic has been closed by Mousemonkey
Ask a new question

Read More

Windows