How to batch rename files copied from OSX to Windows with ':' in filenames?

3

1

This is really puzzling. I have lots of videos that were stored using Mac OS, and now I have to edit them on Windows XP. I copied files using HFSExplorer. Editing software refuses to open the files with their current names, and so far I have not found a way to batch rename all the files.

Names of the files look like this:

clip-2009-10-01 21;26;00.mov

But I suspect in OSX the time was 21:26:00.

I would like to replace the space with an underscore, and semicolons with dash.

I've tried several bulk rename applications, with ; and :, but in vain. Also I've tried rename.pl, but also in vain.

tputkonen

Posted 2009-10-01T18:37:28.407

Reputation: 365

if the names are all fixed format you could do it with a batch file. But you best bet will be a tool like "John T" said. – Matthew Whited – 2009-10-01T18:55:44.003

i'm getting the suspicion that the filenames are not actually "clip-2009-10-01 21;26;00.mov" even though they look like that. Win systems disallow ":" as a filename character, but other filesystems allow it. If the filename was actually "clip-2009-10-01 21:26:00.mov", Windows would NOT display it correctly (would probably display the ":"s as ";"s). Manual renaming would still work. SOME of these tools that you've found not to work might work if you tried replacing ":" with "-". – quack quixote – 2009-10-02T16:57:48.443

Thanks for an interesting insight. I tried Bulk Rename Utility and Lupas but both failed also with :. – tputkonen – 2009-10-04T07:38:01.957

ok, two more ideas, one would be failsafe if this we've got the problem diagnosed correctly. see my answer. – quack quixote – 2009-10-04T09:09:07.517

also, this is very similar to this question: http://superuser.com/questions/31587/how-to-force-windows-xp-to-rename-a-file-with-a-special-character

– quack quixote – 2009-10-04T10:02:46.207

did the perl script-generator i posted work? or did it break on your actual DIR/X output? – quack quixote – 2009-10-04T18:16:34.897

Just noting that OS X doesn't allow ":" in filenames either. Historically ":" used to be the directory separator, what Windows uses "" for. – deceze – 2009-10-05T06:38:41.177

@deceze thanks for the info. the main takeaway is that some character from the OSX filenames was disallowed in Windows, causing the displayed filename to be wrong. – quack quixote – 2009-10-05T19:31:37.487

Answers

4

Updated:

We're under the assumption that "clip-2009-10-01 21;26;00.mov" is not the actual filename; one possibility is that the actual filename is "clip-2009-10-01 21:26:00.mov". However, we can't verify that under Windows.

We may not need to.


Failsafe Method:

Boot to a Linux LiveCD. Ubuntu 9.04 has good NTFS support, and Linux handles a lot more wonky-characters-in-filenames than Windows. The perl rename script may be included as the system's rename command.


This-Might-Actually-Work Batch Method (New Script!)

The DOS command DIR/X shows short filenames, if they exist on your system.

$ cmd
c:\test> dir /x
 Volume in drive E is NUVOL
 Volume Serial Number is 80D3-A96D

 Directory of e:\tor\test

10/04/2009  05:15 AM    <DIR>                       .
10/04/2009  05:15 AM    <DIR>                       ..
10/04/2009  05:11 AM                 0 CLIP-2~1.MOV clip-2009-10-01 21;26;00.mov
               1 File(s)              0 bytes
               2 Dir(s)   5,201,670,144 bytes free

If they do exist, the REN command will move them to a new name; the new name can be a new (valid) long filename.

c:\test> ren CLIP-2~1.MOV "clip-2009-10-01_21-26-00.mov"

That's how to fix one.

To batch process all of them, you need to 1) grab a listing of all the files you want to move; 2) run a short perl script to convert your listing into a batch file with the appropriate REN commands; and 3) run the resulting batch script.

c:\test> dir /x > mybrokenfiles.lst  
$ cat mybrokenfiles.lst | perl -lne 'next if not /MOV/; s/^.{1,39}//; s/^/ren /; s/ (\d\d);(\d\d);(\d\d)/_$1-$2-$3/; print' > fixmybrokenfiles.bat  
c:\test> fixmybrokenfiles.bat  

The perl commandline assumes a very particular input format, so if the DOS listing shows long filenames in something other than the "21;26;00.mov" format, it probably won't do exactly what you want. If you try it, double-check that the batch script looks right before running it.

If you are comfortable with perl (or sed/awk, python, whatever), you can script this yourself. But if DIR/X doesn't show the short filenames, your system has them disabled, and this solution won't help.


Original answer: not useful with what we know now, but if you copy this sort of file off of OSX again, you can use this BEFORE the copy as a preventative step.

