如何在Python中打开带有空格的目录路径? [英] How to open a directory path with spaces in Python?

查看:165
本文介绍了如何在Python中打开带有空格的目录路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从命令行传递源路径和目标路径,如下所示

I am trying to pass source and destination path from the command line as below

python ReleaseTool.py -i C:\Users\Abdur\Documents\NetBeansProjects\Exam System -o C:\Users\Abdur\Documents\NetBeansProjects\Release

但它抛出错误

WindowsError: [Error 3] The system cannot find the path specified: ''

由于考试系统"之间有空格.请建议如何处理.

due to 'Exam System' which has a space between. Please suggest how to handle this.

推荐答案

原因

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.

这篇关于如何在Python中打开带有空格的目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