|
Help on the FileSystemObject - part of a library to work with the Windows File System.
Example Functions: mshShowDriveList
Notes by Stephen Rasey:In the Visual Basic Editor: Goto Tools, Refrences.....
Dim fso as New FileSystemObject
Dim strFolderPath as string
Dim strFullPath as string
strFolderPath = "D:\data\case2" 'a valid path
strFolderPath = "D:\data\case2\" 'a valid path can end in a "\"
strFullPath = strFolderPath & "\" & "WantedFile.txt"
If fso.folderexists(FolderPath) then
If fso.FileExists(strFullPath) Then
'OK to access strFullPath
Else
'Folder Exists, but file not found
End IF
Else
'Folder cannot be found
End if
'Alternative Method of creating FSO
Dim fso as object
Set fso = CreateObject("Scripting.FileSystemObject")
Sub TestFSOproperty()
Dim fso As New FileSystemObject 'Reference: Microsoft Scripting Runtime.
Dim vout As Variant
'Folder and Path Tools
'v = fso.CopyFolder(strSource, strDestPath, [bOverWrite])
'asFolder = fso.CreateFolder(strPath)
'v = fso.DeleteFolder(strFolderSpec, [bBForce])
'bol = fso.FolderExists(strFolderSpec)
'strAbsPath = fso.GetAbsolutePathName(strPath)
'asStr = fso.BuildPath(Path, Name) 'Path does not need to exist.
'asFolder = fso.GetFolder(strFolderPath)
'strPathParent = fso.GetParentFolderName(strPath) 'Does not check for existance.
'asfolder = fso.GetSpecialFolder(i) 'i=0 (Windows Opsys Folder, =1 System, 2=Temp)
'v = fso.MoveFolder(StrSource, strDestPath)
'File & Filename tools
'v = fso.DeleteFile(strFileSpec, [bForce]) 'Force = True will delete ReadOnly.
'bol = fso.FileExists(strFileSpec)
'strBase = fso.GetBaseName(Path) 'Returns the filename part of the FullPath w/o extension.
'vout = fso.GetBaseName("D:\data\case2\0409\xxx.xls") 'returns "xxx" Existance is not tested.
'strExt = fso.GetExtensionName(strPath)
'asFile = fso.GetFile(FilePath) 'error if not exist.
'strNameAndExt = fso.GetFileName(strPath) 'Does not check existance.
'vout = fso.GetFileName("D:\data\case2\0409\xxx.xls") 'returns "xxx.xls"
'v = fso.CopyFile(strSource, strDestPath, [bOverWrite])
'v = fso.MoveFile(Source, strDestPath) 'Wildcards in source's last component only.
'No wildcards in strDestPath.
'If Source has wildcards or DestPath ends in "\",
'then Dest is treated as a FOLDER.
'Stops on first error, no rollback.
'File Properties
'strVersion = fso.GetFileVersion(strPath)
'Drive tools 'bol = fso.DriveExists(strDriveSpec) 'Or (strFileSpec) 'DriveCollection = fso.Drives(Item(Key)) ' MS VBA help show no arguments. 'drive1 = fso.GetDrive(strDriveSpec) 'str1 = fso.GetDriveName(strPath) 'Does not check for existance. 'TextStream functions. 'asTextStream = fso.GetStandardStream(standardStreamType, [bunicode]) 'AsTextStream = fso.CreateTextFile(strFilename, bOverWrite, bUnicode) 'strFileName = fso.GetTempName 'generates random name for a temp File. Use with CreateTextFile 'asTextStream=fso.OpenTextFile(strFilePath, [ForAppendReadWrite], bCreate, FormatTristate]) Set fso = Nothing End Sub Code Examples (Public Domain or Fair Use)
|
For questions or comments concerning content on this
website: Stephen Rasey |