美文网首页
python os,shutil,subprocess,glob

python os,shutil,subprocess,glob

作者: 书案 | 来源:发表于2019-01-09 10:37 被阅读0次
    • os
    import os
    # Directory移動
    os.chdir("usr/dir")
    # 現在のDirectoryをチェック
    os.getcwd()
    # list up the contents
    os.listdir("usr/dir")
    
    # "mydir"のpathはDirectory/fileであるかどうかをチェック
    os.path.isdir("mydir")
    os.path.isfile("mydir")
    # "mydir"のpathはDirectory/fileであるかどうかを問わず、存在をチェック
    os.path.exists("mydir")
    
    # directory or file改名 rename
    os.rename(old_name, new_name)
    # make a new dir
    os.mkdir(dir_name)
    # ディレクトリ(フォルダ)の階層を作成する(すでにパスの途中までディレクトリ(フォルダ)が存在する場合は、残りのディレクトリ(フォルダ)を作成します)
    os.makedirs(parent/child)
    
    • shutil
    import shutil
    # directoryをまるごとコピー
    shutil.copytree("orignal_dir", "target_dir")
    # copy a file
    shutil.copyfile(orignal_file, rename_file)
    # delete a directory
    shutil.rmtree()
    shutil.move(old_dir, new_dir)
    
    • subprocess
    import subprocess
    subprocess.run("dcm2nii -options", shell=True)
    
    • glob
    import glob
    # list up the files including "keyword"
    glob.glob("*keyword*")
    glob.glob("*keyword*")[0]
    

    相关文章

      网友评论

          本文标题:python os,shutil,subprocess,glob

          本文链接:https://www.haomeiwen.com/subject/bojwrqtx.html