xref: /MusicPlayer2/MusicPlayer2/FilePathHelper.h (revision 2e8d72ab3ca05f1f46348c86e45f5084fd48984e)
1 #pragma once
2 class CFilePathHelper
3 {
4 public:
5     CFilePathHelper(const wstring& file_path);
CFilePathHelper()6     CFilePathHelper(){}
7     ~CFilePathHelper();
8 
SetFilePath(const wstring & file_path)9     void SetFilePath(const wstring& file_path) { m_file_path = file_path; }
10 
11     // 获取文件的扩展名(upper:是否大写; width_dot:是否包含“.”)
12     wstring GetFileExtension(bool upper = false, bool width_dot = false) const;
13     // 获取文件名
14     wstring GetFileName() const;
15     // 获取文件名(不含扩展名)
16     wstring GetFileNameWithoutExtension() const;
17     // 获取文件夹名
18     wstring GetFolderName() const;
19     // 获取目录
20     wstring GetDir() const;
21     // 获取上级目录
22     wstring GetParentDir() const;
23     // 获取完整路径
GetFilePath()24     wstring GetFilePath() const { return m_file_path; }
25     // 替换文件的扩展名,返回文件完整路径
26     // 注意对不含扩展名的含“.”字符串使用可能会导致误识别
27     const wstring& ReplaceFileExtension(const wchar_t* new_extension);
28     // 获取文件路径(不含扩展名)
29     wstring GetFilePathWithoutExtension() const;
30 protected:
31     wstring m_file_path;
32 };
33 
34