标签: working-directory

如何在 Dart 中设置当前工作目录?

在 dart 控制台应用程序中,如何设置当前工作目录?

working-directory dart dart-io

6
推荐指数
1
解决办法
982
查看次数

boost :: filesystem :: create_directories(".")失败

boost::filesystem::create_directories(".")总是在我的系统上失败.看起来这可能是一个错误,但在阅读文档后我并不完全确定.这是一个示例程序:

#include <iostream>
#include <boost/filesystem.hpp>

int main(int argc, char* argv[])
try
{
    namespace fs = boost::filesystem;
    std::cerr << "is_directory: " << fs::is_directory(argv[1]) << '\n';
    std::cerr << "create_directory: " << fs::create_directory(argv[1]) << '\n';
    std::cerr << "create_directories: " << fs::create_directories(argv[1]) << '\n';
}
catch (const std::exception& ex)
{
    std::cerr << ex.what() << '\n';
}
Run Code Online (Sandbox Code Playgroud)

如果我使用参数.(意味着当前目录)运行它,它会打印:

is_directory: 1
create_directory: 0
boost::filesystem::create_directories: Invalid argument
Run Code Online (Sandbox Code Playgroud)

前两行并不令人惊讶:.是一个目录,并create_directory()记录下来:

由于p解析为现有目录,因此创建失败不应视为错误.

但第三行对我来说是一个惊喜:create_directories(".")即使.存在也失败了.如果你使用不同的名字就没有这样的失败,比如foo- 它会愉快地创建那个目录,或者如果它已经存在则返回false.

文档有这样的说法:

效果:通过为不存在的p的任何元素调用create_directory()来建立后置条件.

后置条件:is_directory(p) …

c++ boost working-directory boost-filesystem

6
推荐指数
0
解决办法
3137
查看次数

VSCode 中的 Python:每次都将工作目录设置为 python 文件的路径

所以我想从 Spyder 迁移到 VSCode,我遇到了这个问题,我无法访问数据集,因为我的工作目录与数据集的路径不同。

launch.json不是为我自动生成的,因为我没有调试任何东西(我试过这个)。

如何在 VSCode 中将工作目录设置为始终是我要运行的 Python 文件的目录?(如果这是不好的做法,你能告诉我一个易于使用的配置吗?)我想为 VSCode 的 IPython 终端设置它。

python working-directory visual-studio-code

6
推荐指数
6
解决办法
8976
查看次数

使用 Chokidar 监视父文件夹时,文件夹不允许重命名子文件夹或删除非空子文件夹

使用 Chokidar\xef\xbc\x8c 监视包含子文件夹的文件夹时,监视文件夹无法重命名。

\n

版本:\n\xc2\xa0\xc2\xa0\xc2\xa0 Chokidar 版本:3.5.2\n\xc2\xa0\xc2\xa0\xc2\xa0 Angular CLI:12.0.2\n\xc2\xa0\xc2 \xa0\xc2\xa0 节点:16.17.0\n\xc2\xa0\xc2\xa0\xc2\xa0 程序包管理器:npm 9.2.0\n\xc2\xa0\xc2\xa0\xc2\xa0 操作系统版本:Windows 10\xc2\xa0

\n

\r\n
\r\n
//defaultOptions for chokidar :\ndefaultOptions = {\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 ignored: /(^|[\\/\\\\])\\../, // ignore dotfiles\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 persistent: true,\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 depth: 99,\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 alwaysStat: true,\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 awaitWriteFinish: {\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 stabilityThreshold: 2000,\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 pollInterval: 100\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 },\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 ignorePermissionErrors: false,\n    \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 atomic: true // or a custom \'atomicity delay\', in milliseconds (default 100)\n    \xc2\xa0\xc2\xa0\xc2\xa0 }
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

第 1 步:观察任意文件夹,例如使用 chokidar 的测试 1。

\n

步骤 …

rename working-directory node.js electron chokidar

6
推荐指数
0
解决办法
162
查看次数

Python:是否可以在不更改实际当前目录的情况下更改Windows命令行shell当前目录?

我正在使用os.system()Windows命令行shell执行.我想更改Windows cmd当前目录.这是一种方法:

os.chdir('newPath')
Run Code Online (Sandbox Code Playgroud)

但是chdir()也会改变实际的Python当前工作目录.我不想更改实际的Python工作目录,因为我希望我的脚本的其他部分在原始的当前工作目录中运行.我想要更改的只是Windows cmd当前工作目录.换句话说:我希望os.system()命令在一个当前工作目录(Windows cmd当前工作目录)中运行,而其他任何东西应该在另一个当前工作目录(实际的Python当前工作目录)中运行.

这是另一个尝试更改Windows cmd当前目录:

os.system('cd newPath')
Run Code Online (Sandbox Code Playgroud)

但是,这显然不起作用,因为在执行cd newPath命令之后,Windows cmd当前目录被重置(因为我不会在下次调用时使用相同的Windows命令shell os.system()).

是否可以为Windows cmd shell创建单独的当前工作目录?(与实际当前工作目录分开).

python cmd working-directory

5
推荐指数
1
解决办法
3140
查看次数

如何获取Grails/Tomcat Webapp的当前工作目录?

我为Tomcat写了一个Grails webapp,它打开并从./data/transactions/foobar上的Berkeley DB中读取.

这个代码在我的Eclipse环境中运行良好.

但是当我将它移动到服务器时,它会吐出这个异常.当我将WAR文件中的Grails部署为服务器上的webapps Web应用程序时,我不确定当前工作目录的位置.

