BlackDirectory.h
Go to the documentation of this file.
1  /*
2 
3  ####################################################################################
4  # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5  # Copyright (C) 2013-2015 by Yigit YUCE #
6  ####################################################################################
7  # #
8  # This file is part of BlackLib library. #
9  # #
10  # BlackLib library is free software: you can redistribute it and/or modify #
11  # it under the terms of the GNU Lesser General Public License as published by #
12  # the Free Software Foundation, either version 3 of the License, or #
13  # (at your option) any later version. #
14  # #
15  # BlackLib library is distributed in the hope that it will be useful, #
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18  # GNU Lesser General Public License for more details. #
19  # #
20  # You should have received a copy of the GNU Lesser General Public License #
21  # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22  # #
23  # For any comment or suggestion please contact the creator of BlackLib Library #
24  # at ygtyce@gmail.com #
25  # #
26  ####################################################################################
27 
28  */
29 
30 
31 
32 #ifndef BLACKDIRECTORY_H_
33 #define BLACKDIRECTORY_H_
34 
35 #include <string>
36 #include <unistd.h>
37 #include <pwd.h>
38 #include <sys/stat.h>
39 #include <sys/types.h>
40 #include <dirent.h>
41 #include <vector>
42 #include <cstdio>
43 #include <algorithm>
44 
45 
46 
47 
48 
49 namespace BlackLib
50 {
51  const std::string CURRENT_DIRECTORY_NOT_FOUND = "Current Directory Couldn\'t Find";
52 
53 
54  // ########################################### BLACKDIRECTORY DECLARATION STARTS ############################################ //
55 
154  {
155  private:
156  std::string applicationDirectory;
159  public:
160 
165  {
168  };
169 
174  {
175  Directory = 1,
176  File = 2,
179  };
180 
181 
197  BlackDirectory();
198 
217  BlackDirectory(std::string path);
218 
222  virtual ~BlackDirectory();
223 
241  static std::string getHomeDirectoryPath();
242 
260  static std::string getCurrentUserName();
261 
280  static std::string getCurrentDirectoryPath();
281 
300  static std::string getCurrentDirectoryName();
301 
320  static long int getCurrentDirectorySize();
321 
341  static long int getDirectorySize(std::string directoryPath);
342 
362  static bool exists(std::string directoryPath);
363 
383  static bool makeDirectory(std::string directoryPath);
384 
411  static bool removeDirectory(std::string directoryPath, bool rmRecursively = false);
412 
433  static bool renameDirectory(std::string oldDirectoryPath, std::string newDirectoryPath );
434 
459  static bool cd(std::string path);
460 
483  static bool cdUp();
484 
503  static bool isRoot();
504 
554  static std::vector<std::string> getEntryList(std::string directoryPath,
557  bool sortAlphabetically = true);
558 
559 
589  static unsigned int getEntryCount(std::string directoryPath,
592 
593 
643  bool sortAlphabetically = true);
644 
675 
692  std::string getApplicationDirectoryPath();
693 
710  std::string getApplicationDirectoryName();
711  };
712 
713 
714  // ############################################ BLACKDIRECTORY DECLARATION ENDS ############################################# //
715 
716 
717 } /* namespace BlackLib */
718 
719 #endif /* BLACKDIRECTORY_H_ */
static std::string getCurrentDirectoryPath()
Exports current directory path.
Definition: BlackDirectory.cpp:46
static bool isRoot()
Checks working directory is root or not.
Definition: BlackDirectory.cpp:132
Interacts with end user, to use directory system of Linux based OS.
Definition: BlackDirectory.h:153
Definition: BlackDirectory.h:176
static std::string getCurrentUserName()
Exports username.
Definition: BlackDirectory.cpp:38
static std::vector< std::string > getEntryList(std::string directoryPath, BlackDirectory::hiddenFormat hf=BlackDirectory::ExcludeHiddens, BlackDirectory::componentFormat cf=BlackDirectory::All, bool sortAlphabetically=true)
Exports the directories, files and sybollic links list in directory.
Definition: BlackDirectory.cpp:141
componentFormat
Definition: BlackDirectory.h:173
static bool makeDirectory(std::string directoryPath)
Creates new directory.
Definition: BlackDirectory.cpp:221
static bool renameDirectory(std::string oldDirectoryPath, std::string newDirectoryPath)
Renames directory.
Definition: BlackDirectory.cpp:282
static long int getCurrentDirectorySize()
Exports current directory size in bytes.
Definition: BlackDirectory.cpp:86
BlackDirectory()
Constructor of BlackDirectory class.
Definition: BlackDirectory.cpp:13
std::string applicationDirectory
is used to hold the application directory
Definition: BlackDirectory.h:156
static std::string getHomeDirectoryPath()
Exports "home" directory path.
Definition: BlackDirectory.cpp:30
static unsigned int getEntryCount(std::string directoryPath, BlackDirectory::hiddenFormat hf=BlackDirectory::ExcludeHiddens, BlackDirectory::componentFormat cf=BlackDirectory::All)
Exports the directories, files and sybollic links count in directory.
Definition: BlackDirectory.cpp:179
virtual ~BlackDirectory()
Destructor of BlackDirectory class.
Definition: BlackDirectory.cpp:24
std::string getApplicationDirectoryPath()
Exports the application directory path.
Definition: BlackDirectory.cpp:198
static bool cdUp()
Changes working directory to up directory.
Definition: BlackDirectory.cpp:127
static std::string getCurrentDirectoryName()
Exports current directory name.
Definition: BlackDirectory.cpp:68
static bool cd(std::string path)
Changes working directory.
Definition: BlackDirectory.cpp:118
hiddenFormat
Definition: BlackDirectory.h:164
Definition: BlackDirectory.h:178
Definition: BlackDirectory.h:175
Definition: BlackDirectory.h:166
static long int getDirectorySize(std::string directoryPath)
Exports directory size in bytes.
Definition: BlackDirectory.cpp:92
std::string getApplicationDirectoryName()
Exports the application directory name.
Definition: BlackDirectory.cpp:203
static bool exists(std::string directoryPath)
Checks directory existence.
Definition: BlackDirectory.cpp:102
Definition: BlackDirectory.h:167
Definition: BlackDirectory.h:177
const std::string CURRENT_DIRECTORY_NOT_FOUND
If current directory could not find, function returns this.
Definition: BlackDirectory.h:51
Definition: BlackADC.cpp:36
static bool removeDirectory(std::string directoryPath, bool rmRecursively=false)
Removes directory.
Definition: BlackDirectory.cpp:231