![](/img/trans.png)
[英]How to jump from one folder to another folder in python after reading all the files in one folder?
[英]How to take all files from a folder as input (one at a time) and save them into another folder after processing?
我有一個.py
腳本,它一次需要一個.csv
並對其進行預處理。 我正在以這種方式運行 bash 命令:
python3 cleaning_script.py file1.csv results_file1.csv
。 它工作得很好。 一個文件夾中有 300 多個文件需要預處理,有沒有更好的方法(可能是循環,但我不知道如何在這種環境中使用循環),我可以在其中提及該文件夾,並且每個文件是從源文件夾作為輸入,預處理文件保存在目標文件夾中?
由於系統中的非管理權限(Windows 10),我使用 Rstudio 終端來執行我的 bash 命令。
使用 bash,如果沒有大量文件,那么您可以使用 glob:
for file in path/to/dir/*.csv
do
python3 cleaning_script.py "$file" "$(dirname "$file")/result_$(basename "$file")"
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.