/[tivodecode]/t2sami/trunk/Utility.cpp
ViewVC logotype

Diff of /t2sami/trunk/Utility.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 256 by jeremyd2019, Sun Apr 1 04:46:08 2007 UTC revision 257 by jeremyd2019, Tue Dec 27 08:17:02 2011 UTC
# Line 31  Line 31 
31  #endif  #endif
32  #include <string>  #include <string>
33  #include "Utility.h"  #include "Utility.h"
34    #define BOOST_FILESYSTEM_VERSION 3
35  #include <boost/filesystem/path.hpp>  #include <boost/filesystem/path.hpp>
36  #include <boost/filesystem/operations.hpp>  #include <boost/filesystem/operations.hpp>
37  #include <boost/filesystem/convenience.hpp>  #include <boost/filesystem/convenience.hpp>
# Line 41  namespace bfs = boost::filesystem; Line 42  namespace bfs = boost::filesystem;
42  // Returns the directory location corresponding to some path  // Returns the directory location corresponding to some path
43  std::string GetFileDirFromPath(const char *tszPath)  std::string GetFileDirFromPath(const char *tszPath)
44  {  {
45          bfs::path path = bfs::path(tszPath, bfs::native);          bfs::path path = bfs::path(tszPath);
46          return path.branch_path().native_file_string();          return path.parent_path().string();
47  }  }
48    
49  // Returns the filename from the supplied path  // Returns the filename from the supplied path
50  std::string GetFileNameFromPath(const char *tszPath)  std::string GetFileNameFromPath(const char *tszPath)
51  {  {
52          bfs::path path = bfs::path(tszPath, bfs::native);          bfs::path path = bfs::path(tszPath);
53          return path.leaf();          return path.filename().string();
54  }  }
55    
56  // Returns the filetitle from the supplied path  // Returns the filetitle from the supplied path
57  std::string GetFileTitleFromPath(const char *tszPath)  std::string GetFileTitleFromPath(const char *tszPath)
58  {  {
59          bfs::path path = bfs::path(tszPath, bfs::native);          bfs::path path = bfs::path(tszPath);
60          std::string fname = path.leaf();          std::string fname = path.filename().string();
61          std::string::size_type lastdot = fname.rfind('.');          std::string::size_type lastdot = fname.rfind('.');
62          if (lastdot != std::string::npos)          if (lastdot != std::string::npos)
63          {          {
# Line 68  std::string GetFileTitleFromPath(const char *tszPath) Line 69  std::string GetFileTitleFromPath(const char *tszPath)
69  // Returns the file extension from the supplied path  // Returns the file extension from the supplied path
70  std::string GetFileExtFromPath(const char *tszPath)  std::string GetFileExtFromPath(const char *tszPath)
71  {  {
72          bfs::path path = bfs::path(tszPath, bfs::native);          bfs::path path = bfs::path(tszPath);
73          std::string fname = path.leaf();          std::string fname = path.filename().string();
74          std::string::size_type lastdot = fname.rfind('.');          std::string::size_type lastdot = fname.rfind('.');
75          if (lastdot != std::string::npos)          if (lastdot != std::string::npos)
76          {          {
# Line 80  std::string GetFileExtFromPath(const char *tszPath) Line 81  std::string GetFileExtFromPath(const char *tszPath)
81    
82  std::string ExtractFilePath(std::string FileName)  std::string ExtractFilePath(std::string FileName)
83  {  {
84          bfs::path path = bfs::path(FileName, bfs::native);          bfs::path path = bfs::path(FileName);
85          return path.branch_path().native_file_string();          return path.parent_path().string();
86  }  }
87    
88  std::string ConcatPaths(const std::string & dir_name, const std::string & file_name)  std::string ConcatPaths(const std::string & dir_name, const std::string & file_name)
89  {  {
90          bfs::path dir_path (dir_name, bfs::native),          bfs::path dir_path (dir_name),
91                  file_path (file_name, bfs::native);                  file_path (file_name);
92          return (dir_path / file_path).native_file_string();          return (dir_path / file_path).string();
93  }  }
94    
95  bool IsFileNameValid(const char * lpFileName)  bool IsFileNameValid(const char * lpFileName)
# Line 99  bool IsFileNameValid(const char * lpFileName) Line 100  bool IsFileNameValid(const char * lpFileName)
100    
101  bool MakeSureDirectoryPathExists(std::string Dir)  bool MakeSureDirectoryPathExists(std::string Dir)
102  {  {
103          bfs::path pth = bfs::path(Dir, bfs::native).branch_path();          bfs::path pth = bfs::path(Dir).parent_path();
104          if (bfs::exists(pth))          if (bfs::exists(pth))
105          {          {
106                  if (bfs::is_directory(pth))                  if (bfs::is_directory(pth))
# Line 117  bool MakeSureDirectoryPathExists(std::string Dir) Line 118  bool MakeSureDirectoryPathExists(std::string Dir)
118    
119  bool DirectoryExists(const std::string Name)  bool DirectoryExists(const std::string Name)
120  {  {
121          bfs::path pth (Name, bfs::native);          bfs::path pth (Name);
122          return bfs::exists(pth) && bfs::is_directory(pth);          return bfs::exists(pth) && bfs::is_directory(pth);
123  }  }
124    

Legend:
Removed from v.256  
changed lines
  Added in v.257

cvs@jdrake.com
ViewVC Help
Powered by ViewVC 1.1.13