the working directory ‘XXX’ does not exist

积累点滴~

今天在idea上重新建了一个项目,结果一运行就报了’the working directory ‘XXX’ does not exist’的错误:
在这里插入图片描述
明明上一个项目都运行好好的,怎么新建一个就出问题了呢?

再看报错信息 是‘G:\LsyJavaStudy\LsyJavaStudy’这个文件夹不存在。
我又去看了看文件夹:
在这里插入图片描述
在这里插入图片描述
打开 Run-Edit Configuration:
在这里插入图片描述
在这里插入图片描述
原来真的是路径有问题,所以要修改为正确的路径:
在这里插入图片描述

再次运行就正常了。
在这里插入图片描述

### Python `os.path` 模块常见用法 #### 获取当前工作目录 获取脚本运行时所在的当前工作目录对于很多应用程序来说非常重要。 ```python import os current_directory = os.getcwd() print("Current Working Directory:", current_directory) ``` #### 分离路径中的目录和文件名 当处理文件路径时,经常需要单独提取出文件夹部分和文件名称。这可以通过组合使用 `os.path.dirname()` 和 `os.path.basename()` 来实现[^2]。 ```python file_path = "/home/user/documents/file.txt" directory = os.path.dirname(file_path) file_name = os.path.basename(file_path) print("Directory:", directory) # 输出: /home/user/documents print("File Name:", file_name) # 输出: file.txt ``` #### 连接路径片段 为了构建完整的文件路径而不必担心操作系统之间的差异,应该采用 `os.path.join()` 方法来安全地拼接不同的路径组成部分[^4]。 ```python joined_path = os.path.join('path', 'www', 'xxx', 'iii') print(joined_path) # 在Unix/Linux上输出:path/www/xxx/iii;在Windows上输出:path\www\xxx\iii ``` #### 判断路径是否存在以及是否为文件或目录 有时还需要验证给定的路径是否存在,并确认其性质(即它是普通文件还是目录)。为此可分别调用 `os.path.exists()`, `os.path.isfile()`, 及 `os.path.isdir()` 函数。 ```python some_path = '/etc/passwd' if os.path.exists(some_path): if os.path.isfile(some_path): print(f"{some_path} is a regular file.") elif os.path.isdir(some_path): print(f"{some_path} is a directory.") else: print(f"The specified path {some_path} does not exist.") ```
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值