网络建设与运维python脚本应用

python 脚本

(1)在linux4 上编写/root/createfile.py 的 python3 脚 本,创建20 个 文 件 /root/python/file00 至 /root/python/file19,如果文件存在,则删除再创建;每个文 件的内容同文件名,如file00文件的内容为“file00”。

import os

# 创建目标目录
directory = "/root/python"
if not os.path.exists(directory):
    os.makedirs(directory)

# 创建文件
for i in range(20):
    filename = f"file{i:02d}"
    filepath = os.path.join(directory, filename)
    
    # 如果文件存在,则删除
    if os.path.exists(filepath):
        os.remove(filepath)
    
    # 创建文件并写入内容
    with open(filepath, "w") as file:
        file.write(filename)

网络建设与运维-网络安全讨论组:715170200
 

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 16:00:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 16:00:04       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 16:00:04       58 阅读
  4. Python语言-面向对象

    2024-07-15 16:00:04       69 阅读

热门阅读

  1. 如何避免油罐车拉完煤油拉菜油

    2024-07-15 16:00:04       19 阅读
  2. LeetCode 两数之和

    2024-07-15 16:00:04       20 阅读
  3. 如何rpmbuild打包GLIBC二进制库文件?

    2024-07-15 16:00:04       19 阅读
  4. 认知偏差知识手册

    2024-07-15 16:00:04       20 阅读
  5. Python 实现技术指标邮件告警通知

    2024-07-15 16:00:04       18 阅读
  6. ESP-01S + STM32物联网

    2024-07-15 16:00:04       19 阅读
  7. Spring Cloud微服务开发框架

    2024-07-15 16:00:04       19 阅读
  8. 关于c语言在内存中的分配管理

    2024-07-15 16:00:04       18 阅读
  9. Scala之基础面向对象编程

    2024-07-15 16:00:04       18 阅读
  10. Linux入侵排查

    2024-07-15 16:00:04       18 阅读
  11. 短剧app系统开发

    2024-07-15 16:00:04       22 阅读
  12. Vue响应式源码解析

    2024-07-15 16:00:04       17 阅读