[英]find a file with specific extension type then execute linux commands using Python
我想使用 Python3 備份一個.tar
文件,這個.tar
將由另一個程序自動生成。 我要啟動備份腳本,它必須首先檢查*.tar
是否存在,然后我將執行其他命令,如cp
或mv
import os
from os import walk
path = '/path/to/directory' # the directory path that you want to search in
dir_path, dir_names, file_names = next(walk(path)) # You need file_names
for file_name in filenames:
if '.tar' in file_name: # or if os.path.splitext(path)[-1] == '.tar'
<your backup process codes>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.