如何使用Python脚本将文件从Windows复制到Windows/Linux
我需要用相同的逻辑将一个文件从Windows复制到Linux和Windows机器。可能吗 例: 显示错误: 没有这样的文件或目录:“\xxx.xxx.xxx.xxx\Test”如何使用Python脚本将文件从Windows复制到Windows/Linux,python,Python,我需要用相同的逻辑将一个文件从Windows复制到Linux和Windows机器。可能吗 例: 显示错误: 没有这样的文件或目录:“\xxx.xxx.xxx.xxx\Test” Windows和Linux的目录结构不同。在Windows上,将某些内容复制到C:\Program Files可能是有意义的,但在Linux中,您不会将应用程序存储在/Program Files中。但是,您可以做的是相对于以下位置之一存储文件 主目录 pathlib.Path.home() or os.path.expa
Windows和Linux的目录结构不同。在Windows上,将某些内容复制到
C:\Program Files
可能是有意义的,但在Linux中,您不会将应用程序存储在/Program Files
中。但是,您可以做的是相对于以下位置之一存储文件
主目录
pathlib.Path.home() or os.path.expanduser("~")
pathlib.Path.cwd() or os.getcwd()
tempfile.gettempdir()
pathlib.Path.home()或os.Path.expanduser(“~”)
当前工作目录
pathlib.Path.home() or os.path.expanduser("~")
pathlib.Path.cwd() or os.getcwd()
tempfile.gettempdir()
pathlib.Path.cwd()或os.getcwd()
当前Python文件
__FILE__
__文件__
临时目录
pathlib.Path.home() or os.path.expanduser("~")
pathlib.Path.cwd() or os.getcwd()
tempfile.gettempdir()
tempfile.gettempdir()
一旦你有了要开始的文件夹,你就可以像这样得到跨平台的子文件夹 在Python 3.4+中,您将使用pathlib模块
pathlib.Path.home()/“路径”/“到”/“某处”
在较旧版本的Python中,您将使用os.path模块
os.path.join(os.path.expanduser(“~”,“path”,“to”,“某处”)