如何在python中移回一个文件夹 [英] How to move to one folder back in python
本文介绍了如何在python中移回一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上需要走一些路并执行一些命令,下面是代码
Actually need to go some path and execute some command and below is the code
代码:
import os
present_working_directory = '/home/Desktop/folder'
目前我在folder
if some_condition == true :
change_path = "nodes/hellofolder"
os.chdir(change_path)
print os.getcwd()
if another_condition == true:
change_another_path = "nodes"
os.chdir(change_another_path)
print os.getcwd()
**Result**:
'/home/Desktop/folder/nodes/hellofolder'
python: [Errno 1] No such file or directory
实际上,这里发生的是我第一次使用os.chdir()
时目录已更改为
Actually whats happening here is when i first used os.chdir()
the directory has changed to
'/home/Desktop/folder/nodes/hellofolder'
,
但是对于第二个,我需要通过移回一个文件夹
but for the second one i need to run a file by moving to one folder back that is
'/home/Desktop/folder/nodes'
任何人都可以让我如何在python中将一个文件夹移回
So can anyone let me how to move one folder back in python
推荐答案
就像在shell中一样.
Just like you would in the shell.
os.chdir("../nodes")
这篇关于如何在python中移回一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文