com.sleepycat.je.EnvironmentNotFoundException: (JE 4.1.10) ./data/transactions/Foobar
Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no log files in the environment directory. Environment is invalid and must be closed.
Run Code Online (Sandbox Code Playgroud)

Linux服务器上的我的Tomcat安装目录是/ usr/share/tomcat6.webapps root目录是/ usr/share/tomcat6/webapps.我们的WAR目录安装在名为"bridge"的子目录中.我的Grails应用程序的WAR路径位于/ usr/share/tomcat6/webapps/bridge中

我尝试将./data/transaction/Foobar放在/ usr/share/tomcat6/webapps和/ usr/share/tomcat6/webapps/bridge中,没有运气.

我也尝试将./data/transaction/Foobar放入/ usr/share/tomcat6安装基目录,也没有运气.

以下是我从Tomcat服务器看到的错误:

Error 500: Executing action [index] of controller[com.ecmhp.ecmdatabridge.generators.GenerateEmiDigestsController] 
caused exception: (JE 4.1.10) ./data/transactions/Foobar 
    Home directory: ./data/transactions/Foobar ENV_NOT_FOUND: 
    EnvironmentConfig.setAllowCreate is false so environment creation is not permitted, but there are no …
Run Code Online (Sandbox Code Playgroud)

grails tomcat working-directory

5
推荐指数
2
解决办法
5538
查看次数

究竟拥有"当前工作目录"的是什么?

我知道什么是工作目录(wd),它的目的是(至少编写软件).

我不明白的是wd的所有权.此外,我想了解操作系统之间的答案可能有所不同,因此可以理解对特定操作系统上的异常行为的任何澄清.

首先,wd在哪里表现出来?它是否在一个进程中,并且该进程创建的所有线程共享相同的wd?如果wd被线程'A'修改,那么线程'B'的变化是否立即可见,这也是线程'A的进程产生的?

其次,wd最初是如何定义的?如果您从命令提示的东西它容易看到,但对于其派生几个方法相似?


注意:Process Explorer在其"属性"窗口中显示每个进程的"wd".

language-agnostic operating-system platform-agnostic process working-directory

5
推荐指数
1
解决办法
763
查看次数

将脚本的工作文件夹添加到Windows上的Python导入()路径的最佳方法?

我有一个python程序,我使用py2exe编译成Windows .exe.使用Inno Setup,我创建了一个Windows安装程序.

我的程序的性质是它使用插件,后来使用该__import__()语句导入.这些插件位于"plugins"文件夹中,该文件夹本身位于程序的.exe文件所在的子文件夹中.

现在,为了让程序找到插件,它先前在我的文件顶部有以下语句:

sys.path+= ['.']
Run Code Online (Sandbox Code Playgroud)

但是,当用户通过Windows的开始菜单启动程序时,这不能很好地工作,因为显然工作文件夹设置为开始菜单(而不是.exe所在的位置).所以'.'没有解决我想要的问题.

我通过将语句更改为以下来修复它,以便该__import__()语句也查找.exe所在的文件夹(因为它argv[0]是可执行文件的完整路径):

sys.path+= [os.path.dirname(sys.argv[0])]
Run Code Online (Sandbox Code Playgroud)

但是,我不确定我是否选择了正确的解决方案.特别是,因为我的程序是跨平台的(Windows,OSX,Linux),sys.argv文档说argv [0],"它是依赖于操作系统的,无论这是否是一个完整的路径名".

我应该以不同的方式解决这个问题,还是我的方法可行

python windows cross-platform working-directory

5
推荐指数
1
解决办法
275
查看次数

R list.files(my_working_directory)显示没有文件,但我知道它们在那里.怎么修?

我正在尝试使用外部硬盘驱动器中的目录作为工作目录使用R. 我可以将工作目录设置到我想要的位置,但是当我使用list.filesR时看不到任何东西.我也无法read.delim用来加载文件.

例如:

> rm(list = ls())
> WD<-"../../../Volumes/My_HD/my_working_directory" 
> setwd(WD) 
> getwd()
[1] "/Volumes/My_HD/my_working_directory"
Run Code Online (Sandbox Code Playgroud)

到目前为止很好,但随后:

> list.files(WD)
character(0)
Run Code Online (Sandbox Code Playgroud)

虽然我希望我知道的文件列表在那里,我可以看到并打开Finder和终端.实际上R脚本本身就在该目录中.

如果那时我尝试打开一个文件,我得到这样的东西:

> myfile <- read.delim(paste(WD,"/file_name", sep = ""), header = T)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '../../../Volumes/My_HD/my_working_directory/file_name': No such file or directory
Run Code Online (Sandbox Code Playgroud)

我以为我做错了指定目录的路径,但我尝试从RStudio点击(会话>设置工作目录和>到源文件位置或>选择目录...)并得到相同的不满意的结果.

我在MacBookPro(OS X 10.7.05)上使用R版本2.15.1.我正在从RStudio版本0.97.551运行R,但问题与RStudio无关,因为当我直接尝试R时也会发生这种情况.

任何帮助将非常感谢.谢谢.

r working-directory hard-drive

5
推荐指数
1
解决办法
9864
查看次数

Visual Studio生成前事件/生成后事件工作目录

文档中不清楚在Visual Studio中用于构建前或构建后事件的工作目录是什么。它是什么?这在哪里记录?

build working-directory post-build-event visual-studio pre-build-event

5
推荐指数
2
解决办法
2137
查看次数