0

特定のフォルダに文字列「@2x」を付けてファイル名を追加する方法を教えてもらえますか。すべてのファイルの名前を手動で変更する手間をかけたくありません。ありがとう。

4

3 に答える 3

3

AppleScript エディターを起動し、次のスクリプトを貼り付けます。

set appendable to "@2x"
set theFolder to choose folder
tell application "Finder"
    set theFiles to (files of entire contents of theFolder) as alias list
    repeat with theFile in theFiles
        set FileExtension to theFile's name extension as string
        set FileName to theFile's name as string
        set FileBaseName to text 1 thru ((offset of "." in FileName) - 1) of FileName
        set theFile's name to FileBaseName & appendable & "." & FileExtension
    end repeat
end tell

スクリプトは、選択したフォルダー内のすべてのファイルに「@2x」を追加します。
「実行」ボタンをクリックし、任意のフォルダを選択してスクリプトを実行します。

于 2012-06-21T20:56:16.287 に答える
1

ターミナルから実行できます for f in *; do mv f 'f@2X'; done;

于 2012-06-21T20:16:08.833 に答える
1

コードなしでAutomatorでこれを行うことができます。

または、すでに「Xcode」とObjective-C@2Xを知っているように、名前拡張子の前に追加する例を次に示します。

BOOL result;
NSString *fullPath, *filename, *newName;
NSString *dir = @"/Users/jack/Desktop/Untitled 1";
NSFileManager *fm = [NSFileManager defaultManager];
NSEnumerator *enumerator = [[fm contentsOfDirectoryAtPath:dir error:nil] objectEnumerator];

while(filename=[enumerator nextObject]){
    if ([filename hasPrefix:@"."]) { continue;}//skip files that begin with a dot
    fullPath = [dir stringByAppendingPathComponent:filename];
    if (!([fm fileExistsAtPath:fullPath isDirectory:&result]&&result)) { // skip directory
        if ([[filename pathExtension] isEqualToString:@""]) {
            newName = [fullPath stringByAppendingString:@"@2X"];// no extension
        } else {
            newName = [[fullPath stringByDeletingPathExtension] stringByAppendingFormat:@"@2X.%@",[filename pathExtension]];
        }
        result = [fm moveItemAtPath:fullPath toPath:newName error:nil];
    }
}
于 2012-06-22T00:39:55.430 に答える