KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVSystemDirectory.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Mon Sep 24 10:45:52 2012
2 //Author: John Frankland,,,
3 
4 #include "KVSystemDirectory.h"
5 #include "TSystem.h"
6 #include "TList.h"
7 #include "TROOT.h"
8 #include "KVSystemFile.h"
9 #include <iostream>
10 
12 
13 
14 
15 
19 {
20  // Default constructor
21  fContents = 0;
22  fSubdirs = 0;
23  fTotFiles = 0;
24  fTotDirs = 0;
25 }
26 
27 
28 
33 
35  : TSystemDirectory(dirname, path)
36 {
37  // Constructor with name for directory and path.
38  // Path can be given as "." for current working directory.
39  // Shell variables can be used if written as "$(VARIABLE)"
40  fContents = 0;
41  fSubdirs = 0;
42  fTotFiles = 0;
43  fTotDirs = 0;
44  TString Path = path;
45  if (Path == ".") Path = "$(PWD)";
46  gSystem->ExpandPathName(Path);
47  SetTitle(Path);
48  GetListings();
49 }
50 
51 
52 
53 
56 
58 {
59  // Destructor
62 }
63 
64 
65 
70 
72 {
73  // Returns a TList of KVSystemFile objects representing the contents
74  // of the directory.
75  // Returns 0 in case of errors.
76 
77  return fContents;
78 }
79 
80 
81 
86 
88 {
89  // Returns a TList of KVSystemDirectory objects representing the contents
90  // of the directory.
91  // Returns 0 in case of errors.
92 
93  return fSubdirs;
94 }
95 
96 
97 
100 
102 {
103  // Fill lists of files and directories
104 
105  void* dir = gSystem->OpenDirectory(GetTitle());
106  if (!dir) {
107  Error("GetListings", "Cannot open directory %s", GetTitle());
108  return;
109  }
110 
111  const char* file = 0;
112  fContents = new TList;
113  fContents->SetOwner();
114  fSubdirs = new TList;
115  fSubdirs->SetOwner();
116  while ((file = gSystem->GetDirEntry(dir))) {
117  if (IsItDirectory(file)) {
118  TString sdirpath = "";
119  if (file[0] == '.' && file[1] == '\0')
120  continue;
121  else if (file[0] == '.' && file[1] == '.' && file[2] == '\0')
122  continue;
123  else {
124  sdirpath = GetTitle();
125  if (!sdirpath.EndsWith("/"))
126  sdirpath += "/";
127  sdirpath += file;
128  }
129  if (sdirpath != "") {
130  KVSystemDirectory* sd = new KVSystemDirectory(file, sdirpath.Data());
131  fSubdirs->Add(sd);
132  fTotDirs += sd->GetTotalSize();
133  }
134  }
135  else {
136  KVSystemFile* sf = new KVSystemFile(file, GetTitle());
137  fContents->Add(sf);
138  fTotFiles += sf->GetSize();
139  }
140  }
141  gSystem->FreeDirectory(dir);
142 }
143 
144 
145 
149 
151 {
152  // if opt="nosubdirs", do not list contents of subdirectories
153  // default is to list recursively contents of all subdirectories
154 
156  printf("%s :\n[total : %lld / files : %lld bytes]\n\n",
160  GetListOfFiles()->R__FOR_EACH(KVSystemFile, ls)();
161  if (!strcmp(opt, "nosubdirs")) {
162  TIter next(GetListOfDirectories());
163  KVSystemDirectory* sd;
164  while ((sd = (KVSystemDirectory*)next())) {
166  printf("%-60s [total : %lld / files : %lld bytes]\n",
167  sd->GetTitle(), sd->GetTotalSize(), sd->GetTotalFiles());
168  }
169  }
170  else {
171  GetListOfDirectories()->R__FOR_EACH(KVSystemDirectory, ls)();
172  }
175  printf("\n");
176 }
177 
178 
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define SafeDelete(p)
char Char_t
const char Option_t
R__EXTERN TSystem * gSystem
Extension of ROOT TSystemDirectory class, handling browsing directories on disk.
KVSystemDirectory()
Default constructor.
virtual TList * GetListOfDirectories() const
Long64_t fTotFiles
total size of files in directory
void ls(Option_t *option="") const
TList * fSubdirs
subdirectories of directory
Long64_t fTotDirs
total size of files in subdirectories
TList * fContents
contents of directory
Long64_t GetTotalFiles() const
virtual void GetListings()
Fill lists of files and directories.
Long64_t GetTotalSize() const
virtual ~KVSystemDirectory()
Destructor.
virtual TList * GetListOfFiles() const
Extended ROOT TSystemFile with added info on file size etc.
Definition: KVSystemFile.h:17
Long64_t GetSize() const
Definition: KVSystemFile.h:39
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Add(TObject *obj)
virtual const char * GetTitle() const
virtual void Error(const char *method, const char *msgfmt,...) const
static Int_t IncreaseDirLevel()
static void IndentLevel()
static Int_t DecreaseDirLevel()
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
Bool_t IsItDirectory(const char *name) const
void SetTitle(const char *title)
virtual void FreeDirectory(void *dirp)
virtual void * OpenDirectory(const char *name)
virtual const char * GetDirEntry(void *dirp)
virtual char * ExpandPathName(const char *path)