Ghost in the Machine – Delete Files with Long Path Names

Not quite Twilight Zone material, but do you want to see something really scary?  While Robocopy is a valuable tool for us system admins for copying or transferring files and performing backups, we have to be careful about how we use the options.  For instance, the MIR option will create a mirror of your source in your destination.  If you are trying to copy some additional files or perform a backup to add new data to your existing backup, you could be in for a nasty surprise.  The MIR option will delete anything in the destination that does not exist in the source.  If that is not your intention, make sure the option is not in your command path.  You will get bit by the data zombies.  You’ll be ready to organize a posse to track down the specter that made off with your data.

That’s right, blame it on the ghost in the machine if you think you can get away with that.  Good luck!

The Ghost in the Machine term was originally coined by Gilbert Ryle in 1949 to describe the human mind as existing independently of the human brain.  It has evolved to also describe the supposed consciousness in a device that behaves as if it has a will that is independent of what the human operator wants the device to do.  It has also been used by programmers to explain when a program runs contrary to their expectations.  The technology world did not exist in 1949 as we know it today, so the term makes much more sense in our world in my opinion than it does psychology.  After all, many users already describe a computer with strange issues as having gremlins, why not capitalize on that train of thought, eh?  That’s why we in the tech industry always have users reboot as the first course of action.  It works more times than not, doesn’t it?

Everyone knows gremlins can’t survive across the discontinuation of the power source, right?  Wink!  Wink!  Might as well incorporate Sci-Fi in this discussion as we system admins are already accused of speaking Klingon!

So, if you’ve ever tried to move or remove files or folders and been presented with the ‘Destination Path Too Long’ error, there are a couple of built-in options. One is that you can drill down into the folder or folders with the problem files, share the folder, map a network drive to the shared folder, open the mapped drive and delete the file or files, disconnect the mapped drive, and finally, delete the share. This method works well for copying or moving files. However, if you are trying to delete files, I prefer the second method, which I recently used when I was presented with the long filename error while trying to archive a huge user folder for one of our clients after the user had passed away.  That’s when Robocopy with the MIR option became really useful.

Yep, I put the ghost to work. 

The idea is to create an empty folder as your source, then mirror it to the target destination folder.  You can’t perform the copy, move, or delete function on the files, but the ghost can!  A prerequisite is to make sure you have at least the Windows 7/2008 R2 version of Robocopy then proceed to follow the steps listed below.  MIR is the switch that does the trick, and as a word of caution, personally, I would not use this switch for file transfers or backups, only for desired deletes.  Then, use it carefully to avoid unexpected results, which can end up getting pretty scary!  You’ll swear Sam Wheat has taken possession of your computer (remember Sam and Carl in the office scene in Ghost?).  The other switches that I have documented are optional, or you may have a favorite of your own you like to use.

Delete Files with long file names using Robocopy.

My command uses \R and \W switches to set retry and wait times.

  1. Remain calm while you cancel the long path error.
  2. Create an empty temp folder, say C:\Tmp.
  3. Open an administrative Cmd prompt window and type in your command.

Robocopy C:\Tmp D:\TargetPath /MIR /ETA /R:1 /W:1

  1. Sit back, have another cup of coffee, and let the ghost do its work.
  2. When it finishes, verify your target folder is empty – long file names and all, and thank the ghost

That’s a pretty easy fix for a frustrating issue.  In our office the other day, we had 2 very different conversations going on within hearing distance of each other.  In one, someone was describing the best way to cook spaghetti by pouring the noodles into the sauce rather than the other way around.  The second conversation involved fixing a 2003 server.  Somehow a few of us ended up having images of pouring spaghetti sauce on the server.  One person made the comment while chuckling, “Somehow, I don’t think the image I have in my head of pouring spaghetti sauce on a 15-year-old server will solve the problem.”  To which I replied, tongue-in-cheek, “Oh I don’t know, you’d definitely be getting rid of the 2003 server and getting a brand new 2016 server.  Problem solved!”   Now, you don’t have to turn your server into spaghetti, though I’ve seen some cabling that scrounged up the effects of hunger, the point is that we sometimes have to get a little creative with the tools we have in order to get the desired result.

Now that you know about the Robocopy /MIR solution, you don’t have to be in that wild-eyed, frantic frame of mind as Carl was in the movie, when he started realizing he was in the presence of a ghost.  You can sit back and watch the SAMSAMSAMSAMSAMSAMSAMSAM analogous output on the screen, knowing the ghost is at work on your behalf, with gratification that you won this round.  Ditto!

Recently from Rattan - Subscribe to get insight direct to your inbox.

Is your IT dept “just keeping the lights on”? We Can Help!

Let our professional team help your company with its day-to-day technology demands. We’ll free up your team’s time, advance your company’s digital transformation, and potentially save you money.  Start the conversation by completing the form below or give us a call at 405.810.8005.

    Recent Posts

    About The Author

    Donny Hilbern is a network and systems consultant specializing in analyzing, designing, and implementing network and enterprise systems.  Donny has been working in the IT field for over 25 years, with nearly 20 years of that time invested in network and system administration and infrastructure technology.  He has experienced a number of undocumented or lightly documented issues during that time.  His desire is to leverage that experience in sharing about some of those issues and how they were resolved to make IT work for his clients

    Recently from Rattan - Subscribe to get insight direct to your inbox.

    How can we help?

    Are you ready for the benefits of optimized IT services?