import shutil
original = r'{}'.format(input('original path where the file is currently stored\\file_name.file_extension:\n'))
print()
target = r'{}'.format(input('target path where the file will be copied\\file name.file extension:\n'))
shutil.copyfile(original, target)
当我们执行python脚本时,我们可以在argv[0]中获得脚本路径和脚本名称。如果我们使用PyInstaller将脚本转换为一个onefile可执行文件,我们还可以从argv[0]获取可执行文件路径。我在Windows10中测试了以下代码
您还可以使用以下方法复制可执行文件:(未测试)
我认为你应该复制并粘贴这个文件。您可以在python中执行此操作:
https://datatofish.com/copy-file-python/
它使用shuttle库复制要复制的文件目录和目标中的文件:
我将空格与空print语句和“\n”一起使用,以使程序在运行时更具可读性,但这不是必需的
通过这种方式,我们接收原始文件路径的用户输入,然后是目标文件。这使得您可以将任何文件复制并粘贴到python中任何名称的任何目录中
相关问题 更多 >
编程相关推荐