Categories
Windows 7

Can’t delete long or deep folder path

For a while now I’ve been using a scheduled backup that copies my windows profile to my file server on a nightly basis. Well since I switched to Vista and now Windows 7 I’ve noticed something funky.

If you look in your C:\users\<username>\AppData\Local (hidden folder) folder you’ll notice an "Application Data" directory with an icon that looks like it’s a shortcut and that you have no rights to access. Well it seems the Microsoft in all it’s wisdom created a junction point here that basically points back to itself.

So what happens when you have a backup solution that overrides access denied and then attempts to copy this folder is that you copy itself into itself over and over again until you reach the windows folder depth limit and error out. You end up with something like this but MUCH deeper

 folders.jpg

Well I search for about an hour and finally found a solution on Windows IT Pro, JSI Tip 9651.

By using RobCopy, which is now part of Vista and Windows 7, this script will automatically delete the deep/long folder structure. If you’re not runing Vista or Windows 7, make sure a copy of RoboCopy.exe is in the same folder as the batch file.

Copy and paste this into notepad and save as DelFolder.bat. The syntax is DelFolder.bat <FolderPath>:

@echo off
if {%1}=={} @echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 @echo Syntax: DelFolder FolderPath – %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.