I use the commandline a lot on both Windows and Linux systems. There's a handy perl script floating around the internet that allows batch file renames using standard perl regex's (google for rename.pl to find it).

Under Cygwin on windows, use this in the directory your files are located in to rename them:

$ ls
clip-2009-10-01 21;26;00.mov

$ rename.pl 'tr/ ;/_-/;' * 
$ ls
clip-2009-10-01_21-26-00.mov

Pretty sure my version came from the Perl Cookbook:

#!/usr/bin/perl -w
# rename - Larry's filename fixer
$op = shift or die "Usage: rename expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

quack quixote

Posted 2009-10-01T18:37:28.407

Reputation: 37 382

Another fantastic answer by @quack quixote – Josh – 2010-05-06T20:48:24.107

Note cygwin is not a requirement for this; I believe ActivePerl or any other Windows Perl interpreter would work as well. – quack quixote – 2009-10-01T20:08:40.923

I tried that already, but it doesn't do the trick. Name of the file isn't changed. I'm starting to think there is something strange in my environment, I just don't have a clue what. – tputkonen – 2009-10-02T16:04:36.257

Which version? cygwin or activeperl? if cygwin, what perl version? my example usage was an actual test on your filename, so it worked for me. – quack quixote – 2009-10-02T16:54:47.590

Cygwin. The issue may be that the file was copied from OSX. Please see the comments to original question. – tputkonen – 2009-10-04T07:38:44.093

Renaming the short files works - thanks for the tip! – tputkonen – 2009-10-04T17:59:06.490

woot! does the DIR/X output work with perl to generate the batch script correctly? – quack quixote – 2009-10-04T18:13:53.047

It does - thanks!! Because the files are BIG I just changed the line a bit to:

cat mybrokenfiles.lst | perl -lne 'next if not /MOV/; s/^.{1,36}//; s/^/ren /; s/ (\d\d);(\d\d);(\d\d)/_$1-$2-$3/; print' > fixmybrokenfiles.bat

It might have been possible to do that with awk as well.

Thanks a lot!! – tputkonen – 2009-10-05T17:51:31.277

sweet. yes, awk could do it as well, or even sed. i'm more familiar with perl so it was easier there (in my sed attempt, the final substitution regex had to escape all the parentheses too, so was hard to read). – quack quixote – 2009-10-05T20:50:20.823

