Saturday, October 18, 2014

How to Delete a File Created by a Mac and Stored on a Windows File Server

So Macs suck for many-a-reasons, but the main one is that they have never seemed to play too well in a normal, corporate Windows-dominated environment. On the file system level Macs are allowed to put in illegal characters and spaces in places where Windows File Servers can't read correctly. If you need to delete, restore, backup, or edit said files and folders, problems arise.

The usual tricks that work are:

1. Mount the drive via a Mac and try to rename the file or folder manually by removing the trailing space, the period at the end of the filename, or removing the offending character.

2. Finding out the 8.3 name of the file via the DOS command:

dir /x

Then either axing it using the 8.3 name with the ~ in the name.

4. Or if it's a folder with a bunch of data in it, try to use Robocopy to rename the folder first.

Robocopy /MOVE /E /COPYALL BadFolderNameWithTilde NewFolderName

5. What also sometimes works is this command which kills the directory and everything under it recursively via Windows:

rd/s FolderName

6. Or killing it recursively through a mount via Linux or a Mac:

rm -rf FolderName

But in one situation none of my regular tricks worked until I found this site.

In a nutshell, nothing worked because the data used to reside on a 2008 R2 File Server where the 8.3 names did exist. All this data was migrated over to a 2012 R2 File Server, where the 8.3 names were stripped out and fsutil will show that 8.3 is not used at all to reduce overhead by default on the drive level. So without the 8.3 name, the folder was hosed. Solution is this command:

del "\\?\C:\Folder\Subfolder\FolderWithTrailingSpace "
del "\\?\C:\Folder\Subfolder\FolderWithTrailingPeriod."