-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcFuncFiles.cls
277 lines (207 loc) · 7.8 KB
/
cFuncFiles.cls
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cFuncFiles"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function MakeTempFile() As String
Dim sBuffer As String, sPath As String
Dim nCut As Integer
Dim dl As Long
sBuffer = Space$(MAX_PATH)
dl = GetTempPath(MAX_PATH, sBuffer)
If dl Then
sPath = Trim$(Mid$(sBuffer, 1, dl))
Else
sPath = App.Path
End If
sBuffer = Space$(MAX_PATH)
dl = GetTempFileName(App.Path, "pn_", 0, sBuffer)
nCut = InStr(1, sBuffer, Chr(0))
If nCut Then sBuffer = Trim$(Mid$(sBuffer, 1, nCut - 1))
If MyFuncFiles.FileExist(sBuffer) Then Kill sBuffer
MakeTempFile = sBuffer
End Function
Public Function VBArchivoSinPath(ByVal ArchivoConPath As String) As String
Dim k As Integer
Dim ret As String
ret = ""
For k = Len(ArchivoConPath) To 1 Step -1
If Mid$(ArchivoConPath, k, 1) = "\" Then
ret = Mid$(ArchivoConPath, k + 1)
Exit For
End If
Next k
VBArchivoSinPath = ret
End Function
Public Function VBGetTempPath() As String
Dim ret As String
ret = String(100, Chr$(0))
GetTempPath 100, ret
ret = Left$(ret, InStr(ret, Chr$(0)) - 1)
VBGetTempPath = ret
End Function
Public Function AppPathFile(sFileName As String) As String
Dim sFullName As String
sFullName = App.Path
If Right$(sFullName, 1) <> "\" Then sFullName = sFullName & "\"
AppPathFile = sFullName & sFileName
End Function
Function AttachPath(sFileName As String, sPath As String) As String
If Len(Trim(ExtractPath(sFileName))) = 0 Then
AttachPath = FixPath(sPath) & sFileName
Else
If InStr(1, sFileName, "\") = 0 Then
AttachPath = sFileName
Else
AttachPath = FixPath(sPath) & sFileName
End If
End If
End Function
Function FixPath(ByVal sPath As String) As String
If Len(Trim(sPath)) = 0 Then
FixPath = ""
ElseIf Right$(sPath, 1) <> "\" Then
FixPath = sPath & "\"
Else
FixPath = sPath
End If
End Function
Public Function PathArchivo(ByVal Archivo As String) As String
Dim k As Integer
Dim ret As String
ret = ""
For k = Len(Archivo) To 1 Step -1
If Mid$(Archivo, k, 1) = "\" Then
ret = Mid$(Archivo, 1, k)
Exit For
End If
Next k
PathArchivo = ret
End Function
Function ExtractFileName(sFileIn As String) As String
Dim i As Integer
For i = Len(sFileIn) To 1 Step -1
If InStr("\", Mid$(sFileIn, i, 1)) Then Exit For
Next
ExtractFileName = Mid$(sFileIn, i + 1, Len(sFileIn) - i)
End Function
Function ExtractPath(sPathIn As String) As String
Dim i As Integer
For i = Len(sPathIn) To 1 Step -1
If InStr(":\", Mid$(sPathIn, i, 1)) Then Exit For
Next
ExtractPath = Left$(sPathIn, i)
End Function
' Checks wether file exist (handles wildcards too)
Public Function FileExist(ByVal sFile As String) As Boolean
If Len(Trim(sFile)) = 0 Then
' Nothing given
FileExist = False
Exit Function
ElseIf Right(sFile, 1) = "\" Or Right(sFile, 1) = ":" Then
' Just a part of a path or drive... (not complete)
FileExist = False
Exit Function
ElseIf Dir(sFile) = "" Then
' Not there...
FileExist = False
Exit Function
End If
' After all that torture, it must exist...
FileExist = True
Exit Function
ExistErrorHandler:
FileExist = False
End Function
Public Function ExtractFileExt(sFileName As String) As String
Dim i As Integer
For i = Len(sFileName) To 1 Step -1
If InStr(".", Mid$(sFileName, i, 1)) Then Exit For
Next
ExtractFileExt = Right$(sFileName, Len(sFileName) - i)
End Function
Public Function VBGetFileSize(ByVal Archivo As String) As Double
Dim lngHandle As Long
Dim lRet As Double
Dim ret As Long
Dim of As OFSTRUCT
lngHandle = OpenFile(Archivo, of, 0&)
lRet = GetFileSize(lngHandle, ret)
CloseHandle lngHandle
VBGetFileSize = Round((lRet / 1024), 1)
End Function
'obtener la fecha de creacion del archivo
Public Function VBGetFileTime(ByVal Archivo As String) As String
Dim ret As String
Dim lngHandle As Long
Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME
Dim Fecha As String
Dim Hora As String
Dim of As OFSTRUCT
lngHandle = OpenFile(Archivo, of, 0&)
GetFileTime lngHandle, Ft1, Ft1, Ft2
FileTimeToLocalFileTime Ft2, Ft1
FileTimeToSystemTime Ft1, SysTime
CloseHandle lngHandle
Fecha = Format(Trim(Str$(SysTime.wDay)), "00") & "/" & Format(Trim$(Str$(SysTime.wMonth)), "00") + "/" + LTrim(Str$(SysTime.wYear))
Hora = Format(Trim(Str$(SysTime.wHour)), "00") & ":" & Format(Trim$(Str$(SysTime.wMinute)), "00") + ":" + LTrim(Str$(SysTime.wSecond))
VBGetFileTime = Fecha & " " & Hora
End Function
Public Function VBOpenFile(ByVal Archivo As String) As Boolean
On Local Error Resume Next
Dim ret As Boolean
Dim lRet As Long
Dim of As OFSTRUCT
Dim nFreeFile As Integer
ret = False
nFreeFile = FreeFile
Open Archivo For Input Shared As #nFreeFile
If Err = 0 Then
ret = True
Else
ret = False
End If
Close #nFreeFile
VBOpenFile = ret
End Function