We have a little problem here.

We have a share with the backup of all the server's offices, Its a really big share with more than 8.000.000 files.

Our users usually give long names to the folders they create, and then make subfolders (long too) and more subfolders... and more suboflders....

We have a new share with more capacity, and with a simpe robocopy bat we copied all the files and folders (some give problems, but we manually copied them)

But the problem is deleting them. del command didnt work well when so long paths, neirder rmdir... I'm tried some commanders, but no luck.

Can u recommend me any tool that can delete recursively or able to delete 255+ paths?

Edited: The SO on background of the share it's NetApp OS. But I can access it from Windows Servers. 2000 and 2003


Not perfect solution but that works

Here's the script on Windows Scripting I do to solve the problem. It isn't perfect but if anyone has the same problem can use it.

Option Explicit 
DIM strFolder

' ************************************************************
' Setup
' ************************************************************
' Folder to delete files from (files will also be deleted from subfolders)
strFolder = "Z:\del"
' ************************************************************
set objFSO = createobject("Scripting.FileSystemObject")

Wscript.echo "Processing " & strFolder
RecursiveDeleteByExtension strFolder

wscript.echo "Finished"

sub RecursiveDeleteByExtension(byval strDirectory)
    DIM objFolder, objSubFolder, objFile, Tmp, Indice

    set objFolder = objFSO.GetFolder(strDirectory)

    Wscript.echo "Processing " & strDirectory

    for each objFile in objFolder.Files
        WScript.echo "Deleting:" & objFile.Path
    Indice = 0
    For each objSubFolder in objFolder.SubFolders
        If Len (objSubFolder.Name) > 5 Then
            Indice = Indice + 1
            objSubFolder.Move(objFolder.Path & "\" & Indice & ".t")
        End if

    for each objSubFolder in objFolder.SubFolders
        RecursiveDeleteByExtension objSubFolder.Path
end sub

What this script do, recursively, is changing a very long path like \bla...\bla...\bla...\bla... to a much more shorter \1\2\1\2\ and after the renaming in the end of each recursion, it deletes the object folder (who's empty, btw).

It worker extremely well for me, even so we found full paths near 200 chars (imagine with before the script).

  • 4
    Specifying the operating system here would be very useful- I am assuming windows? – AliGibbs Feb 2 '11 at 12:35

This is a program dot_deltree.cs in C# which deletes directory trees of any depth. It works by first moving too deep directories to random name in the most shallow directory.

using System;
using System.IO;

public class dot_deltree
    public static void Main(string[] args) {
        if ( ! (args.Length == 1) ) {
            Console.Error.WriteLine("Usage: dot_deltree [path]");

        string dirname = args[0];

        if ( ! Directory.Exists(dirname) ) {
            Console.Error.WriteLine("{0} does not exist or is not a directory!", dirname);


        while ( true ) {
            string too_deep_dir = deltree( dirname );
            if ( too_deep_dir.Equals("") ) {
            string randomname = Path.GetRandomFileName();
                "Moving too deep directory {0}:{2} to random name {1}", 
                too_deep_dir, randomname, too_deep_dir.Length
            Directory.Move( too_deep_dir, Path.Combine(dirname,randomname) );

    public static void confirm_deleting(string path) {
        Console.Write("Do you really want do delete directory {0} recursively (type YES)? ", path);
        string result = Console.ReadLine();
        if ( ! result.Equals("YES") ) {

    public static string deltree(string uncpath) {
        if ( uncpath.Length > 200 ) {
            return uncpath;
        string[] subdirectories = Directory.GetDirectories(uncpath);
        foreach (string subdirectory in subdirectories) {
            string result = deltree(subdirectory);
            if ( ! result.Equals("") ) {
                // Return up too deep directory
                return result;
        // Console.Error.WriteLine("Deleting {0}", uncpath);
        return "";

Compiled using Mono C# compiler using gmcs dot_deltree.cs for .NET 2.0 is here (4kb).


try for /f "delims=" %a in ('dir /ad /b') do rm /s /q "%a" - it will recursively and without asking delete all the subdirectories of the current directory listed in dir /ad /b output

  • Hi Addan. Nice approach, but it didnt work becasue after lvl 1 dirs there are more long dirs. Something similar but with recursivity will work. Any ideas? – Carlos Garcia Feb 2 '11 at 14:42

If this share is the only thing on a partition then it would be easiest to just reformat it.

If there's something worth saving on the partition, then just copy it somewhere, reformat and copy it back.

  • I wish it was so simply. It's a CIFs Shared volum from a NAS of 3.4TB with much more info. Why are the backups inside the main share, and not in another volum is another history... but in short, I can reformat :) – Carlos Garcia Feb 2 '11 at 14:45

Try using "deltree". I'm on only linux right now, but I recommend doing a "deltree /?" first!

  • Tryed too before asking. Isn't on windows 2003 server :( – Carlos Garcia Feb 2 '11 at 13:49

Have you tried WinDirStat I'm not sure about the 255 limit as it issues windows commands to do the deleting but it might help you sort out the mess easier.

Very useful tool otherwise

  • Yep. tryed. In fact, it's the toold that I use for knowing what is using the space, and to delete. but when u delete them, it passes to the "windows" delete command. thanks for the point, anyway. – Carlos Garcia Feb 2 '11 at 13:48

What happens if you use robocopy's /move option? This will delete the files from the source after copying.

  • Correct. We used the /move option after the first one, and it moved many folders, but still didnt move many folders, listen on the "skipped" tab in the resum. Here's the resum of the logs – Carlos Garcia Feb 2 '11 at 14:47
  • Total Copied Skipped Dirs : 259592 163349 96243 Files : 868750 839296 29454 Bytes : 153.809 g 151.076 g 2.733 g As you can "barely" see on the comment, theres 30k folders (with their files) skipped with the robocopy /move option. – Carlos Garcia Feb 2 '11 at 15:10

What if you used ROBOCOPY with the /MIR flag to mirror an empty folder overtop the unwanted files? If it's smart enough to copy files with long names, it should be smart enough to delete them.

 MKDIR empty
 ROBOCOPY empty <dest> /MIR

Althoguh it's possible that this won't get any farther than Chris' suggestion.

  • Good aproach. I cant try it now. For my experience, if you tried to delete a folder with enought subfolders, windows gives an error. Dunno if the mirror option use "delete-create" method or "overwrite" method. – Carlos Garcia Feb 3 '11 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.