0

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

我有一个包含数百张这样的图片的文件夹:

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( so PA-600-01.jpg, PA-600-02.jpg, PA-600-03.jpg and PA-600-04.jpg)的PA-600图片移到一个名为... 直到PA-601PA-601-01.jpg, PA-601-02.jpg and PA-601-03.jpgPA-601PA-602PA-602-01.jpg, PA-602-02.jpg, PA-602-03.jpg, PA-602-04.jpg and PA-602-05.jpgPA-602PA-699

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

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
4

2 回答 2

1

尝试:

set myFolder to (choose folder)
set pFolder to POSIX path of myFolder
set folderNames to paragraphs of (do shell script "find " & quoted form of pFolder & " \\! -name \".*\" -type f -print0 | xargs -0 ls -t | grep -Eo PA-[0-9]{3} | uniq")

repeat with aFolder in folderNames
    (do shell script "mkdir -p " & quoted form of (pFolder & aFolder))
    tell application "System Events" to move (every file of myFolder whose name begins with aFolder) to (pFolder & aFolder)
end repeat

编辑如果你想硬连线到你可以使用的文件夹的路径:

set myFolder to "Macintosh HD:Users:YoSo:Desktop:test"
set pFolder to myFolder's POSIX path & "/"
set folderNames to paragraphs of (do shell script "find " & quoted form of pFolder & " \\! -name \".*\" -type f -print0 | xargs -0 ls -t | grep -Eo PA-[0-9]{3} | uniq")

repeat with aFolder in folderNames
    (do shell script "mkdir -p " & quoted form of (pFolder & aFolder))
    tell application "System Events" to move (every file of folder myFolder whose name begins with aFolder) to (pFolder & aFolder)
end repeat
于 2013-02-25T23:50:17.133 回答
0

不知道如何在 applescript 中执行此操作,但在您已安装在 Mac 上的 bash 中执行此操作非常简单:

#!/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 替换为文件的真实路径):

$ cd /Users/lionel/files 
$ bash script.sh
于 2013-02-25T21:46:28.153 回答