我正在Vimscript中寻找一种优雅的方法来检查函数中当前目录中是否存在文件.
我想出了这个,但不确定这是否是最优雅的解决方案(我将设置vim选项,如果它存在) - 是否有任何方法不必再进行文件名的比较 - 可能使用不同的__CODE__内置函数( ?):
:function! SomeCheck()
: if findfile("SpecificFile", ".") == "SpecificFile"
: echo "SpecificFile exists"
: endif
:endfunction
Run Code Online (Sandbox Code Playgroud) 如何在Qt中检查给定路径中是否存在文件?
我目前的代码如下:
QFile Fout("/Users/Hans/Desktop/result.txt");
if(!Fout.exists())
{
eh.handleError(8);
}
else
{
// ......
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时,handleError即使我在路径中提到的文件不存在,它也没有给出指定的错误消息.
我想检查一个给定的目录是否存在.我知道如何在Windows上执行此操作:
BOOL DirectoryExists(LPCTSTR szPath)
{
DWORD dwAttrib = GetFileAttributes(szPath);
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
Run Code Online (Sandbox Code Playgroud)
和Linux:
DIR* dir = opendir("mydir");
if (dir)
{
/* Directory exists. */
closedir(dir);
}
else if (ENOENT == errno)
{
/* Directory does not exist. */
}
else
{
/* opendir() failed for some other reason. */
}
Run Code Online (Sandbox Code Playgroud)
但我需要一种可移植的方式来做这个..有没有办法检查目录是否存在,无论我使用什么操作系统?也许是C标准库的方式?
我知道我可以使用预处理程序指令并在不同的操作系统上调用这些函数,但这不是我要求的解决方案.
我最终用这个,至少现在:
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
int dirExists(const char *path)
{
struct stat info;
if(stat( path, &info ) != …Run Code Online (Sandbox Code Playgroud) 如果远程服务器(由HTTP提供服务)上存在文件,并且有URL,我该如何检查Java?我不想下载文件,只检查它的存在.
在我的CMake脚本中,我想看看我的系统上是否有文件,如果有文件,请使用默认文件.这是代码:
find_file(
${project_name}_${customer}_config
${ROOT}/configuration/${customer}/configuration.${project_name}.xml
)
if(NOT ${${project_name}_${customer}_config} STREQUAL
${project_name}_${customer}_config-NOTFOUND )
configure_file(${ROOT}/configuration/${customer}/configuration.${project_name}.xml
${CMAKE_CURRENT_BINARY_DIR}/conf/configuration.xml)
else()
configure_file(${FAPP_ROOT}/configuration/Default/configuration.${project_name}.xml
${CMAKE_CURRENT_BINARY_DIR}/conf/configuration.xml)
endif()
Run Code Online (Sandbox Code Playgroud)
但似乎这不起作用.
检查CMake中是否存在文件的正确方法是什么?
我需要检查远程服务器上是否存在特定文件.使用is_file()和file_exists()不起作用.任何想法如何快速,轻松地做到这一点?
if (!(file_exists(http://mysite.com/images/thumbnail_1286954822.jpg))) {
$filefound = '0';
}
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?