我正在尝试批量重命名操作系统上同一文件夹中的许多文件。
我有一个包含两个变量的数据集:oldname
和newname
.
数据集中有更多的文件名,然后是需要重命名的实际文件,所以我想构建一些与数据集中的观察匹配的文件,重命名匹配的文件,然后将其移动到新位置。
例如,我在一个位置有三个文件:
filepath/to/my/files/file1.jpg
filepath/to/my/files/file2.jpg
filepath/to/my/files/file3.jpg
具有字符串变量的数据集:
Dataset
newname oldname
a pink files/file1.jpg
b blue files/file4.jpg
c purple files/file6.jpg
d green files/file3.jpg
e red files/file2.jpg
这是程序所需的输出:
filepath/for/matches/pink.jpg
filepath/for/matches/red.jpg
filepath/for/matches/green.jpg
我需要使用!
运算符来实现我想要的吗?
编辑:
到目前为止,我有一种移动比赛的方法,但不能重命名它们:
global dir "/filepath"
global old "$dir/to/my/"
global new "$dir/for/matches"
ssc install mvfiles
preserve
keep if oldname!=.
foreach i in oldname{
mvfiles, infolder($old) outfolder($new) match(substr(`i',6,9))
}
restore