sadly i just made one of these on my system, and no short filename to fix. have to take the drive back to the original system just to rename it. :( – quack quixote – 2009-10-06T07:13:42.280

2

Check out Rename Master, it has a myriad of ways to manipulate filenames in batch. You'll want to check out the replace tab.

alt text

Rename Master is freeware.

John T

Posted 2009-10-01T18:37:28.407

Reputation: 149 037

1

Just do this in mac or linux. This will rename all files and folders with a : to a -

find . -depth -exec rename 's/:/-/g' * {}\;

patrick

Posted 2009-10-01T18:37:28.407

Reputation: 11

1

Lupas Rename is a FREEWARE program developed to rename a big number of files. It works on Win95, Win98, WinME, WinNT, Win2K and WinXP. It is a simple .EXE file and doesn't need any other external libraries.

Here are some of the features :

  • Rename files and folders
  • Rename files in recursive subdirectories
  • Shell Integration (right click on a folder in the explorer to start LupasRename on these folder)
  • Instant Preview (Optional)
  • Undo the last rename operation
  • Make a Batch file to rename from a DOS Console
  • Make a Batch file for UNDO operation from a DOS Console
  • Save and Load your options into an INI File
  • Filter by any masks: .mp3;.mp2 or ???a*.txt...
  • Replace a substring by other with Matchcase Optional
  • Replace a substring by other with Matchcase Optional in Extension

alt text

harrymc

Posted 2009-10-01T18:37:28.407

Reputation: 306 093

When I click rename, it says "The system cannot find the file specified." – tputkonen – 2009-10-02T16:05:06.740

I just tried it without any problem. You should select all the files to rename and do it in 2 steps: (1) Replace the text [space] with this new text [_] then Rename (2) Same for ; to - – harrymc – 2009-10-02T20:24:57.103

The issue may be that the file was copied from OSX. Please see the comments to original question. – tputkonen – 2009-10-04T07:39:14.840

Lupas Rename has an action called Remove accents. Maybe this will normalize the file names a bit. If not, File Boss is another renamer with 30-days trial : http://www.theutilityfactory.com/summaries/rename-files-advanced-formatting.htm.

– harrymc – 2009-10-04T15:35:27.403

0

Use a Linux live CD to get to the folder with said files and then:

rename -v 's/\:|\*|\?|\"//g' "{}" \; *.mov

This will remove most of what Windows didn't want. E.g.

2004-01-02_23:58:22.mpg

will become:

2004-01-02_235822.mpg

user36263

Posted 2009-10-01T18:37:28.407

Reputation:

0

Total commander includes a batch renaming tool named Multi-Rename Tool (default shortcut is Ctrl+M).

In your case you can rename the files by running process twice, once to replace space and once to replace semicolon.

Other way is to use rename mask - select range before space, add underscore, then range after the space, while replacing semi colon with dash using Search and replace.

T. Kaltnekar

Posted 2009-10-01T18:37:28.407

Reputation: 7 636

0

Myself, I like @~quack's answer. +1.

But, for posterity, here's what I was going to post.

I've been using StExBar in Stefan's Tools for a good while now. It adds a toolbar to the Windows Explorer with several handy functions.

http://tools.tortoisesvn.net/

(He has several tools, but this specific one is StExBar)

You can accomplish your requested rename with two simple commands. Here's a screenshot of the first, which shows you a preview of the files being renamed, and what they will be renamed.

enter image description here

JMD

Posted 2009-10-01T18:37:28.407

Reputation: 4 427

0

Similar to a couiple of the other solutions, Bulk Rename Utility is a utility that'll do the job. I find it very useful and easy to use for my bulk file re-naming needs.

Bonus

Posted 2009-10-01T18:37:28.407

Reputation: 1 192

It doesn't work for me. As you can see from the "new name" column, it doesn't replace ; with _:

http://i37.tinypic.com/vqjhqq.jpg

If I click rename, it says the file didn't require name change.

– tputkonen – 2009-10-02T16:10:37.617

Tested ok for me (under Win 7 64bit), admittedly with a text file I just renamed to same-as your filename rather than an actual mov file created under OSX. – Bonus – 2009-10-03T11:30:21.737

0

What are the permissions on the file? Are you sure you have permission to rename them? If not, take ownership of the files and try again.

MDMarra

Posted 2009-10-01T18:37:28.407

Reputation: 19 580

good thought, and something to check on the "check simple stuff first" principle, but he mentioned this error from one of the tools: "The system cannot find the file specified." i'd expect permissions problems to give a different error. – quack quixote – 2009-10-04T12:29:49.657

There is no issue with the permissions. Thanks for bringing this up though as I forgot to mention it. – tputkonen – 2009-10-04T13:50:59.837

0

Under the assumption that the file-names contain weird and invisible characters, the way to proceed is to use DOS names of the old 8.3 format. To find out these names use the -x parameter:

image

Now use the short name to rename the file:

ren CLIP-2~1.MOV "clip-2009-10-01_21_26_00.mov"

If you use copy-paste to rename the file, be careful not to propagate the weird characters, so don't leave blank characters in the new name (because they might not really be blank).

harrymc

Posted 2009-10-01T18:37:28.407

Reputation: 306 093

Thanks, this seems to work. However, I have to come up with a script as it's possible to rename them manually also in Explorer. – tputkonen – 2009-10-04T17:59:36.647

0

Interesting problem.

You can write your own custom script. Here is one script that will work. It will REPLACE ALL COLONS, SEMICOLONS, SPACES WITH UNDERSCORE. I will assume the files are in E:/ and the names follow the pattern of clip*.mov. You can change this values in the script to your correct values. You can customize the script even further, if you wish.

# Script Mac2WindowsFileTransfer.txt
# Go to directory where files are stored.
cd "E:/"                                     ### CHANGE THIS TO YOUR CORRECT VALUE. ###
# Get a list of clip*.mov files.
var str list ; lf -rng "clip*.mov" > $list   ### CHANGE THIS TO YOUR CORRECT VALUE. ###
# Go thru files one by one.
while ($list <> "")
do
    # Get the next file.
    var str file
    lex "1" $list > $file
    # Create the new name.
    var str newname
    stex -p "^/^l[" $file > $newname
    # REPLACE ALL COLONS, SEMICOLONS,  SPACES WITH UNDERSCORE.
    while ( { sen -r "^(\:\; )^" $newname } > 0 )
        sal -r "^(\:\; )^" "_" $newname
    # Rename file.
    system rename ("\""+$file+"\"") $newname
done

Save the script as C:/Scripts/Mac2WindowsFileTransfer.txt. The script is in biterscripting ( http://www.biterscripting.com ). You can download biterscripting free. Run the by typing the following command in biterscripting.

script "C:/Scripts/Mac2WindowsFileTransfer.txt"

Patrick

PatrickMc

Posted 2009-10-01T18:37:28.407

Reputation: