Python3 文件夹文件路径获取创建时间戳作为文件名

# coding: utf8
import requests     # 网络加载模块
import os           # 系统文件模块
import time         # 引入时间模块
import calendar;    # 函数calendar。转换表示当前时间的元组 时间戳处理


def fileManager():
    # 时间戳
    # timeName = time.time()
    iamgeName = calendar.timegm(time.gmtime())
    # 时间格式串
    # nameStr= time.localtime(timeName)
    iamgeType = "jpg"
    allNmae = "%s.%s" %(iamgeName,iamgeType)

    print("开始文件操作")
    # print(out)

    # 打印当文件路径
    print(__file__)
    # 打印当前文件夹路径
    print(os.path.abspath(os.path.dirname(__file__)))
    # Python脚本工作的目录路径
    currentFile = os.getcwd()
    print(currentFile)
    print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))

    # 获取上上级目录
    print(os.path.abspath(os.path.dirname(os.getcwd())))
    print(os.path.abspath(os.path.join(os.getcwd(), "..")))

    # 分离扩展名:os.path.splitext()
    # 获取路径名:os.path.dirname()
    # 获取文件名:os.path.basename()

    # 当前路径下添加的子文件夹
    tempFile ="temp"
    allFile =  "%s/%s" %(currentFile,tempFile)

    # 判断路径是否存在
    # 存在     True
    # 不存在   False
    isExists = os.path.exists(allFile)
    if not isExists:
        print("不存在 创建文件夹")
        # 创建文件夹路径
        os.mkdir(allFile)
    else:
        print("存在")

    allPath = "%s/%s" %(allFile,allNmae)
    print(allPath)

    # open(allPath, 'wb').write(r.content) # 将内容写入存档 比如网络下载的图片


if __name__ == '__main__':
    fileManager()

# coding: utf8

import requests # 网络加载模块

import os # 系统文件模块

import time # 引入时间模块

import calendar; # 函数calendar。转换表示当前时间的元组 时间戳处理


 

def fileManager():

# 时间戳

# timeName = time.time()

iamgeName = calendar.timegm(time.gmtime())

# 时间格式串

# nameStr= time.localtime(timeName)

iamgeType = "jpg"

allNmae = "%s.%s" %(iamgeName,iamgeType)

print("开始文件操作")

# print(out)

# 打印当文件路径

print(__file__)

# 打印当前文件夹路径

print(os.path.abspath(os.path.dirname(__file__)))

# Python脚本工作的目录路径

currentFile = os.getcwd()

print(currentFile)

print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))

# 获取上上级目录

print(os.path.abspath(os.path.dirname(os.getcwd())))

print(os.path.abspath(os.path.join(os.getcwd(), "..")))

# 分离扩展名:os.path.splitext()

# 获取路径名:os.path.dirname()

# 获取文件名:os.path.basename()

# 当前路径下添加的子文件夹

tempFile ="temp"

allFile = "%s/%s" %(currentFile,tempFile)

# 判断路径是否存在

# 存在 True

# 不存在 False

isExists = os.path.exists(allFile)

if not isExists:

print("不存在 创建文件夹")

# 创建文件夹路径

os.mkdir(allFile)

else:

print("存在")

allPath = "%s/%s" %(allFile,allNmae)

print(allPath)

# open(allPath, 'wb').write(r.content) # 将内容写入存档 比如网络下载的图片


 

if __name__ == '__main__':

fileManager()

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值