寻找 Applescript 来查找文件并将它们移动到不同的文件夹 [英] Looking for an Applescript to find files and move them to different folder

查看:53
本文介绍了寻找 Applescript 来查找文件并将它们移动到不同的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试寻找一个脚本来查找文件并将其移动到不同的文件夹.

I'm trying to find a script to find and move files to a different folder.

我有一个文件夹,里面有数百张这样的图片:

I've got a folder with hundreds pictures like this:

PA-600-01.jpg, PA-600-02.jpg, PA-600-03.jpg, PA-600-04.jpg, PA-601-01.jpg, PA-601-02.jpg, PA-601-03.jpg, PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg, PA-602-05.jpg

我想用 PA-600 移动所有图片(所以 PA-600-01.jpg、PA-600-02.jpg、PA-600-03.jpg 和PA-600-04.jpg) 在一个名为 PA-600 的文件夹(新的或已有的,更容易...)上,用 PA-601 移动所有图片(PA-601-01.jpg、PA-601-02.jpg 和 PA-601-03.jpg)在名为 PA-601 的文件夹中, 用PA-602(PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg, PA-602-04.jpg, PA-602-03.jpg.jpg 和 PA-602-05.jpg) 位于名为 PA-602... 的文件夹中,直到 PA-699

I want to move all the pictures with PA-600 (so PA-600-01.jpg, PA-600-02.jpg, PA-600-03.jpg and PA-600-04.jpg) on a folder (new or already existing, the easier...) named PA-600, move all the pictures with PA-601 (PA-601-01.jpg, PA-601-02.jpg and PA-601-03.jpg) on a folder named PA-601, move all the pictures with PA-602 (PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg and PA-602-05.jpg) on a folder named PA-602... until PA-699

我试图移动一个文件而不是一组文件:

I tried to move a file but not a group of files:

tell application "Finder" make new folder at alias "Macintosh HD:Users:AirYoSo:Desktop:600-699" with properties {name:"PA-600"} copy file "Macintosh HD:Users:AirYoSo:Desktop:600-699:PA-600-01.jpg" to folder "Macintosh HD:Users:AirYoSo:Desktop:600-699:PA-600" end tell

推荐答案

不知道如何在 applescript 中做到这一点,但在 bash 中做到这一点非常简单,您已经在 Mac 上安装了它:

No idea how to do it in applescript, but this is quite trivial to do in bash, which you have installed on your Mac:

#!/bin/bash
for (( c=600; c<=699; c++ ))
do
  echo "Processing PA-$c"
  mkdir -p PA-$c
  mv PA-$c-*.jpg PA-$c/
done

将其保存到一个文件中,例如 script.sh,将文件复制到您的 jpg 文件所在的目录中,然后像这样在终端中运行它(将/Users/lionel/files 替换为文件的真实路径):

Save this to a file, for example script.sh, copy the file to the directory with your jpg files, and run it like this, in Terminal (replace /Users/lionel/files with the real path to your files):

$ cd /Users/lionel/files 
$ bash script.sh

这篇关于寻找 Applescript 来查找文件并将它们移动到不同的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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