![](/img/trans.png)
[英]How to delete one file from a folder, if two files with the same name and different ending exist in the same folder?
[英]Finding one file without extension from other files with same name but different file type
如果你所做的只是移動到另一個文件夾,我會推薦bash,因為它是一個如此簡單的操作
#!/bin/bash
mv report.pdf /path/to/new/folder
我同意AllenMoh對bash的回答。 由於OP也詢問了Python,這里是Python解決方案。
import shutil
import os
src = '/path/report.pdf'
dst = '/new_path/'
shutil.move(src, dst)
# alternative, if destination is on current file system, you can use rename
# notice here the filename is specified
dst = '/new_path/report.pdf'
os.rename(src, dst)
您可以使用Python-Magic庫幫助來查找文件類型。
讀取循環中的所有magic.from_file("filename")
並將其傳遞給magic.from_file("filename")
並檢查輸出以查看它是否為pdf。 如果是pdf,則將其移至目標目錄。
此api不依賴於文件擴展名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.