義父の奇妙な症状を助けようとしています。突然、彼の新しい MacBook Pro にある iCloud Drive ドキュメントの大部分 (おそらく 20%) が開かなくなりました。調べてみたところ、問題のあるファイルはファイル拡張子のないファイルのようです。それらは .doc ファイルではなく、「Unix 実行可能」ファイルとして表示されます。
ファイル拡張子として .doc を追加すると、ファイルはすぐにダウンロードされ、適切に開きます。
誰かこれを見たことがありますか? 何百ものファイルを 1 つずつ手動で名前変更する以外に、何か解決策はありますか?
答え1
Mac OS 9 以前では、Mac がファイルのタイプを認識する唯一の方法は、ファイルの「タイプ」コードと「作成者」コードを使用することでした。OS X では拡張子に切り替わりましたが、それらのコードはまだ存在していました (最初の設定を上書きできた可能性がありますが、今ではファイルを識別する「バックアップ」の方法だと思います)。
私は DOC ファイル (.doc 拡張子付き) を取得し、それを「Foo」(拡張子なし) に名前変更したところ、Finder がそれを認識しました。コマンドを使用してxattr
、元のファイルのコードが新しいファイルにコピーされ、最初の Mac の Finder で開くことができることを確認できました。
別の Mac (iCloud 経由で同期) の Finder を確認すると、「Foo」ファイルは UNIX ファイルです。つまり、iCloud はソースからの拡張属性を同期していません。拡張機能がない場合、宛先側でコードを再適用するか、拡張機能を追加する必要があります。
運が良ければ、Word、Excel などのファイルを別々のフォルダーに保存して、一括で名前を変更できます (以下を参照)。そうでない場合は、file
各ファイルに対してコマンドを実行して内容を確認し、手動で名前を変更できます。
ファイル名を一括変更するには、それを実行するツールがたくさんあると思いますが、この Perl スクリプトを使用することもできます。これは私が何年も前に書いたもので、ひどいものですが、私が試したすべての処理で機能します。
#!/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";
}
}