ETHZParser::ETHZParser(std::string root) : DatabaseParser(), _rootPath(root) { _vStateVectorNames.push_back("class"); _vStateVectorNames.push_back("x"); _vStateVectorNames.push_back("y"); _vStateVectorNames.push_back("z"); _vStateVectorNames.push_back("yaw"); _vStateVectorNames.push_back("pitch"); _vStateVectorNames.push_back("roll"); //To be put in the xml conf file _templateSize.height = 150; _templateSize.width = 150; _vCenters.resize(1, std::vector<cv::Point_<int> >()); _vPaths.resize(1, std::vector<std::string>()); _vGDTruth.resize(1, std::vector<std::vector<double> >()); path p(_rootPath); if (!exists(p)) throw ForestException("Error : " + _rootPath + " does not exist"); if (is_regular_file(p)) throw ForestException("Error : " + _rootPath + " is not a folder"); else if (!is_regular_file(p) && !is_directory(p)) throw ForestException("Error : " + _rootPath + " is not a folder"); std::vector<path> vec; copy(directory_iterator(p), directory_iterator(), back_inserter(vec));//get all files and folder recursively for (std::vector<path>::const_iterator it = vec.begin() ; it != vec.end() ; it++) { if(is_directory(*it)) this->exploreFolder(*it); } }
/* Adds .vifm extension to all regular files in colors_dir directory. */ static void rename_color_schemes(const char colors_dir[]) { DIR *dir; struct dirent *d; dir = opendir(colors_dir); if(dir == NULL) { return; } while((d = readdir(dir)) != NULL) { char full_old_path[PATH_MAX]; char full_new_path[PATH_MAX]; snprintf(full_old_path, sizeof(full_old_path), "%s/%s", colors_dir, d->d_name); snprintf(full_new_path, sizeof(full_new_path), "%s/%s.vifm", colors_dir, d->d_name); #ifndef _WIN32 if(d->d_type == DT_REG || (d->d_type == DT_UNKNOWN && is_regular_file(full_old_path))) #else if(is_regular_file(full_old_path)) #endif { (void)rename(full_old_path, full_new_path); } } closedir(dir); }
void ribi::braw::qtbrainweavercreateassessmentcompletedialog_test::save() { QtCreateAssessmentCompleteDialog d; d.SetQuestion("A question"); const std::string filename{"test_save." + GetFilenameExtension()}; assert(!is_regular_file(filename)); d.Save(filename); QVERIFY(is_regular_file(filename)); ribi::delete_file(filename); assert(!is_regular_file(filename)); }
void ribi::braw::qtbrainweaverstudentmenudialog_test::save() { File f; QtStudentMenuDialog d(f); d.SetName("Jane Doe"); const std::string filename{"test_save." + GetFilenameExtension()}; assert(!is_regular_file(filename)); d.Save(filename); QVERIFY(is_regular_file(filename)); ribi::delete_file(filename); assert(!is_regular_file(filename)); }
bool GameScene::loadGame() { BmsParser parser; bool parseResult = parser.compile(mSong->getPath().c_str(), mBmsDocument); if( !parseResult ) return false; char* supportFormat[] = {"bmp", "jpg", "png"}; int supportLen = sizeof(supportFormat) / sizeof(supportFormat[0]); // image(bga) for(auto it = mBmsDocument.bga().begin(); it != mBmsDocument.bga().end(); it++) { path fullpath = mBmsDocument.header().getParentPath() / it->second; if (is_regular_file(fullpath)) { auto image = new Image; if (image->initWithImageFile(fullpath.string().c_str())) { mImageDictionary[it->first] = image; continue; } delete image; } // try alternatives for (const char* ext : supportFormat) { auto alter = fullpath.replace_extension(ext); if (is_regular_file(alter)) { auto image = new Image; if (image->initWithImageFile(alter.string().c_str())) { mImageDictionary[it->first] = image; break; } delete image; } } } // wave for(auto it = mBmsDocument.wave().begin(); it != mBmsDocument.wave().end(); it++) { path fullpath = mBmsDocument.header().getParentPath() / it->second; mWavDictionary[it->first] = Audio::AudioManager::instance()->loadSound(fullpath.string().c_str()); } return true; }
int main(int argc, char** argv) { ProgramOptions program_options(argc, argv); std::thread t[program_options._threads]; for (int i : range(program_options._threads)) { t[i] = std::thread(call_from_thread, i); } std::cout << "Printed from the main thread" << std::endl; for (auto& thread : t) { thread.join(); } /// BACKGROUND boost::filesystem::path background_dir(program_options._background_input_directory); boost::filesystem::directory_iterator bit(background_dir), beod; std::vector<boost::filesystem::path> background_input_files; BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(bit, beod)) { if(is_regular_file(p) && p.extension() == program_options._input_file_extension) { background_input_files.push_back(p); } } ColibriPLM plm = ColibriPLM(program_options); plm.create_background_model(background_input_files); /// FOREGROUND if(program_options._foreground_input_directory != "") { boost::filesystem::path foreground_dir(program_options._foreground_input_directory); boost::filesystem::directory_iterator fit(foreground_dir), feod; BOOST_FOREACH(boost::filesystem::path const &p, std::make_pair(fit, feod)) { if(is_regular_file(p) && p.extension() == program_options._input_file_extension) { std::vector<std::pair<Pattern, double>> document_word_probs = plm.create_document_model(p); boost::filesystem::path output_file_name = boost::filesystem::path(program_options._generated_output_directory + "/" + p.stem().string() + ".dwp"); write_probs_to_file(document_word_probs, plm.getDecoder(), output_file_name); } } }
void DirHandler::files_counting(pair<string, int> * dir, string cur_path) { if (stop_condition) return; path p(cur_path); try { if (exists(p)) // does p actually exist? { if (is_regular_file(p)){ // is p a regular file? //cout << p << " - It's file. size is " << file_size(p) << endl; } else if (is_directory(p)) // is p a directory? { for (directory_iterator it(p); it != directory_iterator(); ++it) { if (is_regular_file(*it)){ dir->second++; } else if (is_directory(*it)){ // dive to next directory string next_path = it->path().string(); files_counting(dir, next_path); } } } else{ //cout << p << " exists, but is neither a regular file nor a directory" << endl; } } else { //cout << p << " does not exist" << endl; } } catch (const filesystem_error& ex) { cout << ex.what() << endl; } // thread is finishing // when path name equals initial directory name if (dir->first.compare(cur_path) == 0){ thr_finishes(); } }
void DirAnalyzer::getFiles(path folder_path, vector<File> & files) { vector<path> files_to_read = readFolder(folder_path); for (vector<path> ::const_iterator it (files_to_read.begin()); it != files_to_read.end(); ++it) { path p=*it; try { if (is_regular_file(p)) // is p a regular file? { File new_file(p); /*File new_file; new_file.setName(p.filename()); new_file.setPath(p.string()); new_file.setSize(file_size(p));*/ files.push_back(new_file); } else if (is_directory(p)) // is p a directory? { getFiles(p, files); } } catch (const filesystem_error& ex) { cout << ex.what() << '\n'; exit(1); } } }
int find_file(const char *filename) { Buffer *bp; char *s; for (bp = head_bp; bp != NULL; bp = bp->next) if (bp->filename != NULL && !strcmp(bp->filename, filename)) { switch_to_buffer(bp); return TRUE; } s = make_buffer_name(filename); if (strlen(s) < 1) { free(s); return FALSE; } if (!is_regular_file(filename)) { minibuf_error("%s is not a regular file", filename); waitkey(WAITKEY_DEFAULT); return FALSE; } bp = create_buffer(s); free(s); bp->filename = zstrdup(filename); switch_to_buffer(bp); read_from_disk(filename); thisflag |= FLAG_NEED_RESYNC; return TRUE; }
inline bool is_other(file_status s) noexcept { return (exists(s) && not is_regular_file(s) && not is_directory(s) && not is_symlink(s)); }
int main(int argc, char **argv) { char *from_path, *to_path; char buf[BUFFER_SIZE]; int from_fd, to_fd, n; if (argc != 3) err_quit("usage: %s <from> <to>", argv[0]); from_path = argv[1]; to_path = argv[2]; if (is_regular_file(from_path) == 0) err_quit("%s is not regular file", from_path); if ((from_fd = open(from_path, O_RDONLY)) < 0) err_sys("open %s failed", from_path); if ((to_fd = open(to_path, O_CREAT | O_WRONLY | O_TRUNC, FILE_MODE)) < 0) err_sys("open %s failed", to_path); while ((n = read(from_fd, buf, BUFFER_SIZE)) > 0) { if (buf[0] != '\0') write(to_fd, buf, 1); else lseek(to_fd, 1, SEEK_CUR); } close(from_fd); close(to_fd); return 0; }
std::vector<std::string> find_layout_files(const std::string& apk_directory) { std::vector<std::string> layout_files; std::string root = apk_directory + std::string("/res"); path_t res(root); if (exists(res) && is_directory(res)) { for (auto it = dir_iterator(res); it != dir_iterator(); ++it) { auto const& entry = *it; path_t entry_path = entry.path(); if (is_directory(entry_path) && starts_with(entry_path.filename().string().c_str(), "layout")) { for (auto lit = dir_iterator(entry_path); lit != dir_iterator(); ++lit) { auto const& layout_entry = *lit; path_t layout_path = layout_entry.path(); if (is_regular_file(layout_path)) { layout_files.push_back(layout_path.string()); } } } } } return layout_files; }
bool LoadFont(const bfs::path && path, const std::string & font) { if(bfs::exists(path)) { if( is_regular_file(path) ) { if(path.filename() == font) { sf::Font * f = new sf::Font(); f->loadFromFile(path.string()); loaded_fonts[const_cast<std::string&>(font)] = f; return true; } } if( is_directory(path) ) { std::vector<bfs::path> ls_path; std::copy(bfs::directory_iterator(path), bfs::directory_iterator(), std::back_inserter(ls_path)); for(auto it = ls_path.begin(); it != ls_path.end(); ++it) { if( LoadFont(std::move(*it), font) ) return true; } } } return false; }
vector<string> all_files_from_path(const string &dir_path, const string &ext, bool case_sensitive, bool recursive) { vector<string> all_files; string extension_with_case = ext; if ( case_sensitive ) to_upper( extension_with_case ); if ( !exists(dir_path) ) return all_files; directory_iterator end_itr; // default construction yields past-the-end for (directory_iterator itr(dir_path); itr != end_itr; ++itr) { if ( is_regular_file(itr->status()) ) { if ( ext != "" ) { string filename_extension_with_case = itr->path().string(); if ( case_sensitive ) to_upper( filename_extension_with_case ) ; if ( extension( filename_extension_with_case ) == extension_with_case ) all_files.push_back( itr->path().string() ); } else all_files.push_back( itr->path().string() ); } else if ( is_directory(itr->status()) ) { vector<string> files_in_recursion = all_files_from_path( itr->path().string() , extension_with_case , true ); all_files.insert( all_files.end() , files_in_recursion.begin() , files_in_recursion.end() ); } } return all_files; }
SCVectorizedMat Converter::multiGray2SCMat(char* dirpath){ /** * Vectorize and concatenate multiple images. */ SCVectorizedMat data; path p(dirpath); if (exists(p) && is_directory(p)){ for (directory_entry& x : directory_iterator(p)){ if (is_regular_file(x.path())){ string path = x.path().string(); if (path.find( ".DS_Store" ) != string::npos ) continue; SCMat frame = readGray2SCMat(path); cout << path << endl; frame.gray.reshape(frame.rows * frame.cols, 1); if (data.nMat == 0) { data.rows = frame.rows; data.cols = frame.cols; data.gray = frame.gray; data.nMat ++; } else{ data.gray = join_rows(data.gray, frame.gray); data.nMat ++; } } } } return data; }
fs::path HOSTFXR_UTILITY::GetAbsolutePathToHostFxr( const fs::path & dotnetPath ) { std::vector<std::wstring> versionFolders; const auto hostFxrBase = dotnetPath.parent_path() / "host" / "fxr"; LOG_INFOF(L"Resolving absolute path to hostfxr.dll from '%ls'", dotnetPath.c_str()); if (!is_directory(hostFxrBase)) { throw InvalidOperationException(format(L"Unable to find hostfxr directory at %s", hostFxrBase.c_str())); } FindDotNetFolders(hostFxrBase, versionFolders); if (versionFolders.empty()) { throw InvalidOperationException(format(L"Hostfxr directory '%s' doesn't contain any version subdirectories", hostFxrBase.c_str())); } const auto highestVersion = FindHighestDotNetVersion(versionFolders); const auto hostFxrPath = hostFxrBase / highestVersion / "hostfxr.dll"; if (!is_regular_file(hostFxrPath)) { throw InvalidOperationException(format(L"hostfxr.dll not found at '%s'", hostFxrPath.c_str())); } LOG_INFOF(L"hostfxr.dll located at '%ls'", hostFxrPath.c_str()); return hostFxrPath; }
std::vector< std::string > getImagesList(const char *dir_path) { std::vector< std::string > ret; boost::filesystem::path dir(dir_path); if(!exists(dir)) { std::cout << "O diretório de entrada não existe." << std::endl; return ret; } boost::filesystem::recursive_directory_iterator dir_it(dir); boost::filesystem::recursive_directory_iterator end_it; while(dir_it != end_it) { if(is_regular_file((*dir_it).path())) { if((*dir_it).path().filename().string() != ".gitignore") { ret.push_back((*dir_it).path().string()); } } ++dir_it; } std::random_shuffle(ret.begin(), ret.end()); return ret; }
int color_scheme_exists(const char name[]) { char full_path[PATH_MAX]; snprintf(full_path, sizeof(full_path), "%s/colors/%s", cfg.config_dir, name); return is_regular_file(full_path); }
/* * -EBADF, -EISDIR, -EFBIG, -ENOSPC */ int64_t sys_write(int fd, void *buf, uint64_t count) { struct file *file; struct inode *inode; int64_t write_len; file = unrolled_lookup(¤t->fdtable, fd); if (file == NULL) return -EBADF; if ((file->flags & O_WRONLY) == 0) return -EBADF; assert(file->inum > 0); if (is_dir(file->inum)) return -EISDIR; if (!is_regular_file(file->inum)) return -EBADF; inode = inode_get(file->inum); spin_lock(&file->lock); write_len = file_write(inode, buf, file->offset, count); if (write_len < 0) goto out; assert(file->offset + write_len <= inode->size_low); file->offset += write_len; out: spin_unlock(&file->lock); return write_len; }
StatusLine FileReader::get_resource(const std::string& abs_path,Entity& saver) { StatusLine ret(http_200,""); std::string full_path=m_doc_root+abs_path; try { boost::filesystem::path file_path(full_path); if(boost::filesystem::exists(file_path) ) { if (is_regular_file(file_path)) { ret = read_file(full_path,saver); } else if (is_directory(file_path)) { ret.reson_pharse()="can not get a directory :" + full_path; ret.status_code().code()=http_403; } else { ret.reson_pharse()=full_path+ " is neither a regular file nor a directory"; ret.status_code().code()=http_409; } } else { ret.reson_pharse()=full_path+ " is not exists"; ret.status_code().code()=http_404; } } catch (boost::filesystem::filesystem_error& e) { ret.reson_pharse()=e.what(); ret.status_code().code()=http_500; } catch (std::exception& e) { ret.reson_pharse()=e.what(); ret.status_code().code()=http_500; } catch (...) { ret.reson_pharse()="Unkonw exception"; ret.status_code().code()=http_500; } return ret; }
int color_scheme_exists(const char name[]) { char cs_path[PATH_MAX]; get_cs_path(name, cs_path, sizeof(cs_path)); return is_regular_file(cs_path); }
bool FileList::addFile(const UString &file) { if (!exists(file.c_str()) || !is_regular_file(file.c_str())) // File is either no regular file or doesn't exist return false; addPath(file, path(file.c_str())); return true; }
int add_file(ff7::lgp::Archive& ar, fs::path const& path) { int added{}; if (is_directory(path)) { for (auto it = rec_it(path); it != rec_it(); ++it) if (is_regular_file(it->path())) { ar[it->path().generic_string()] = ff7::lgp::make_file(it->path().string()); ++added; } } else if (is_regular_file(path)) { ar[path.generic_string()] = ff7::lgp::make_file(path.string()); ++added; } return added; }
void MainPurgeLoop::DealWithFile(const path pathname) { if(!is_regular_file(config_ptr->backup_to_home(pathname) )) { FileMoveTask* mtask= new FileMoveTask(pathname, config_ptr->backup_to_removed_purge(pathname),config_ptr ); config_ptr->add_task(mtask); } }
void Handler::processCommandDownload(CommandBase& command) { static string rootDir; static int allowDownload = -1; if (allowDownload < 0) { string allowDownloadStr; Config::instance().get(CONFIG_ALLOW_DOWNLOAD, allowDownloadStr); allowDownload = (allowDownloadStr == "true") ? 1 : 0; string home; Config::instance().get(CONFIG_HOME_DIR, home); if (home.empty()) THROW("Home directory is not defined"); rootDir = home + WWW_DIR; } if (allowDownload != 1) THROW("Download functionality is disabled"); DownloadCommand& cmd = static_cast<DownloadCommand&>(command); string path = rootDir + cmd.m_path; if (!exists(path) || !is_regular_file(path)) { const char* err404 = "HTTP/1.1 404 No such file\r\n\r\n"; int ret = m_socket.send(err404, strlen(err404)); if (ret != (int)strlen(err404)) THROW("Failed to send error 404"); return; } string type = "text/plain"; size_t pos = path.find('.'); if (pos != string::npos) { string ext = path.substr(pos+1); type = Config::instance().contentType(ext); } string contentType = string("Content-Type: ") + type; int size = (int)file_size(path); ostringstream response; response << responseHeader << "\r\n"; response << contentType << "\r\n"; response << contentLength << size << "\r\n"; response << "\r\n"; vector< char > content; content.resize(size); FILE* f = fopen(path.c_str(), "rb"); if (f == NULL) THROW(string("Failed to open file - ")+strerror(errno)); int ret = fread(&content[0], 1, size, f); fclose(f); if (ret != (int)size) THROW(string("Failed to read file - ")+strerror(errno)); ret = m_socket.send(response.str().c_str(), response.str().length()); if (ret != (int)response.str().length()) THROW("Failed to send data"); ret = m_socket.send(&content[0], size); if (ret != (int)size) THROW(string("Failed to send file - ")+strerror(errno)); }
// Return full path of FILE, searching in a number of predefined places. // If not found, return "". string resolvePath(const string& file, bool include_user) { static StringArray prefixes; static int sys_index = 0; if (prefixes.size() == 0) { // Look in ~/.ddd. prefixes += session_state_dir(); sys_index = prefixes.size(); // Look in $DDD_HOME. if (getenv(DDD_NAME "_HOME") != 0) prefixes += getenv(DDD_NAME "_HOME"); // Look in DDD_ROOT (typically /usr/local/share/ddd-VERSION). prefixes += DDD_ROOT; // Look in DDD_ALT_ROOT (typically /usr/local/share/ddd).. prefixes += DDD_ALT_ROOT; for (int i = 0; i < 3; i++) { string prefix; switch (i) { case 0: prefix = myPrefix(); break; case 1: prefix = "/usr/local"; break; case 2: prefix = "/usr"; break; } prefixes += prefix + "/share/" ddd_NAME "-" DDD_VERSION; prefixes += prefix + "/share/" ddd_NAME; prefixes += prefix + "/lib/" ddd_NAME "-" DDD_VERSION; prefixes += prefix + "/lib/" ddd_NAME; prefixes += prefix + "/" ddd_NAME "-" DDD_VERSION; prefixes += prefix + "/" ddd_NAME; } } StatusDelay delay("Searching " + quote(file)); for (int i = include_user ? 0 : sys_index; i < prefixes.size(); i++) { string path = prefixes[i] + "/" + file; set_status("Trying " + quote(path)); if (is_regular_file(path) || is_directory(path)) { delay.outcome = quote(path); return path; } } delay.outcome = "not found"; return ""; }
int64_t file_mod_time(const std::string& fname) { path p(fname); if(is_regular_file(p)) { return static_cast<int64_t>(last_write_time(p)); } else { return 0; } }
void uploadctr(char *filename, char *ip) { int ret, size, p, n, k, i, j; FILE *fd; SOCKET sd; unsigned char *buf; fd = fopen(filename, "rb"); if ( fd == NULL ) { printf("file %s not found\n", filename); return; } #ifndef __WIN32__ if (!is_regular_file(filename)) { printf("file %s is not a regular file\n", filename); fclose(fd); return; } #endif fseek(fd, 0, SEEK_END); size = ftell(fd); fseek(fd, 0, SEEK_SET); buf = malloc(size); if ( buf == NULL ) { printf("Not enough memory!\n"); fclose(fd); return; } fread(buf, size, 1, fd); // gah no validation, M4 will verify some... fclose(fd); ret = httpConnect(ip); if ( ret >= 0 ) { sd = ret; // connect socket if ( httpSend(sd, "/CARTIMG.BIN", buf, size, "upfile", "/upload.html", ip) >= 0 ) ret = httpResponse(sd); httpClose(sd); if ( ret == 200 ) printf("Upload OK!\r\n"); else printf("Upload error code. %i\r\n", ret); } else printf("Connect to %s failed\n", ip); free(buf); }
void pipeline::reload_shadow_mapping() { auto vertex_file = shader_directory / "null.vertex.glsl"; auto fragment_file = shader_directory / "null.fragment.glsl"; if (!is_regular_file(vertex_file) || !is_regular_file(fragment_file)) return; shadow_mapping = basic_pass{ "shadow_mapping", add_program(program::configuration() .vertex_shader(shader_directory / "null.vertex.glsl") .fragment_shader(shader_directory / "null.fragment.glsl") .preprocessor_commands("#version 330\n")), GL_DEPTH_BUFFER_BIT, GL_BACK, render_mode{} .set(render_mode::statics) .set(render_mode::dynamics) .set(render_mode::test_depth)}; }
// The processPath ends with dotnet.exe or dotnet // like: C:\Program Files\dotnet\dotnet.exe, C:\Program Files\dotnet\dotnet, dotnet.exe, or dotnet. // Get the absolute path to dotnet. If the path is already an absolute path, it will return that path fs::path HOSTFXR_UTILITY::GetAbsolutePathToDotnet( const fs::path & applicationPath, const fs::path & requestedPath ) { LOG_INFOF(L"Resolving absolute path to dotnet.exe from '%ls'", requestedPath.c_str()); auto processPath = requestedPath; if (processPath.is_relative()) { processPath = applicationPath / processPath; } // // If we are given an absolute path to dotnet.exe, we are done // if (is_regular_file(processPath)) { LOG_INFOF(L"Found dotnet.exe at '%ls'", processPath.c_str()); return processPath; } // At this point, we are calling where.exe to find dotnet. // If we encounter any failures, try getting dotnet.exe from the // backup location. // Only do it if no path is specified if (requestedPath.has_parent_path()) { LOG_INFOF(L"Absolute path to dotnet.exe was not found at '%ls'", requestedPath.c_str()); throw InvalidOperationException(format(L"Could not find dotnet.exe at '%s'", processPath.c_str())); } const auto dotnetViaWhere = InvokeWhereToFindDotnet(); if (dotnetViaWhere.has_value()) { LOG_INFOF(L"Found dotnet.exe via where.exe invocation at '%ls'", dotnetViaWhere.value().c_str()); return dotnetViaWhere.value(); } const auto programFilesLocation = GetAbsolutePathToDotnetFromProgramFiles(); if (programFilesLocation.has_value()) { LOG_INFOF(L"Found dotnet.exe in Program Files at '%ls'", programFilesLocation.value().c_str()); return programFilesLocation.value(); } LOG_INFOF(L"dotnet.exe not found"); throw InvalidOperationException(format( L"Could not find dotnet.exe at '%s' or using the system PATH environment variable." " Check that a valid path to dotnet is on the PATH and the bitness of dotnet matches the bitness of the IIS worker process.", processPath.c_str())); }