【发布时间】:2014-06-05 14:22:03
【问题描述】:
我有这个 bash 脚本,它遍历当前目录中的文件并从 文件名 中提取 日期部分,然后使用 ( Unix)touch 命令将该文件的 modification-date (mtime) 修改(或更新)到该日期。
文件名示例
Electric company name - bill - 2014-03-22.pdf
Bash 脚本:
我将这个 bash 脚本保存为 _save_file_mtime_from_filename.sh(将 chmod +x 添加到其中)并放入我想要更改文件修改时间的目录中。然后从命令行运行它。
#!/bin/bash
CURRENT_DIR=$(dirname $_)
cd $CURRENT_DIR
for f in *
do
# Strip the file extension
d=${f%.*}
# Strip the last 10 characters
d=${d:${#d}-10}
# Check the format / mask
if [[ $d = ????-??-?? ]] ; then
# Strip the dash
d=${d//-}
# Run `touch` on the file with the extracted date format
# and add `0000` to the file date
touch -t ${d}0000 "$f"
fi
done
现在我正在寻找 此脚本的 Windows 版本
我已经搜索了网络(和 Stackoverflow)。发现了一些相关的问题,例如https://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command 和https://superuser.com/questions/251470/windows-recursive-touch-command/251507#251507
有没有人知道Windows 版本 使用_save_file_mtime_from_filename.bat 可执行版本基本上做同样的事情?
在 (Mac) Automator 操作的帮助下,保存为“应用程序”,您甚至可以通过鼠标右键 (https://discussions.apple.com/thread/5287944?start=15&tstart=0) 在 Mac Finder 中触发此脚本。甜蜜!
【问题讨论】:
-
为什么不直接安装 cygwin?
标签: windows bash shell batch-file timestamp