News and Articles on Technology, Finance and Marketing

Deleting very long complicated directory structure in Windows

If you are a programmer, you would have faced this kind of issue at least once in your programming life, a long folder structure got created and you are not able to delete it using Windows delete option nor with DOS commands.

Normally you can delete folders recursively using command "rmdir", for example, "rmdir delete_me /s /q" but if it is really large rmdir simply returns an error "File name too large...".

Root cause: In Windows and DOS, there is a flag "MAX_PATH" which has value 260, means a file path can have only a maximum of 260 characters including the drive and null character("D:\256-character path string"). So, files created by other programs which has more than 260 characters cannot be deleted using Windows or DOS commands.

There are multiple ways to delete these files/folders, like moving few set of folders into the root folder, or writing a script which will recursively delete folders etc. If you don't want to spend time on these try the command "robocopy". Robocopy is a Windows command to copy files from one location to another.

Syntax: robocopy <Source> <Destination> [<File>[ ...]] [<Options>]

There is an optional flag MIR which can be used to mirror a directory tree. We will use this flag to delete the folders recursively, how?

First we will create an empty directory say "c:\empty". Say the folder we want to delete is "c:\delete_me", then issue the command:

robocopy "c:\empty" "c:\delete_me" /MIR
The trick is, robocopy tries to mirror the empty folder; since there are no files or folders in the source directory, it simply deletes the files and folders under target directory recursively! Nice trick, isn't it?

Hope we saved your day! Feel free to drop your comments below.

Share:

No comments:

Post a Comment

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to our feed and get articles like this delivered automatically to your feed reader? Like our Facebook Page.

About Us

About Us
We provide you the latest news on technology, finance and entertainment across the globe. Fell free to contact us for any questions or concerns.

Popular Posts

Blog Archive

Recent Posts

Definition List

Definition list
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Pages

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.