簡體   English   中英

如何使用 Python 腳本將某些類型的文件移動到其他目錄

[英]How to move certain types of files to other directory with a Python script

我的代碼是:

subprocess.call(["mv", "*.fasta", f"{my_model_dir}/."])

我得到的錯誤代碼是:

mv: cannot stat '*.fasta': No such file or directory

我嘗試將所有 fasta 文件移動到其他目錄,但是,我收到一條錯誤消息。

我認為這是因為 '*' 在 Python 中用作正則表達式,所以在這種情況下它不起作用。 要將帶有 Python 腳本的文件移動到其他目錄,我該怎么辦?

嘗試subprocess.call(["mv", "\*.fasta", f"{my_model_dir}/."])

您可以使用osshutil庫:( 如何在 Python 中移動文件?
對於同類型的文件,可以用os循環瀏覽,然后一個一個移動。
os參考:( https://www.geeksforgeeks.org/os-module-python-examples/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM