有没有办法将两个列表写入.csv两个列表以在Apple脚本中分开列?
要自动编写立即在.csv du -sh的目录下方的文件/文件夹的文件列表,
这是我要寻找的内容,但所有数据都在写入.CSV时最终出现在一个列中。如果可以逗号划定数据而不是选项卡,那可能会解决问题。
我得到的近距离定义了两个变量:儿童规模和儿童路径。每个都是我想要的数据列表。
我尝试了Echo,printf,现在粘贴了,而没有得到我想要的东西,有点困难。
set RootDirectoryPosix to POSIX path of RootDirectoryAlias
set ChildSizes to do shell script ("du -sh -- " & RootDirectoryPosix & "*" & "| cut -f1")
set ChildPaths to do shell script ("du -sh -- " & RootDirectoryPosix & "*" & "| cut -f2")
set ChildPathsString to ChildPaths as string
set ChildSizesString to ChildSizes as string
tell application "Finder"
do shell script "paste -d ," & ChildSizesString & " " & ChildPathsString & " >~/Test.csv"
end tell
Looking to automate writing the filesizes of files/folders immediately beneath a directory to a .csv
du -sh is the closes to what I'm looking for but all the data ends up in one column when writing to a .csv. If it were possible to comma deliminate the data instead of tab, that might solve the issue.
The closes I've gotten is defining two variables: ChildSizes and ChildPaths. With each being only a list of the data I want.
I've tried echo, printf, and now paste without getting exactly what I want and am a bit stumped.
set RootDirectoryPosix to POSIX path of RootDirectoryAlias
set ChildSizes to do shell script ("du -sh -- " & RootDirectoryPosix & "*" & "| cut -f1")
set ChildPaths to do shell script ("du -sh -- " & RootDirectoryPosix & "*" & "| cut -f2")
set ChildPathsString to ChildPaths as string
set ChildSizesString to ChildSizes as string
tell application "Finder"
do shell script "paste -d ," & ChildSizesString & " " & ChildPathsString & " >~/Test.csv"
end tell
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里,我从用户域中选择root文件夹脚本文件夹。以下脚本在桌面上创建CSV文件。
当我检查时,shell命令创建了用 tabs 界定的文本。脚本只是用“”;定界符。
添加列标题:
Here, I choose for the root folder the Scripts folder from user domain. Following script creates CSV file on the desktop.
As I checked the shell command creates text delimited with TABs. The script simply replaces them with ";" delimiter.
With adding column titles:
这就是我最终得到的:
This is what I ended up with: