2 回答
TA贡献1862条经验 获得超6个赞
像这样使用简单的 shell 工具狂欢:
find . -type f -name '*Species_name*' -exec bash -c '
dir=$(grep -oP "Species_name\d+" <<< "$1")
echo mkdir "$dir"
echo mv "$1" "$dir"
' -- {} \;
echo 当输出看起来不错时删除命令。
TA贡献1829条经验 获得超7个赞
假设您的所有asc文件都像示例中那样命名:
from os import mkdir
from shutil import move
from glob import glob
fs = []
for file in glob("*.asc"):
f = file.split('.')[0]
fs.append(f)
mkdir(f)
for f in fs:
for file in glob("*.*"):
if file.startswith(f):
move(file, f'.\\{f}\\{file}')
更新:
假设您的所有Species_name.asc文件都像您的示例中那样标记:
from os import mkdir
from shutil import move
from glob import glob
fs = [file.split('.')[0] for file in glob("Species_name*.asc")]
for f in fs:
mkdir(f)
for file in glob("*.*"):
if file.startswith(f):
move(file, f'.\\{f}\\{file}')
添加回答
举报