上移目录
我正在 php 脚本中创建一个目录,进入该目录并执行一些操作。这部分工作正常。
现在,我想移出该目录并将其删除。 有关如何执行此操作的任何指示?
我尝试过提升 1 级,但不起作用,
chdir("../");
chdir("..")
system("cd ..");
上述任何操作对当前工作目录都没有任何影响
I'm creating a directory in a php script, moving into that directory and doing some stuff. This part works fine.
Now, I want to move out of this directory and delete it.
Any pointers on how to do this?
I have tried moving up 1 level, but it doesnt work
chdir("../");
chdir("..")
system("cd ..");
none of the above have any effect on the present working directory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以执行以下操作来更明确地了解您的预期路径:
You could do something like this to be more explicit about your intended paths:
创建该目录后,请勿 chdir 进入该目录,从外部修改文件,然后将其删除。
即,而不是做类似的事情:
将代码构造为:
然后您不需要遍历目录层次结构。
Don't chdir into that directory once you create it, modify files from outside it, and then remove it.
i.e. instead of doing something like:
structure your code as:
You then don't need to walk the directory hierarchy.
我建议不要实际更改目录;只需保留感兴趣的路径并直接对其(及其中的文件)进行操作即可。
也就是说,
chdir ('../');
应该可以工作。I would advise against actually changing dir; simply hold the path of interest and operate upon it (and the files within it) directly.
That said,
chdir ('../');
should work.你可以像这样在上层创建一个目录
而不需要移动它
you can create a directory on the upper level like this
without move in it