iCloud Drive on MacOS - files without extensions don't open

0

Trying to help my father-in-law with a weird one: all of a sudden a large percentage (maybe 20%) of his iCloud Drive docs on his very new MacBook Pro will not open. I've looked at it and the problematic files appear to be files that do not have file extensions. They show as 'Unix executable' files rather than .doc files.

If I go in and add the .doc as a file extension, the file immediately downloads and will open properly.

Anybody ever seen this before? Is there any solution other than actually having to manually rename hundreds of files, one at a time?

dvanhook

Posted 2018-04-09T01:05:03.303

Reputation: 3

Answers

0

In Mac OS 9 and earlier, the only way for a Mac to know what type of file you had was through file "Type" and "Creator" Codes. With OS X, it switched to extensions, but those codes were still there (possibly could override the settings in the beginning, but now I think they're a "backup" way to identify files).

I just took a DOC file (with a .doc extension), renamed it to "Foo" (no extension), and the Finder recognized it. Using the xattr command, I was able to see that the codes from the original file were copied to the new file, so Finder on my first Mac could open.

Checking Finder on another Mac (synced thru iCloud) and the "Foo" file is a UNIX file. So, iCloud is NOT syncing the extended attributes from the source. Without an extension, you'd have to re-apply the codes on the destination side, or just add the extension.

With any luck, you've kept Word, Excel, etc, files in separate folders, and can rename in batch (see below). If not, you can run the file command on each file to see what it is, then rename manually.

To batch rename files, I think there are tons of tools to do it, or you can use this Perl script to do it. I wrote it years ago, and it's lame, but it works for everything I've thrown at it.

#!/usr/bin/perl

use strict;
use File::Copy;

if (scalar(@ARGV) < 2) {
  print "\nUSAGE: $0 <extension> <file(s)>\n\n";
  exit 1;
}

my $ext = shift;
# Strip off leading period, since we'll add it later.
$ext =~ s/^\.//;

# Everytime I pass this script's @ARGV back out to a system call
# the whole argument arrary gets treated like a long string.
# If any individual $ARGV had spaces in it, that $ARGV ends up
# looking like multiple args to the system call.
# So, parse each $ARGV one at a time, in double-quotes.
foreach my $arg (@ARGV) {
  if ($arg =~ m/\./) {
    # This $arg already has an extension!
    if ($arg =~ m/\.$ext$/) {
      # This $arg already has this $ext.  Skip it.
      warn "WARNING!  $arg already has that extension.\n";
      next;
    }
    else {
      # This $arg has an extension, but it's not the same as $ext.
      warn "WARNING!  $arg already had an extension.\n";
    }
  }
  renameFile("\$", ".$ext", $arg);
}

sub renameFile {
  my $searchString = shift;
  my $replacementString = shift;
  my $file = shift;

  if (-e "$file") {
    my $newName = $file;
    if ($newName =~ s/$searchString/$replacementString/ge) {
      if (-e "$newName") {
        print "ERROR!  Unable to move '$file' to '$newName' because\n";
        print "        a file named '$newName' already exists!\n";
      }
      else {
        print "Moving '$file' to '$newName'.\n";
        move("$file", "$newName") || die "Unable to rename '$file'.\nStopped";
      }
    }
  }
  else {
    print "File '$file' does not exist.\n";
  }
}

jimtut

Posted 2018-04-09T01:05:03.303

Reputation: 832

Wow, that's great -- great detective work. Thanks for the script, too. My father-in-law called Apple support, and as it turns out they re-downloaded everything and the data came back down with most of the files from iCloud. Not sure why it wasn't there to begin with, but that's a question for Tim C, I guess. Marking this as a complete answer, though, as this script is sweet. – dvanhook – 2018-04-10T18:57:15.070