且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Python中打开带有空格的目录路径?

更新时间:2022-12-27 18:28:27

原因

Windows NT 中的 NTFS 支持长文件名或带空格的路径.但是,在命令提示符操作中指定这些文件名或目录名时,它们需要用引号引起来.不使用引号会导致错误消息.

Long filenames or paths with spaces are supported by NTFS in Windows NT. However, these filenames or directory names require quotation marks around them when they are specified in a command prompt operation. Failure to use the quotation marks results in the error message.

解决方案

在指定长文件名或带有空格的路径时使用引号.例如,在命令提示符下键入以下内容复制 c:\我的文件名 d:\我的新文件名导致以下错误消息:

Use quotation marks when specifying long filenames or paths with spaces. For example, typing the following at the command prompt copy c:\my file name d:\my new file name results in the following error message:

The system cannot find the file specified.

正确的语法是:复制c:\我的文件名"d:\我的新文件名"请注意,必须使用引号.

The correct syntax is: copy "c:\my file name" "d:\my new file name" Note that the quotation marks must be used.