home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / AA_File_de565532202002.psc / FilleOp.bas < prev    next >
Encoding:
BASIC Source File  |  2002-02-20  |  23.8 KB  |  701 lines

  1. Attribute VB_Name = "FileAccess"
  2. '***************************************
  3. '* Special Note on use:                *
  4. '* A reference must be made to the     *
  5. '* Microsoft Scripting Library for     *
  6. '* some of the functions to work.      *
  7. '***************************************
  8.  
  9. '**************************************************************************************
  10. '********************************** Private Declarations ******************************
  11. '**************************************************************************************
  12. Private Type SHFILEOPSTRUCT
  13.     hWnd As Long
  14.     wFunc As Long
  15.     pFrom As String
  16.     pTo As String
  17.     fFlags As Integer
  18.     fAnyOperationsAborted As Boolean
  19.     hNameMappings As Long
  20.     lpszProgressTitle As String
  21. End Type
  22.  
  23. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
  24. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
  25. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  26.  
  27. Private Const FO_DELETE = &H3
  28. Private Const FOF_ALLOWUNDO = &H40
  29. Private Const FOF_CREATEPROGRESSDLG As Long = &H0
  30. Public Enum RemoveMethod
  31.     RecycleFile = 1
  32.     DeleteFile = 2
  33. End Enum
  34.  
  35. Private FileObject As New FileSystemObject
  36. '***********************************************************************************
  37. '***********************declarations for LaunchWithDefaultApp***********************
  38. '***********************************************************************************
  39. #If Win32 Then
  40. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
  41.     (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
  42.     ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd _
  43.     As Long) As Long
  44.  
  45.  
  46. Private Declare Function GetDesktopWindow Lib "User32" () As Long
  47. #Else
  48.  
  49.  
  50. Declare Function ShellExecute Lib "SHELL" (ByVal hWnd%, _
  51.     ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _
  52.     ByVal lpszDir$, ByVal fsShowCmd%) As Integer
  53.  
  54.  
  55. Declare Function GetDesktopWindow Lib "USER" () As Integer
  56. #End If
  57. Private Const SW_SHOWNORMAL = 1
  58. 'End declaration for launchwithdefaultapp
  59.  
  60. '**************************************
  61. 'Windows API/Global Declarations for :Sy
  62. '     stem Folders
  63. '**************************************
  64.  
  65. Public Const CSIDL_DESKTOP = &H0
  66. Public Const CSIDL_PROGRAMS = &H2
  67. Public Const CSIDL_CONTROLS = &H3
  68. Public Const CSIDL_PRINTERS = &H4
  69. Public Const CSIDL_PERSONAL = &H5
  70. Public Const CSIDL_FAVORITES = &H6
  71. Public Const CSIDL_STARTUP = &H7
  72. Public Const CSIDL_RECENT = &H8
  73. Public Const CSIDL_SENDTO = &H9
  74. Public Const CSIDL_BITBUCKET = &HA
  75. Const CSIDL_STARTMENU = &HB
  76. Const CSIDL_DESKTOPDIRECTORY = &H10
  77. Const CSIDL_DRIVES = &H11
  78. Const CSIDL_NETWORK = &H12
  79. Const CSIDL_NETHOOD = &H13
  80. Const CSIDL_FONTS = &H14
  81. Const CSIDL_TEMPLATES = &H15
  82. Const MAX_PATH = 260
  83. Private Type SHITEMID
  84.     cb As Long
  85.     abID As Byte
  86. End Type
  87. Private Type ITEMIDLIST
  88.     mkid As SHITEMID
  89. End Type
  90. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
  91. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
  92.  
  93. '*perso test
  94. Public Type att
  95. Alias As Integer
  96. Archive As Integer
  97. System As Integer
  98. ReadOnly As Integer
  99. Volume As Integer
  100. Directory As Integer
  101. Hidden As Integer
  102. Normal As Integer
  103. End Type
  104. Global at As att
  105. '********************************************************************
  106.  
  107. '******broseforfolder api declaration
  108. Private Type BrowseInfo
  109.     hWndOwner As Long
  110.     pIDLRoot As Long
  111.     pszDisplayName As Long
  112.     lpszTitle As Long
  113.     ulFlags As Long
  114.     lpfnCallback As Long
  115.     lParam As Long
  116.     iImage As Long
  117. End Type
  118. Const BIF_RETURNONLYFSDIRS = 1
  119. 'Const MAX_PATH = 260
  120. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
  121. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
  122. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
  123. 'Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
  124. '******************************************************************************************************************************
  125.  
  126.  
  127. '****************GetIconFromFile decaration**************************
  128. Global Const DI_MASK = &H1
  129. Global Const DI_IMAGE = &H2
  130. Global Const DI_NORMAL = DI_MASK Or DI_IMAGE
  131. Public Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
  132. Public Declare Function DrawIconEx Lib "User32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
  133. Public Declare Function DestroyIcon Lib "User32" (ByVal hIcon As Long) As Long
  134. '********************************************************************
  135. Public Function GetIconFromFile(filename As String) As Long
  136.     GetIconFromFile = ExtractAssociatedIcon(App.hInstance, filename, 2)
  137. End Function
  138. Public Function BrowseFF() As String
  139.     
  140.     
  141.     Dim iNull As Integer, lpIDList As Long, lResult As Long
  142.     Dim sPath As String, udtBI As BrowseInfo
  143.     With udtBI
  144.         'Set the owner window
  145.         .hWndOwner = Form1.hWnd
  146.         'lstrcat appends the two strings and returns the memory address
  147.         .lpszTitle = lstrcat("C:\", "")
  148.         'Return only if the user selected a directory
  149.         .ulFlags = BIF_RETURNONLYFSDIRS
  150.     End With
  151.  
  152.     'Show the 'Browse for folder' dialog
  153.     lpIDList = SHBrowseForFolder(udtBI)
  154.     If lpIDList Then
  155.         sPath = String$(MAX_PATH, 0)
  156.         'Get the path from the IDList
  157.         SHGetPathFromIDList lpIDList, sPath
  158.         'free the block of memory
  159.         CoTaskMemFree lpIDList
  160.         iNull = InStr(sPath, vbNullChar)
  161.         If iNull Then
  162.             sPath = Left$(sPath, iNull - 1)
  163.         End If
  164.     End If
  165.  
  166.     BrowseFF = sPath
  167. End Function
  168.  
  169.  
  170.  
  171.  
  172.  
  173. '***********************************************************************************
  174. '****************************CODE***************************************************
  175. '***********************************************************************************
  176.  
  177.  
  178.  
  179.  
  180. '*** Launch With Default App ********************
  181. '* Iputs: VData - The name of the file          *
  182. '* purpose: !!                                  *
  183. '************************************************
  184. Public Function LaunchWithDefaultApp(VData As String) As Long
  185.       Dim Scr_hDC As Long
  186.       Dim Dire As String
  187.       Dire = Left(VData, 3)
  188.       Scr_hDC = GetDesktopWindow()
  189.       StartDoc = ShellExecute(Scr_hDC, "Open", VData, "", Dire, SW_SHOWNORMAL)
  190. End Function
  191.  
  192.  
  193.  
  194. '*** File Exists 1 and 2*************************
  195. '* Inputs: FileName - The name of the file.     *
  196. '* Returns: True if the file exists.            *
  197. '* Purpose: Tests whether or not a file exists. *
  198. '************************************************
  199. Public Function FileExists(filename As String) As Boolean
  200.     FileExists = Not (Dir(filename) = "")
  201. End Function
  202.  
  203. Private Function FileExists2(ByVal PathToCheck As String) As Boolean
  204.     'incovenients of the method:  Last access date and time will be changed to the current date and time
  205.     On Error GoTo MakeF
  206.         'If file does Not exist, there will be an Error
  207.         Open PathToCheck For Input As #1
  208.         Close #1
  209.         'no error, file exists
  210.         FileExists2 = True
  211.     Exit Function
  212. MakeF:
  213.         'error, file does Not exist
  214.         FileExists2 = False
  215.     Exit Function
  216. End Function
  217.  
  218. '*** Rename File ***************************************
  219. '* Inputs : This - file to be moved                    *
  220. '*          Tothis - Location to be moved              *
  221. '*          Description - working or not with...       *
  222. '*******************************************************
  223. Private Function Rename(This As String, ToThis As String, Optional Descript As Boolean = False) As Boolean
  224.     Select Case Descript
  225.             Case False
  226.                If FileExists(ToThis) Then
  227.                    If MsgBox(ToThis & " already exixts, dou you want to verwrite the destination file ? ", vbApplicationModal + vbCritical + vbYesNo, "Warning , Destinationfile allready exixts ! ") = vbYes Then
  228.                        Kill ToThis
  229.                        Name This As ToThis
  230.                    Else
  231.                    MsgBox " Opreation Cancelled", vbInformation + vbOKOnly
  232.                    End If
  233.                Else
  234.                    Name This As ToThis
  235.                End If
  236.             Case True
  237.                Name This As ToThis
  238.             End Select
  239. End Function
  240. '*** Get File Extension ********************************
  241. '* Inputs: FileName - The name of the file.            *
  242. '* Returns: The extension of the file as a string.     *
  243. '* Purpose: Finds the extension of the specified file. *
  244. '*******************************************************
  245. Public Function GetFileExt(filename As String) As String
  246.     Dim i As Integer
  247.     i = Len(filename)
  248.     While i > 1 And Mid$(filename, i, 1) <> "."
  249.         i = i - 1
  250.     Wend
  251.     If Mid$(filename, i, 1) = "." Then
  252.         GetFileExt = Right$(filename, Len(filename) - i)
  253.     ElseIf i = 0 Then
  254.         GetFileExt = ""
  255.     End If
  256. End Function
  257.  
  258.  
  259. '*** Get File Name ************************************
  260. '* Inputs: FileName - The name of the file.           *
  261. '* Returns: The name of the file (without extension). *
  262. '* Purpose: Finds the name of the specified file.     *
  263. '******************************************************
  264.  
  265. Public Function GetFileName(filename As String) As String
  266.     Dim i As Integer
  267.     i = Len(filename)
  268.     While i > 0 And Mid$(filename, i, 1) <> "\"
  269.         i = i - 1
  270.     Wend
  271.     If Mid$(filename, i, 1) = "\" Then
  272.         GetFileName = Right$(filename, Len(filename) - i)
  273.     ElseIf i = 0 Then
  274.         GetFileName = ""
  275.     End If
  276. End Function
  277. Public Function GetFnameWITHOUText(filename As String) As String
  278. Dim i As Integer
  279. i = Len(filename)
  280. While i > 1 And Mid$(filename, i, 1) <> "."
  281. i = i - 1
  282. Wend
  283. If Mid$(filename, i, 1) = "." Then
  284.     GetFnameWITHOUText = Left(filename, i - 1)
  285. ElseIf i = 0 Then
  286.     GetFnameWITHOUText = "Error"
  287. End If
  288.  
  289.  
  290. End Function
  291.  
  292. '*** Remove File ******************************
  293. '* Inputs: FileName - The name of the file.   *
  294. '*         Action - The method of deletion.   *
  295. '* Purpose: Deletes a file or moves it to the *
  296. '*          recycle bin.                      *
  297. '* Notes: Possible values for "Action:"       *
  298. '*        RecycleFile - Moves the file to the *
  299. '*                      recycle bin.          *
  300. '*        DeleteFile - Deletes the file.      *
  301. '*        Both of these methods displays a    *
  302. '*        confirmation prompt to the user.    *
  303. '**********************************************
  304. Public Function RemoveFile(filename As String, Action As RemoveMethod) As Boolean
  305.     Dim FileOperation As SHFILEOPSTRUCT
  306.     Dim tmpReturn As Long
  307.     On Error GoTo RemoveFile_Err
  308.     With FileOperation
  309.         .wFunc = FO_DELETE
  310.         .pFrom = filename
  311.         If Action = RecycleFile Then
  312.             .fFlags = FOF_ALLOWUNDO + FOF_CREATEPROGRESSDLG
  313.         Else
  314.             .fFlags = FO_DELETE + FOF_CREATEPROGRESSDLG
  315.         End If
  316.     End With
  317.     tmpReturn = SHFileOperation(FileOperation)
  318.     If tmpReturn <> 0 Then
  319.         RemoveFile = False
  320.     Else
  321.         RemoveFile = True
  322.     End If
  323.     Exit Function
  324. RemoveFile_Err:
  325.     RemoveFile = False
  326. End Function
  327.  
  328.  
  329. '*** Create Directory ***************************
  330. '* Inputs: DirName - The name of the directory. *
  331. '* Purpose: Creates the specified directory.    *
  332. '************************************************
  333. Public Sub CreateDir(DirName As String)
  334. On Error GoTo ErrH
  335.  
  336.     Call FileObject.CreateFolder(DirName)
  337.     GoTo fin
  338. ErrH:
  339. If Err.Number = 58 Then Err.Clear Else MsgBox Err.Description
  340. Err.Clear
  341. fin:
  342. End Sub
  343.  
  344.  
  345. '*** Delete Directory *******************************
  346. '* Inputs: DirName - The name of the directory.     *
  347. '* Purpose: Deletes the specified directory.        *
  348. '* Notes: It does not prompt for user confirmation. *
  349. '*        The data within the directory is also     *
  350. '*        deleted and not moved to the recycle bin. *
  351. '****************************************************
  352. Public Sub DeleteDir(DirName As String)
  353.     Call FileObject.DeleteFolder(DirName, True)
  354. End Sub
  355.  
  356.  
  357. '*** Create Temporary File *********************
  358. '* Inputs: none                                *
  359. '* Returns: The name of the temporary file as  *
  360. '*          a string.                          *
  361. '* Purpose: Generates a unique name to be used *
  362. '*          for a temporary file name.         *
  363. '***********************************************
  364. Public Function CreateTemp() As String
  365.     CreateTemp = FileObject.GetTempName
  366. End Function
  367.  
  368. '*** Get and Set attributes of o file ****************
  369. '*                                                   *
  370. '*****************************************************
  371. Public Function GetAttributes(OfThis As String) As String
  372. Dim Tmp As VbFileAttribute
  373. Tmp = GetAttr(OfThis)
  374. With at
  375. .Alias = 0
  376. .Archive = 0
  377. .Directory = 0
  378. .Hidden = 0
  379. .Normal = 0
  380. .ReadOnly = 0
  381. .System = 0
  382. .Volume = 0
  383. End With
  384.  
  385. If Tmp >= vbAlias Then '64
  386.     GetAttributes = GetAttributes & " Alias"
  387.     Tmp = Tmp - vbAlias
  388.     at.Alias = 1
  389. End If
  390. If Tmp >= vbArchive Then ' 32
  391.     GetAttributes = GetAttributes & " Archive"
  392.     Tmp = Tmp - vbArchive
  393.     at.Archive = 1
  394.     End If
  395. If Tmp >= vbDirectory Then '16
  396.     GetAttributes = GetAttributes & " directory"
  397.     Tmp = Tmp - vbDirectory
  398.     at.Directory = 1
  399. End If
  400. If Tmp >= vbVolume Then '8
  401.     GetAttributes = GetAttributes & " volume"
  402.     Tmp = Tmp - vbVolume
  403.     at.Volume = 1
  404.     End If
  405.  
  406. If Tmp >= vbSystem Then '4
  407.     GetAttributes = GetAttributes & " System"
  408.     Tmp = Tmp - vbSystem
  409.     at.System = 1
  410. End If
  411. If Tmp >= vbHidden Then '2
  412.     GetAttributes = GetAttributes & " Hidden"
  413.     Tmp = Tmp - vbHidden
  414.     at.Hidden = 1
  415. End If
  416. If Tmp >= vbReadOnly Then '1
  417.     GetAttributes = GetAttributes & " Read Only"
  418.     Tmp = Tmp - vbReadOnly
  419.     at.ReadOnly = 1
  420. End If
  421. If Tmp = vbNormal Then '0
  422.     GetAttributes = GetAttributes & " Normal"
  423.     Tmp = Tmp - vbNormal
  424.     at.Normal = 1
  425. End If
  426.  
  427.  
  428. End Function
  429. Public Function SetAttributes(OfThis As String, ByVal ToThis As VbFileAttribute) As Boolean
  430.  SetAttributes = True
  431.  On Error GoTo ErrH
  432.   SetAttr OfThis, ToThis
  433.  GoTo fin
  434. ErrH:
  435.  SetAttributes = False
  436.  Err.Clear
  437.  Exit Function
  438. fin:
  439.  SetAttributes = True
  440. End Function
  441.  
  442.  
  443. '*** Write INI ***************************************
  444. '* Inputs: SectionName - The name of the section     *
  445. '*         to write to.                              *
  446. '*         KeyName - The name of the key to write.   *
  447. '*         KeyValue - The value to write to the key. *
  448. '*         FileName - The name of the INI file to    *
  449. '*         write to.                                 *
  450. '* Purpose: Writes the specified value and name to   *
  451. '*          an INI file.                             *
  452. '* Notes: This function is included for Win16        *
  453. '*        compatability only.  Whenever possible,    *
  454. '*        data should be written to the              *
  455. '*        registry instead.                          *
  456. '*****************************************************
  457. Public Sub WriteINI(SectionName As String, KeyName As String, KeyValue As String, filename As String)
  458.     WritePrivateProfileString SectionName, KeyName, KeyValue, filename
  459. End Sub
  460.  
  461.  
  462. '*** Read INI *************************************
  463. '* Inputs: SectionName - The name of the section  *
  464. '*         from which to read.                    *
  465. '*         KeyName - The name of the key whose    *
  466. '*         value is to be read.                   *
  467. '*         FileName - The name of the INI file.   *
  468. '* Returns: The value of the specified key name.  *
  469. '* Purpose: Reads a value from an INI file.       *
  470. '* Notes: This function is included for Win16     *
  471. '*        compatability only.  Whenever possible, *
  472. '*        data should be written to the           *
  473. '*        registry instead.                       *
  474. '*        If the key was not found, the string    *
  475. '*        "NOT FOUND" is returned.                *
  476. '**************************************************
  477. Public Function ReadINI(SectionName As String, KeyName As String, filename As String) As String
  478.     Dim tmpBuffer As String * 255
  479.     GetPrivateProfileString SectionName, KeyName, "NOT FOUND", tmpBuffer, Len(tmpBuffer), filename
  480.     ReadINI = tmpBuffer
  481. End Function
  482.  
  483.  
  484. Private Function IsPathValid(ThisFile As String) As Long
  485.     Dim lngPos As Long 'Declare container For postion of "\"
  486.     Dim lngTemp As Long 'Declare a Temporary long Container For comparason
  487.     Dim intLoop As Integer 'Declare container To work as counter
  488.     Dim arrChars(21) As String 'Declare container For invalid charactors in path
  489.     '---------------------------------------
  490.     '     -----------------------------
  491.     'Return Values And Descriptions
  492.     '0 = No path set
  493.     '1 = Valid Path set
  494.     '2 = Invalid Charactor Found
  495.     '3 = Invalid ":" found after second char
  496.     '     of path
  497.     '4 = Invalid "\\" found after second cha
  498.     '     r of path
  499.     '5 = No Drive assignment Found and Not a
  500.     '     UNC Path
  501.     '6 = Valid Drive letter found but no "\"
  502.     '     preceding ":"
  503.     '---------------------------------------
  504.     '     -----------------------------
  505.     'assign invalid charactors to array
  506.     arrChars(0) = "'"
  507.     arrChars(1) = """"
  508.     arrChars(2) = "("
  509.     arrChars(3) = ")"
  510.     arrChars(4) = "!"
  511.     arrChars(5) = "@"
  512.     arrChars(6) = "#"
  513.     arrChars(7) = "%"
  514.     arrChars(8) = "^"
  515.     arrChars(9) = "&"
  516.     arrChars(10) = "*"
  517.     arrChars(11) = "+"
  518.     arrChars(12) = "="
  519.     arrChars(13) = "<"
  520.     arrChars(14) = ">"
  521.     arrChars(15) = "?"
  522.     arrChars(16) = "/"
  523.     arrChars(17) = "."
  524.     arrChars(18) = ","
  525.     arrChars(19) = "`"
  526.     arrChars(20) = ";"
  527.  
  528.  
  529.     If Len(ThisFile) = 0 Then 'if length of Property is zero return an Error value
  530.         IsPathValid = 0
  531.         'clean out variables to conserve memory
  532.         '     use
  533.         GoTo ExitThisFunction
  534.     End If
  535.  
  536.  
  537.     For intLoop = 0 To 20 Step 1 'loop through array
  538.         lngPos = InStr(1, ThisFile, arrChars(intLoop), vbBinaryCompare) 'Check For invalid charactor in String
  539.  
  540.  
  541.         If lngPos > 0 Then 'if found then return Error value
  542.             IsPathValid = 2
  543.             'clean out variables to conserve memory
  544.             '     use
  545.             GoTo ExitThisFunction
  546.         End If
  547.     Next intLoop
  548.     lngTemp = 1 'set Comparason starting point
  549.     lngPos = InStr(1, ThisFile, ":", vbBinaryCompare) 'check For correct drive letter syntax
  550.  
  551.  
  552.     Select Case lngPos
  553.         Case Is = 1, Is >= 3 'invalid drive letter syntax found return Error value
  554.         IsPathValid = 3
  555.         'clean out variables to conserve memory
  556.         '     use
  557.         GoTo ExitThisFunction
  558.         Case Is = 0 'No Drive letter assignment found check To see If unc path
  559.  
  560.  
  561.         For intLoop = 1 To Len(ThisFile) Step 1 'set counter to step through Each charactor in String
  562.             lngPos = InStr(intLoop, ThisFile, "\", vbBinaryCompare) 'check For directory delimiter
  563.  
  564.  
  565.             If lngPos > 0 Then 'value found so check that it is Single
  566.  
  567.  
  568.                 If intLoop > 1 Then 'Starting values With "\\" are acceptable as unc paths
  569.  
  570.  
  571.                     If lngPos > 2 And (lngPos - 1) = lngTemp Then 'any other location In the String With "\\" is invalid
  572.                         IsPathValid = 4 'return Error value
  573.                         'clean out variables to conserve memory
  574.                         '     use
  575.                         GoTo ExitThisFunction
  576.                     End If
  577.                 End If
  578.             Else
  579.  
  580.  
  581.                 If intLoop = 1 Or intLoop = 2 Then 'Must have at least "//" as first 2 charactors to be valid unc path
  582.                     IsPathValid = 5 'return Error value
  583.                     'clean out variables to conserve memory
  584.                     '     use
  585.                     GoTo ExitThisFunction
  586.                 End If
  587.             End If
  588.             lngTemp = lngPos 'increment temp value
  589.         Next intLoop 'increment counter
  590.         Case Is = 2
  591.         'check rest of string for "\\"
  592.         lngTemp = 1 'set Comparason starting point
  593.  
  594.  
  595.         For intLoop = 3 To Len(ThisFile) Step 1 'set counter to step through Each charactor in String
  596.             lngPos = InStr(intLoop, ThisFile, "\", vbBinaryCompare) 'check For directory delimiter
  597.  
  598.  
  599.             If lngPos > 0 Then 'value found so check that it is Single
  600.  
  601.  
  602.                 If lngPos > 3 And (lngPos - 1) = lngTemp Then 'any other location In the String With "\\" is invalid
  603.                     IsPathValid = 4 'return Error value
  604.                     'clean out variables to conserve memory
  605.                     '     use
  606.                     GoTo ExitThisFunction
  607.                 End If
  608.             Else
  609.  
  610.  
  611.                 If intLoop = 3 Then 'must have a "/" following drive letter To be valid path
  612.                     IsPathValid = 6 'return Error value
  613.                     'clean out variables to conserve memory
  614.                     '     use
  615.                     GoTo ExitThisFunction
  616.                 End If
  617.             End If
  618.             lngTemp = lngPos 'increment temp value
  619.         Next intLoop 'increment counter
  620.     End Select
  621. IsPathValid = 1 'path passes checks return valid value
  622. 'clean out variables to conserve memory
  623. '     use
  624. ExitThisFunction:
  625. lngPos = vbNull
  626. intLoop = vbNull
  627. lngTemp = vbNull
  628. Erase arrChars
  629. End Function
  630.  
  631.  
  632. Public Function GetSpecialfolder(CSIDL As Long) As String
  633.     Dim r As Long
  634.     Dim IDL As ITEMIDLIST
  635.     'Get the special folder
  636.     r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
  637.     If r = NOERROR Then
  638.         'Create a buffer
  639.         Path$ = SPACE$(512)
  640.         'Get the path from the IDList
  641.         r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
  642.         'Remove the unnecessary chr$(0)'s
  643.         GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
  644.         Exit Function
  645.     End If
  646.     GetSpecialfolder = ""
  647. End Function
  648.  
  649. Public Function GetFileSize(filename) As String
  650. Dim s As Double
  651. Dim st As String
  652. s = FileLen(filename) / 1024
  653. s = s / 1024
  654. st = "Mb"
  655.  If s > 1 Then
  656.  GoTo ok
  657.  Else
  658.  s = s * 1024
  659.  st = "Kb"
  660.  End If
  661.  If s > 1 Then
  662.  GoTo ok
  663.  Else
  664.  s = s * 1024
  665.  st = "b"
  666.  End If
  667.  
  668. ok:
  669.  GetFileSize = Round(s, 2) & st
  670. fin:
  671. End Function
  672. Public Function GetFileDate(filename As String) As String
  673.     On Error Resume Next
  674.     GetFileDate = FileDateTime(filename)
  675. End Function
  676. Public Function PutInRecycle(ParamArray vntFileName() As Variant) As Boolean
  677.    Dim i As Integer
  678.    Dim sFileNames As String
  679.    Dim SHFileOp As SHFILEOPSTRUCT
  680.  
  681.    For i = LBound(vntFileName) To UBound(vntFileName)
  682.       sFileNames = sFileNames & vntFileName(i) & vbNullChar
  683.    Next
  684.         
  685.    sFileNames = sFileNames & vbNullChar
  686.  
  687.    With SHFileOp
  688.       .wFunc = FO_DELETE
  689.       .pFrom = sFileNames
  690.       .fFlags = FOF_ALLOWUNDO + FOF_SILENT + FOF_NOCONFIRMATION
  691.    End With
  692.  
  693.    i = SHFileOperation(SHFileOp)
  694.    
  695.    If i = 0 Then
  696.       PutInRecycle = True
  697.    Else
  698.       PutInRecycle = False
  699.    End If
  700. End Function
  701.