[英]Python converting back slash to forward slash
I'm trying to copy dir1 to dir2. 我正在尝试将dir1复制到dir2。 Dir1 contains sub-folders and files.
Dir1包含子文件夹和文件。 In the moment of copy I'm creating url like this
C:/dirA/dir1
and C:/dirB/dir2
. 在复制的那一刻,我正在创建类似
C:/dirA/dir1
和C:/dirB/dir2
。 As you see all slashes are forwarded. 如您所见,所有斜杠都已转发。 When run I get this error
运行时出现此错误
No such file or directory path C:/dirB/dir2\\folder1\\file.txt
As you see sub-folder and file have backslashes. 如您所见,子文件夹和文件带有反斜杠。 I really do not know how to change that backslashes because when I create a paths I don't know the names of sub-folders/files.
我真的不知道如何更改反斜杠,因为在创建路径时,我不知道子文件夹/文件的名称。 I can't post entire code because it's huge.
我无法发布整个代码,因为它很大。 To copy I use
distutils.dir_util.copy_tree
. 要复制,请使用
distutils.dir_util.copy_tree
。
在连接之前,您似乎可以在路径的某些部分上使用os.path.normpath
来对当前操作系统进行规范化,在Windows上它将使用正确的斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.