Jump to content

Recommended Posts

Posted

I was doing some housekeeping on one of our file servers and I noticed the backup routine was bleating about being unable to access a handful of folders in the users area. On closer inspection it looks like the affected users have created a folder to house website files, either manually or my copying a website. The folders have no security properties and the folder name ends with a space. The folders are empty.

 

I can't delete them, taking ownership has no effect, and MS Article ID: 320081 is as much use as a eunuch in a brothel.

 

Any suggestions much appreciated!

  • 2 years later...
Posted
the folder name ends with a space.

I had exactly the same issue recently after some Mac users created folders that had spaces and question marks at the end which Windows didn't like. I used the script below to strip out every single illegal character from all files and sub-folders contained within a folder.

 

fix_filenames.pl

#!/usr/bin/perl -w

# This script renames all the files supplied as command-line args
# where necessary so that the filename is acceptable to MS Windows
# Cameron Hayne ([email protected]), June 2004
# http://hintsforums.macworld.com/showthread.php?t=25080

use strict;

chomp @argV = ) unless @argV;

# The Microsoft document at: [url]http://support.microsoft.com/kb/100108[/url]
# says that the following characters are not allowed in filenames in each of 
# the specified file-systems:
# FAT:   .  "  /  \  [  ]  |  :  ;  ,  =
# NTFS:  ?  "  /  \  <  >  |  :  *

# We don't do anything with the dot (.) since it clearly is allowable in spite 
# of what that document says.
# And we don't do anything with the slash (/) since that character will not 
# occur in OS X file names and modifying it would cause troubles when a file 
# path (with directories) is specified.
# The changing of the filenames is done via the 'tr' statements below.
# Each occurrence of a character in the first curly brackets is replaced by the
# character in the second curly brackets.

foreach my $filename  @argV)
{
   my $orig_filename = $filename;

   $filename =~ tr{\\}{-};
   $filename =~ tr{*?}{X};
   $filename =~ tr{"><[]|:;,=}{_};

   unless ($filename eq $orig_filename)
   {
   print "About to rename $orig_filename to $filename\n";
   if (-e $filename)
   {
       print "Oops, there already exists a file named $filename\n";
       print "Skipping the rename - you will have to do it manually\n";
   }
   else
   {
       rename($orig_filename, $filename);
   }
   }
}

 

To run it, open Terminal on a Mac, make the script executable (chmod +x ~/Desktop/fix_filenames.pl), cd to the folder above the one you want to strip the illegal characters from and then run the command below.

 

find -d . -print0 | xargs -0 ~/Desktop/fix_filenames.pl

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...