作者:叶子1209 | 来源:互联网 | 2023-12-10 12:41
I have a work folder directory.
我有一个工作文件夹目录。
holder = Dir.glob("*")
=> holder = ["Project One", "Project Two", "Project Three", "Backups", "Summer 2012"]
I would like to use regex in my script to sort a new file that is in another directory into one of the Project directories above. I can easily do this using a regex.match
command like.
我想在我的脚本中使用正则表达式将另一个目录中的新文件排序到上面的一个Project目录中。我可以使用regex.match命令轻松完成此操作。
other_files = ["Project One Picture 2399.jpg", "Project Two Doc.txt"]
if /project\Done/i.match(other_files[0])
#if true cp to Project One directory i think you get the point
I would like to create regex expression from the holder
array. So all i need to do is create another folder and the script will add another regex in the array. Is there an easy way to do this? Or is there a way to store regex in an array?
我想从holder数组创建regex表达式。所以我需要做的就是创建另一个文件夹,脚本将在数组中添加另一个正则表达式。是否有捷径可寻?或者有没有办法在阵列中存储正则表达式?
regex_array = ["/project\Done/i", "/project\Dtwo/i", "/project\Dthree/i", "/backups/i", "/summer\W\d\d\d\d/i"]
2 个解决方案