Deleting a very long path in a directory

Viewed 11506

I have a pretty weird problem with a folder structure that was created by my ant build...it created a folder structure such that C:helper/class/helper/class/helper/class and goes on for a very long time.

I was wondering if there was some script that I could use to delete these folders using cmd on Windows 7.

I have already tried:

rmdir /s /q

along with trying to use :

robocopy "C:helper/class/helper/class/helper/class" C:Test

But still I got no luck...

Does anyone have any suggestions or script that I could use for a bat file to recursively delete this structure?

7 Answers

i've done it with "FastCopy ver3.13"

source : path of to long directory

dest: c:\x\

operation mode (drop down): Delete all (delete all files / dirs by force)

executed it 3 times, and my problem was solved. robocopy, 7zip does not work for me.

I did it programmatically, see the code below

public static void main(String[] args) throws Exception {

    // This "c:/e" folder contains more then 5000 inner folders with name 'e'.
    // Removing of these folders is slow.
    // It takes about 10 minutes to delete a single tail folder programmatically.
    // But we can arrange these folders to a flat structure with 100 sub-folders depth.
    File root = new File("c:/e");

    // This folder will have parts of the root folder
    File target = new File("c:/e2");
    target.mkdirs();
    int currentFolderNum = 0;

    // Walk to the last folder
    while (root.exists() && root.listFiles() != null && root.listFiles().length > 0) {
        if (root.listFiles().length > 0) {
            root = root.listFiles()[0];
        }
    }

    // Now the root folder is a tail of c:/e/e/...

    int numFolders = 0;
    int nextNumber = 0;
    int partSize = 99;
    while (root.getParentFile().getName().equals("e")) {
        File parentFile = root.getParentFile();
        if (numFolders++ == partSize) {
            File newFolder = new File(target, "f" + ++nextNumber);
            boolean renamed = root.renameTo(newFolder);
            log.info("Count: {}. Folder: {} Moved? {}", currentFolderNum, newFolder.getAbsolutePath(), renamed);
            if (!renamed) {
                System.exit(1);
            }
            numFolders = 0;
        }
        root = parentFile;
        currentFolderNum++;
    }
}

Now all folders in the c:/e2 folder have short names and can be removed with TotalCommander or Windows Explorer.

Related