编写程序,实现一个具有各份文件与文件求功能的各份工具。python
时间: 2024-03-18 17:41:11 浏览: 17
好的,我可以为您提供一个简单的Python程序,它可以实现文件的复制、移动、删除和重命名等基本操作。以下是程序代码:
```python
import os
import shutil
while True:
print("请选择您要执行的操作:")
print("1. 复制文件")
print("2. 移动文件")
print("3. 删除文件")
print("4. 重命名文件")
print("0. 退出程序")
choice = input("请输入数字进行选择:")
if choice == "1":
src_file = input("请输入要复制的文件路径:")
dst_file = input("请输入复制后的文件路径:")
shutil.copy(src_file, dst_file)
print("文件复制成功!")
elif choice == "2":
src_file = input("请输入要移动的文件路径:")
dst_file = input("请输入移动后的文件路径:")
shutil.move(src_file, dst_file)
print("文件移动成功!")
elif choice == "3":
src_file = input("请输入要删除的文件路径:")
os.remove(src_file)
print("文件删除成功!")
elif choice == "4":
src_file = input("请输入要重命名的文件路径:")
dst_file = input("请输入文件的新名称:")
os.rename(src_file, dst_file)
print("文件重命名成功!")
elif choice == "0":
print("程序已退出。")
break
else:
print("输入有误,请重新输入。")
```
您可以根据需要在程序中添加其他功能。希望能对您有所帮助!