2 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
像這樣使用簡(jiǎn)單的 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 當(dāng)輸出看起來不錯(cuò)時(shí)刪除命令。

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
假設(shè)您的所有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}')
更新:
假設(shè)您的所有Species_name.asc文件都像您的示例中那樣標(biāo)記:
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}')
添加回答
舉報(bào)