与附加文件夹名的文件名[不明白] [英] Append filenames with folder name [dont understand]

查看:204
本文介绍了与附加文件夹名的文件名[不明白]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林努力理解如何重命名(附加)文件名与文件夹名称的文件夹中。
例如,about.txt,picture.jpg等成为FOLDERNAME-about.txt,FOLDERNAME画面等。
IM在AppleScript的一个完整的小白,这是我的第一个脚本永远!

 上运行{输入参数}告诉应用程序发现者
设置theFolder到文件夹OS X:用户:大卫:桌面:SCRIPT:脚本复制
设置targetFolder到文件夹OS X:用户:大卫:桌面:SCRIPT:脚本复制完毕对话框显示您希望哪位结构复制?按钮{结构 - MAIN,结构 - 其他}
设置chosenStructure到按钮返回结果的如果chosenStructure的内容等于结构-MAIN,然后
    设置chosenStructure为OS X:用户:大卫:桌面:SCRIPT:脚本的副本: - 主
其他
    设置chosenStructure为OS X:用户:大卫:桌面:SCRIPT:脚本的副本: - 其它
万一显示对话框指定一个新的文件夹名称:默认回答约翰·狗
设置了newName为(结果返回的文本)
设置createNewStructure作出新的文件夹在targetFolder具有属性{名}了newName
复制文件夹chosenStructure来createNewStructure全部内容的每个文件
设置the_folder到文件夹chosenStructure的名称
与this_file重复(获得的文件夹chosenStructure的全部内容的文件)    设置the_start为偏移_在((this_file的名称)作为字符串)
    设置the_stop计数(的this_file作为字符串名称)
    设置this_file名(the_folder及(项目the_start直通the_stop的this_file作为字符串(名))的)
重复结束告诉结束
返回输入
运行结束

感谢您的帮助!


解决方案

  

我想要的文件夹内的所有文件名具有文件夹名称
  prepended在文件名的开头。例如,about.txt成为
  FOLDERNAME-about.txt等。


试试这个:

 告诉应用程序发现者
    ...
    设置the_folder为createNewStructure的名字
    与this_file重复(获得createNewStructure的全部内容的文件)
        设置this_file名the_folder&安培; - 与& (this_file的名称)
    重复结束
告诉结束

整个脚本:

 设置为theFolder((路径为桌面)文本)及SCRIPT:脚本复制
设置targetFolder为((路径为桌面)文本)及SCRIPT:脚本复制完毕对话框显示您希望哪位结构复制?按钮{ - 主, - 其它}
设置chosenStructure为((路径为桌面)文本)及SCRIPT:脚本的副本:&放大器;按钮返回结果的显示对话框指定一个新的文件夹名称:默认回答约翰·狗
设置了newName为(结果返回的文本)告诉应用程序发现者
    设置createNewStructure作出新的文件夹在targetFolder具有属性{名}了newName
    复制文件夹chosenStructure来createNewStructure全部内容的每个文件    设置the_folder为createNewStructure的名字
    与this_file重复(获得createNewStructure的全部内容的文件)
        设置this_file名the_folder&安培; - 与& (this_file的名称)
    重复结束
告诉结束

Im struggling to understand how to rename(append) filenames inside a folder with the folders name. Eg, about.txt, picture.jpg, etc to become folderName-about.txt, folderName-picture, etc. Im a complete noob at applescript, this is my first script ever!

on run {input, parameters}

tell application "Finder"
set theFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy"
set targetFolder to folder "OS X:Users:David:Desktop:SCRIPT:script-copy-finished"

display dialog "Which structure do you wish to duplicate?" buttons {"Structure-MAIN", "Structure-OTHER"}
set chosenStructure to button returned of result

if contents of chosenStructure is equal to "Structure-MAIN" then
    set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-MAIN"
else
    set chosenStructure to "OS X:Users:David:Desktop:SCRIPT:script-copy:-OTHER"
end if

display dialog "Specify a new folder name:" default answer "John The Dog"
set newName to (text returned of result)
set createNewStructure to make new folder at targetFolder with properties {name:newName}
duplicate every file of entire contents of folder chosenStructure to createNewStructure






set the_folder to name of folder chosenStructure
repeat with this_file in (get files of entire contents of folder chosenStructure)

    set the_start to offset of "_" in ((name of this_file) as string)
    set the_stop to count (name of this_file as string)
    set name of this_file to (the_folder & (items the_start thru the_stop of (name of this_file as string)))
end repeat

end tell


return input
end run

Thanks for your help!

解决方案

I want all filenames inside the folder to have the folders name prepended at the beginning of the filename. Eg, about.txt to become folderName-about.txt, etc.

Try this:

tell application "Finder"
    ...
    set the_folder to name of createNewStructure
    repeat with this_file in (get files of entire contents of createNewStructure)
        set name of this_file to the_folder & "-" & (name of this_file)
    end repeat
end tell

The whole Script:

set theFolder to ((path to desktop) as text) & "SCRIPT:script-copy"
set targetFolder to ((path to desktop) as text) & "SCRIPT:script-copy-finished"

display dialog "Which structure do you wish to duplicate?" buttons {"-MAIN", "-OTHER"}
set chosenStructure to ((path to desktop) as text) & "SCRIPT:script-copy:" & button returned of result

display dialog "Specify a new folder name:" default answer "John The Dog"
set newName to (text returned of result)

tell application "Finder"
    set createNewStructure to make new folder at targetFolder with properties {name:newName}
    duplicate every file of entire contents of folder chosenStructure to createNewStructure

    set the_folder to name of createNewStructure
    repeat with this_file in (get files of entire contents of createNewStructure)
        set name of this_file to the_folder & "-" & (name of this_file)
    end repeat
end tell

这篇关于与附加文件夹名的文件名[不明白]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