1

在将图像文件添加到文件夹时,我需要按顺序重命名它们。IE。image-0001.jpg 和 image-0002.jpg 位于我添加 test.jpg 的文件夹中,并将其重命名为 image-0003.jpg。我已经尝试过自动重命名功能,但每次添加新文件时它都会从 image-0001.jpg 重新开始,而不是继续序列。

任何帮助是极大的赞赏。

4

2 回答 2

2

You could make this easy on yourself by using a handy application built into the OS called "Folder Actions". Folder Actions contains one or more special handlers, formally known as folder action event handlers, that run when they are triggered by a change in the target folder. I know I'm confusing but I'll do my best.

What you are trying to accomplish requires an adding folder items to event handler. It requires one direct parameter, which can be anything you wish i.e. target_folder. The handler requires an additional parameter as well; after receiving, which should also be a variable name, i.e. these_items. I have composed a script for you that should do the trick. I have added comments that show you what I'm doing when I do it. Here it is:

on adding folder items to the target_folder after receiving these_items
    tell application "Finder"
       set all_images to every item of the target_folder as list
       repeat with i from 1 to the count of these_items --iterates through all the items you dropped in the folder
          set this_image to item i of these_items --the current image
          set the name of this_image to "image" & (i + the count of all_images) as string --renames the image based on the number of images already in the folder
       end repeat
    end tell
end adding folder items to

YAY! The script is done! But are WE done? Not quite. We still need to attach the script to a folder (the script won't run if you try to execute it in script editor).

To do this, first save the script as a Script File in the Folder Action Scripts folder in the Scripts folder in either the local Library folder or the current user's Library folder. Create the folder yourself if it doesn't already exist. Next, launch the Folder Actions Setup application by double-clicking it in the AppleScript folder in the Applications folder. In the window that comes up, click the + button under the table on the left (click the "Enable Folder Actions" checkbox if it isn't already checked) to open a standard file browser sheet, navigate to your desired folder, and click "Open". The Choose a Script to Attach sheet automatically opens, listing all the scripts in all of the Folder Action Script folders. Choose the newly-created script, click "Attach", and BAM you are done!

To see the script in action, drag an image onto the folder. The image is instantly renamed, regardless of if the folder window is open. If you have any questions, or if the script doesn't work, just ask me. :)

于 2011-07-04T20:27:41.103 回答
0

好吧,不用挖掘一些代码并交给你一个答案我会告诉你想要你想做的事

是创建一个 while 循环来检查 image-000 & i 的存在,其中 i 当然是一个变量,如果它存在则增加 i 然后当文件不存在时重命名你的文件。

于 2011-04-15T13:54:33.953 回答