How To Delete Undeletable Files and Folders

How To delete those undeletable files and folders


Ace Fekay, MCT, MVP, MCITP EA, Exchange 2010 Enterprise Administrator, MCTS Windows 2008, Exchange 2010 & Exchange 2007, MCSE 2003/2000, MCSA Messaging 2003
Microsoft Certified Trainer
Microsoft MVP: Directory Services
Active Directory, Exchange and Windows Infrastructure Engineer



A little background on undeletable files and folders


I’ve seen these in the past regarding ‘pubbed’ FTP servers by software, game and movie users that find open FTP servers. They would upload their illegal software to the FTP servers they find, but they would name the files and the folder they create with extended characters and symbols that FTP supports but Windows does not directly support (ASCII characters), as well as create a very deep file structure with these extended unsupported ASCII characters, and/or file names with these characters that are greater than 256 characters. Windows directly supports ANSI characters. However, although Windows supports ASCII characters indirectly, it is not supported directly through the Windows Explorer GUI or the command line. Therefore this prevents admins from getting to them or deleting them, nor delete them. In the older NT4 days, you could install the POSIX support tools (to support UNIX based commands and using ASCII characters) to read and remove them, but that no longer applies with Windows 2000 and newer. However Windows still provides POSIX support but not directly. They can be deleted by using specific commands, but you just have to know the commands!


Also, if it was an FTP created folder and files, and the size shows zero bytes, yet you know it is much larger, then it’s also likely the files are using an alternate data stream which would explain why their file size appears as zero bytes.


 


Is the drive NTFS?



So the other factor, as mentioned, is if the file, folder name, and/or number of child folders is greater than 256 characters. Many operating system limits are based on the i386 addressable 32bit architecture, such as the number of users that can access a share, which is 4.3 billion objects. It also depends on the drive and if an app can read it. Many programs also expect a limit of 256 objects (characters, paths, bytes, etc), maybe even the deltree command is limited, however NTFS formatted drives can go beyond the 256 objects.


Therefore, not being able to delete them is caused by the factors above, special or extended ASCII characters, trailing spaces, trailing dots (periods) or reserved names in the folders, such as com, lpt, etc, such as when a machine gets ‘pubbed’ into an FTP site where the ‘pubsters’ will create these deep paths and using reserved names to prevent the admin from deleting them. If you’ve found someone accidentally created such files or subfolders with these characters, it will give you headaches to remove them. With an FTP app it’s easy to read and remove them, because FTP uses ASCII characters, such as what POSIX uses, however WIndows uses ANSI and cannot translate the folders. In this case, you can setup a local FTP service, then use an FTP app to connect to your own machine, then you wil be able to read and delete the files and folders. That is only one option, which many adminstrators are reluctant to do.


 


Removing folder examples:


Assuming the first folder is the numeral “1” on D drive (and use the quotes if you have problems and watch the required periods if the command uses it):


rm -r “//D/1″


RD \\.\c=D:\1


RmDir \\.\D:\1 /s /q


RmDir \\.\C:\YourFTP_ROOT’s_PATH\COM1 /s /q


C:\>cd inetpub\ftproot
C:\Inetpub\ftproot>rd /s /q \\?\c:\inetpub\ftproot
NOTE – The syntax is literal, do not substitue or remove the question mark (?), change only the path.



Removing files examples


Note: In the following examples, if the filename contains symbollic, extended or other characters, enter what you can and wildcard the rest or use file completion or use a full wildcard.


DEL \\.\c:\somedir\filename.


DEL \\.\c:\somedir\lpt


DEL \\.\c:\somedir\aux


DEL \\.\c:\somedir\com


etc



Read the following references for more information and instructions.


How to Remove Files with Reserved Names in Windows:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q120716


You cannot delete a file or a folder on an NTFS file system volume:
http://support.microsoft.com/kb/320081


Cannot Delete Files or Folders with Extended Characters:
http://support.microsoft.com/kb/131702


Here’s how to create a locked folder with FTP:
http://www.madchat.org/coding/w32nt.rev/dirnt.htm
 
Here’s how to delete them:
How to Remove Files with Reserved Names in Windows
http://support.microsoft.com/kb/120716



Ace Fekay

Leave a Reply