简体   繁体   English

尝试使用Applescript重命名文件夹中的文件

[英]Trying to rename files within folders using Applescript

I'm new to Applescripts but i used VB.net alot in the past and could do this easily with VB.net, however i am restricted to using Applescript at the moment as i dont have access to vb.net. 我是Applescripts的新手,但过去我经常使用VB.net,并且可以通过VB.net轻松完成此操作,但是由于我无权访问vb.net,因此目前仅限使用Applescript。

We handle a lot of images at the auctioneers where i work and need to rename all these images inside their folders to allow us to mass upload the images. 我们在我工作的拍卖商处处理大量图像,因此需要重命名文件夹中的所有这些图像,以使我们能够批量上传图像。

So we have folders from 1 to around 600 called "1" to "600", which would represent Lot 1 or Lot 600 in the sale, inside these folders we have about 7 .jpg images of that lot, with the main image being called "Main.jpg" (this is renamed to "Main" manually as i edit the image on photoshop as only the main image needs editing) 因此,我们有1到600个左右的文件夹,分别称为“ 1”至“ 600”,代表着拍卖品中的Lot 1或Lot600。在这些文件夹中,我们有大约7个该批次的.jpg图像,主要图像称为“ Main.jpg”(当我在photoshop上编辑图像时,由于仅需要编辑主图像,因此手动将其重命名为“ Main”)

The goal of this coding venture is to have all the contents of all the folders from 1 to 600 with the "Main.jpg" file being renamed to the lot number, i'll show an example of what i mean below: 此编码事业的目标是将所有文件夹的所有内容从1到600,并将“ Main.jpg”文件重命名为批号,下面将举例说明我的意思:

Old contents in folder "1": 文件夹“ 1”中的旧内容:

img_001.jpg, img_002.jpg, img_003.jpg, Main.jpg img_001.jpg,img_002.jpg,img_003.jpg,Main.jpg

New Contents in folder "1": 文件夹“ 1”中的新内容:

1_1.jpg, 1_2.jpg, 1_3.jpg, 1.jpg 1_1.jpg,1_2.jpg,1_3.jpg,1.jpg

as this may be really simple for 1 to 10 folders trying to do this with 900 folders in the past has taken me 3 days using the manual rename right-click function on mac and i want to make a program which will allow me to automate this process, saving me a lot of time. 因为这对于1到10个文件夹来说可能真的很简单,过去尝试使用900个文件夹来完成此操作已经花费了我3天的时间,所以我在Mac上使用了手动重命名右键单击功能,并且我想制作一个程序,使我可以自动执行此操作过程,为我节省了很多时间。

Any help will me massively appreciated 任何帮助我都会非常感激

Haydon 海顿

Pretty straight forward as Pat said. 就像Pat所说的那样非常直接。 Here is just some entry points: First ask user to select the parent folder which contains all your folders : 这里只是一些入口点:首先要求用户选择包含所有文件夹的父文件夹:

set ParentF to choose folder "select your parent folder"
tell application "Finder" to set myFolders to every folder of ParentF

myFolders contains a list of all sub folders {"1", "2",...}. myFolders包含所有子文件夹{“ 1”,“ 2”,...}的列表。 You need to loop through each folder of that list (search for "repeat" loops). 您需要遍历该列表的每个文件夹(搜索“重复”循环)。 for each folder, use again similar syntax to get all files in the folder : 对于每个文件夹,再次使用类似的语法来获取文件夹中的所有文件:

tell application "Finder" to set myFiles to every item of AFolder whose name extension is "jpg"

Then again, loop through each file to change its name property. 然后再次遍历每个文件以更改其name属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM