2

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

Thanks.

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
DIM objFSO

' ************************************************************
' 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
        objFile.Delete
    next    
    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
    Next

    for each objSubFolder in objFolder.SubFolders
        RecursiveDeleteByExtension objSubFolder.Path
    Next
    objFSO.DeleteFolder(strDirectory)
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).

HBruijn
  • 77,029
  • 24
  • 135
  • 201
Carlos Garcia
  • 318
  • 3
  • 12

7 Answers7

2

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]");
            Environment.Exit(1);
        }

        string dirname = args[0];

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

        confirm_deleting(dirname);

        while ( true ) {
            string too_deep_dir = deltree( dirname );
            if ( too_deep_dir.Equals("") ) {
                break;
            }
            string randomname = Path.GetRandomFileName();
            Console.Error.WriteLine(
                "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") ) {
            Environment.Exit(1);
        }
    }

    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);
        Directory.Delete(uncpath,true);
        return "";
    }
}

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

Tometzky
  • 2,679
  • 4
  • 26
  • 32
1

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

addam
  • 430
  • 2
  • 6
  • 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 02 '11 at 14:42
1

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.

Tometzky
  • 2,679
  • 4
  • 26
  • 32
  • 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 02 '11 at 14:45
0

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

0

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 02 '11 at 13:48
0

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

Chris
  • 955
  • 7
  • 17
  • 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 02 '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 02 '11 at 15:10
0

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.

Nic
  • 13,425
  • 17
  • 61
  • 104
  • 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 03 '11 at 14:57