代码拉取完成,页面将自动刷新
'''
模拟linux的cp指令。
'''
from shutil import copy2
# copy2函数与copy函数的功能类似,但除了copy函数的功能外,还会复制文件的状态信息.
# 如最后访问时间,最后修改时间等。类似Linux的cp -p命令
# copy()文件复制。shutil可以简单地理解为sh + util,shell工具.
# shutil模块是对os模块的补充,主要针对文件的拷贝、删除、移动、压缩和解压操作。
# 测试文件是否存在
def test_file_exist(location):
try:
with open(location, mode="rb") as fileread:
fileread.read(8) # 检测能否读到数据
except IOError:
return 0
source = input("Source Full Path:")
location = source
# 检测来源文件是否存在。
if test_file_exist(location) == 0:
print("File is not found or don't have permission to access this file.")
exit()
destination = input("Destination Full Path:")
location = destination
# 检测目标文件是否存在。
if test_file_exist(location) != 0:
print("File exist.Can't overwrite.Try again,plz.")
exit()
copy2(source, destination)
print("Fin.")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。