Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnFileUtils.h
Go to the documentation of this file.
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnFileUtils.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
19 #pragma once
20 
21 #include <set>
22 #include <string>
23 #include <string.h>
24 #include <vector>
25 #include <fstream>
26 
27 using namespace std;
28 
31 vector<string> drwnDirectoryListing(const char *directory,
32  const char *extension = NULL, bool bIncludeDir = true,
33  bool bIncludeExt = true);
34 
37 vector<string> drwnDirectoryListing(const char *directory,
38  const set<const char *>& extensions, bool bIncludeDir = true);
39 
41 string drwnGetCurrentDir();
43 bool drwnChangeCurrentDir(const char *directoryPath);
44 
46 bool drwnCreateDirectory(const char *directoryPath);
48 bool drwnRemoveDirectory(const char *directoryPath);
49 
51 bool drwnRemoveFile(const char *filename);
52 
54 bool drwnIsAbsolutePath(const char *path);
56 bool drwnIsRelativePath(const char *path);
57 
59 int drwnCountFields(ifstream *ifs, char delimiter = ' ', bool bSkipRepeated = true);
60 
62 vector<string> drwnReadFile(const char *filename);
64 vector<string> drwnReadLines(const char *filename);
66 string drwnReadAll(const char *filename);
68 int drwnCountLines(const char *filename);
69 
71 bool drwnPathExists(const char *pathname);
73 bool drwnFileExists(const char *filename);
75 bool drwnDirExists(const char *dirname);
76 
78 unsigned int drwnFileSize(const char *filename);
79 
81 bool drwnFileResize(const char *filename, unsigned int size);
82 
85 int drwnDirSize(const char *dirname);
vector< string > drwnReadFile(const char *filename)
read strings (separated by whitespace) from a file
Definition: drwnFileUtils.cpp:239
int drwnDirSize(const char *dirname)
returns the number of files and subdirectories in directory (excluding . and ..)
Definition: drwnFileUtils.cpp:404
bool drwnFileExists(const char *filename)
checks if a file exists
Definition: drwnFileUtils.cpp:323
bool drwnIsAbsolutePath(const char *path)
returns true if the directory path is absolute (starts from root)
Definition: drwnFileUtils.cpp:197
bool drwnPathExists(const char *pathname)
checks if a path (directory or file) exists
Definition: drwnFileUtils.cpp:317
bool drwnIsRelativePath(const char *path)
returns true if the directory path is relative to the current directory
Definition: drwnFileUtils.cpp:207
unsigned int drwnFileSize(const char *filename)
returns the size of a file in bytes
Definition: drwnFileUtils.cpp:374
vector< string > drwnDirectoryListing(const char *directory, const char *extension=NULL, bool bIncludeDir=true, bool bIncludeExt=true)
returns a sorted list of filenames in directory filtered by extension
Definition: drwnFileUtils.cpp:41
bool drwnDirExists(const char *dirname)
checks if a directory exists
Definition: drwnFileUtils.cpp:346
int drwnCountLines(const char *filename)
counts the number of non-empty lines in a text file
Definition: drwnFileUtils.cpp:298
bool drwnCreateDirectory(const char *directoryPath)
creates a new directory path
Definition: drwnFileUtils.cpp:143
string drwnReadAll(const char *filename)
read complete file into a single string
Definition: drwnFileUtils.cpp:277
bool drwnChangeCurrentDir(const char *directoryPath)
changes the current directory (returns true if successful)
Definition: drwnFileUtils.cpp:125
bool drwnRemoveDirectory(const char *directoryPath)
removes a directory and its contents
Definition: drwnFileUtils.cpp:158
string drwnGetCurrentDir()
returns the current directory path
Definition: drwnFileUtils.cpp:113
bool drwnRemoveFile(const char *filename)
removes a file
Definition: drwnFileUtils.cpp:185
int drwnCountFields(ifstream *ifs, char delimiter= ' ', bool bSkipRepeated=true)
counts the number of fields per line (separated by a single character delimiter)
Definition: drwnFileUtils.cpp:214
bool drwnFileResize(const char *filename, unsigned int size)
resizes a file to size bytes
Definition: drwnFileUtils.cpp:386
vector< string > drwnReadLines(const char *filename)
read complete lines from a file
Definition: drwnFileUtils.cpp:258