0

谁能告诉我如何使用字符串“@2x”在特定文件夹中附加文件名。我不想麻烦手动重命名每个文件。谢谢。

4

3 回答 3

3

启动 AppleScript Editor 并粘贴以下脚本:

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 回答