python建立資料夾授權

2021-10-24 05:43:29 字數 904 閱讀 8390

#!/usr/bin/python3

#centos新建資料夾的,並且授權777,www

import os

import time

localtime=time.strftime(』%y-%m-%d %h:%m:%s』,time.localtime(time.time()))

print(os.getcwd())

dir=os.chdir(r』/data/wwwroot』)

print(dir)

print(『localtime=』+localtime)

#列印系統年份

year=time.strftime(』%y年』,time.localtime(time.time()))

print(year)

#列印月份

month=time.strftime(』%m月』,time.localtime(time.time()))

print(month)

#列印日期

day=time.strftime(』%d日』,time.localtime(time.time()))

print(day)

#列印具體時間_時

mdh=time.strftime(』%h時』,time.localtime(time.time()))

print(mdh)

#列印具體時間_分

mdm=time.strftime(』%m分』,time.localtime(time.time()))

print(mdm)

#列印具體時間_秒

mds=time.strftime(』%s秒』,time.localtime(time.time()))

print(mds)

#列印年具體的路徑

fileyear=os.getcwd()

Python 建立資料夾

def mkdir path 引入模組 import os 去除首位空格 path path.strip 去除尾部 符號 path path.rstrip 判斷路徑是否存在 存在 true 不存在 false i ists os.path.exists path 判斷結果 ifnot i ists ...

Python建立資料夾

import os 批量建立資料夾,用來存放按日儲存的日常工作檔案 def mkdir all path 獲取檔案是否存在 folder os.path.exists all path ifnot folder os.makedirs 建立檔案時如果路徑不存在會建立這個路徑 os.makedirs ...

建立資料夾

當某資料夾不存在時,建立資料夾 import os path dir file if not os.path.exists path dir os.makedirs path dir 同時建立資料夾有兩種函式,os.mkdir和os.makedirs,兩者的區別在於前者是一級一級建立檔案目錄,後者可...