-
Notifications
You must be signed in to change notification settings - Fork 12
/
FileName.cpp
155 lines (127 loc) · 3.43 KB
/
FileName.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// FileName.cpp: implementation of the CFileName class.
//
//////////////////////////////////////////////////////////////////////
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
#include "stdafx.h"
#include "FileName.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFileName::CFileName(CString szFileName)
{
m_szFileName = szFileName;
}
CFileName::~CFileName()
{
}
void CFileName::SetFileName(CString szFileName)
{
m_szFileName = szFileName;
}
/*****************************************************************
*
* Function: GetFileName()
*
* Purpose: Retrieves current filename minus the path
*
* Remarks: if the filename is "c:\incoming\hello.txt", this
* function returns "hello.txt".
*
******************************************************************/
CString CFileName::GetFileName()
{
CString szFileName;
_splitpath(m_szFileName, m_szDrive, m_szDir, m_szFname, m_szExt);
szFileName = m_szFname;
szFileName += m_szExt;
return szFileName;
}
/*****************************************************************
*
* Function: GetRoot()
*
* Purpose: Retrieves the path only of the current filename.
*
* Remarks: if the filename is "c:\incoming\hello.txt", this
* function returns "c:\incoming\".
*
******************************************************************/
CString CFileName::GetRoot()
{
CString szFileName;
_splitpath(m_szFileName, m_szDrive, m_szDir, m_szFname, m_szExt);
szFileName = m_szDrive;
szFileName += m_szDir;
return szFileName;
}
/*****************************************************************
*
* Function: GetFileTitle()
*
* Purpose: Retrieves the title of the filename excluding
* the path and extension.
*
* Remarks: if the filename is "c:\incoming\hello.txt", this
* function returns "hello".
*
******************************************************************/
CString CFileName::GetFileTitle()
{
CString szFileName;
_splitpath(m_szFileName, m_szDrive, m_szDir, m_szFname, m_szExt);
szFileName = m_szFname;
return szFileName;
}
/*****************************************************************
*
* Function: GetDescription()
*
* Purpose: Returns the description of the file
*
******************************************************************/
CString CFileName::GetDescription()
{
CString szTypeName;
SHFILEINFO sfi;
SHGetFileInfo(m_szFileName,
0,
&sfi,
sizeof(SHFILEINFO),
SHGFI_TYPENAME);
szTypeName = sfi.szTypeName;
return szTypeName;
}
/*****************************************************************
*
* Function: Exists()
*
* Purpose: Determines whether a file or directory exists.
*
******************************************************************/
bool CFileName::Exist()
{
WIN32_FIND_DATA fd;
CString szFindPath=m_szFileName;
int nSlash = szFindPath.ReverseFind('\\');
if( nSlash == szFindPath.GetLength()-1)
{
szFindPath = szFindPath.Left(nSlash);
}
HANDLE hFind = FindFirstFile( szFindPath, &fd );
if ( hFind != INVALID_HANDLE_VALUE )
{
FindClose( hFind );
}
return hFind != INVALID_HANDLE_VALUE;
}