我正在寻找一种方法来浏览数千个文件名列表,在服务器上的某组子文件夹中搜索它们,并导出这些文件位置的列表。
实施例: 保存在Textedit或Excel中我有:
12345.psd
67890.psd
这些需要在这里搜索:
Servername:图像库:摄影:
然后,我需要一个导出到TextEdit或Excel中的这些文件的位置列表,以获得如下列表:
Servername:Image Bank:摄影:主题名称:12345.psd
Servername:图像库:摄影:主题名称:67890.psd
手动搜索单个文件已经过了一段时间。我是Automator和Applescript的新手,所以我正在学习。到目前为止,我已经搜索了论坛和教程,与朋友,同事和IT人员进行了讨论,花了几个小时进行测试和试验,没有成功。
这至少听起来有可能吗?如果是这样,我将继续尝试,因为这在未来的项目中将是非常宝贵的。
答案 0 :(得分:0)
作为一个例子和测试...
我在' Servername:Image Bank:Photography'包含三个主题名称'它们之间的文件夹包含90,000个.psd文件(每个文件中有30,000个文件'主题名称'文件夹)。
然后我创建了一个包含3,100个.psd文件名的列表。此列表仅包含文件名和.psd扩展名,文件名分布在为此测试创建的90,000 .psd文件的名称上,以便必要时必须逐步读取整个主列表,以便获取完全限定的路径文件名。
然后我在终端中编写了这个bash
脚本:
touch getpfn
nano getpfn
在nano
中,我输入了以下内容:
#!/bin/bash
master_list="The_PSD_Path_Filenames_List_on_Servername_at_Image_Bank_Photography.txt"
get_list="The_Get_Path_Filenames_List.txt"
the_list="The_Wanted_Path_Filenames_List.txt"
psd_file_path='/Volumes/Image Bank/Photography'
find "$psd_file_path" -type f -iname '*.psd' > "$master_list"
while read -r line; do
grep -m 1 "$line" "$master_list" >> "$the_list"
done<"$get_list"
通过按以下键序列保存更改并退出nano
:
Control X
Y
输入
返回终端:
制作脚本可执行文件:
chmod u+x getpfn
执行脚本:
./getpfn
在我的系统上,花了不到六分钟就在服务器上获得了3,100个完全限定的PSD文件路径文件名,而不是90,000个条目。可以理解的是,YMWV基于所有相关因素!
我在下面添加了此bash
脚本的评论版本:
#!/bin/bash
# Define Variables
# These filenames are arbitrary but should adequately
# differentiate their functionality within this script.
# Set them to whatever is appropriate for your usage.
# 'master_list' gets created by the output of the 'find'
# command. It will contain the fully qualified path filenames
# of all PSD files within Servername:Image Bank:Photography
# mounted at '/Volumes/Image Bank' using: 'psd_file_path'
master_list="The_PSD_Path_Filenames_List_on_Servername_at_Image_Bank_Photography.txt"
# 'get_list' Is a plain text file created from the spreadsheet.
# It contains one filename, e.g. 12345.psd, per line. Filenames
# can be numeric and or alphanumeric, doesn't matter as long as
# there is only one filename per line and is a plain text file.
get_list="The_Get_Path_Filenames_List.txt"
# 'the_list' gets created by the output of the 'grep' command.
# Each line of 'master_list' that contains the filename on
# the processed line of the 'get_list' is written to 'the_list'
# 'the_list' then contains the fully qualified pathnames
# of the filenames in 'get_list' based on 'psd_file_path'.
the_list="The_Wanted_Path_Filenames_List.txt"
# Note: This script assumes that 'Image Bank' is the mounted share
# of 'Servername' and is accessible at: '/Volumes/Image Bank'
psd_file_path='/Volumes/Image Bank/Photography'
# Create the Master PSD Path Filename List
find "$psd_file_path" -type f -iname '*.psd' > "$master_list"
# Loop through the e.g. 'Get_Path_Filenames_List.txt' against the e.g.
# 'The_PSD_Path_Filenames_List_on_Servername_at_Image_Bank_Photography.txt'
# while writing matches to e.g: The_Wanted_Path_Filenames_List.txt
while read -r line; do
grep -m 1 "$line" "$master_list" >> "$the_list"
done<"$get_list"
# Now finished, the e.g. 'The_Wanted_Path_Filenames_List.txt' file
# contains the mounted path filenames of all the filenames in
# the e.g. 'Get_Path_Filenames_List.txt' file.
#
# Depending on what will be done with this list, further
# processing can be done as needed and or wanted.