Solved

Wsh2 & Ruchi

Posted on 2000-04-01
11
323 Views
Last Modified: 2008-03-06
Hello Wsh2 & Ruchi
How do you use a FileSystemObject to create directories, drives, files, folders? Including a file object and folder object to gather information about the files, folders, so on. EG. Last Modified, Path, Size, so on.
Thanx,
Robinson
0
Comment
Question by:vbrobinson
11 Comments
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
I hope you don't go blind.. <LOL>
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
From MSDN:
----------------------------------------
Programming in the FSO Object Model


Programming in the FSO object model involves three main tasks:

1. Using the CreateObject method, or dimension a variable as a FileSystemObject object to create a FileSystemObject object.

2. Using the appropriate method on the newly-created object.

3. Accessing the object's properties.

The FSO object model is contained in a type library called Scripting, which is located in the file Scrrun.Dll. If you don't already have a reference to it, check "Microsoft Scripting Runtime" in the References dialog available from the Properties menu. You can then use the Object Browser to view its objects, collections, properties, methods, and events, as well as its constants.

----------------------------------
1. Creating a FileSystemObject Object

The first step is to create a FileSystemObject object to work with. You can do this in two ways:

Dimension a variable as type FileSystemObject object:
Dim fso As New FileSystemObject

Use the CreateObject method to create a FileSystemObject object:
Set fso = CreateObject("Scripting.FileSystemObject")

In the above syntax, Scripting is the name of the type library, and FileSystemObject is the name of the object which you want to create an instance of.

Note: The first method works only in Visual Basic, while the second method works either in Visual Basic or VBScript.

------------------------------
2. Using the Appropriate Method

The next step is to use the appropriate method of the FileSystemObject object. For example, if you want to create a new object, you can use either CreateFolder or CreateTextFile. (The FSO object model doesn't support the creation or deletion of drives.)

If you want to delete objects, you can use the DeleteFile and DeleteFolder methods of the FileSystemObject object, or the Delete method of the File and Folder objects.

Using the appropriate methods, you can also copy and move files and folders.

Note that some functionality in the FileSystemObject object model is redundant. For example, you can copy a file using either the CopyFile method of the FileSystemObject object, or you can use the Copy method of the File object. The methods work the same. Both exist to give you maximum programming flexibility.

------------------------------------------------------------
3a. Accessing Existing Drives, Files, and Folders

To gain access to an existing drive, file, or folder, use the appropriate "get" method of the FileSystemObject object:

GetDrive

GetFolder

GetFile

For example:

Dim fso As New FileSystemObject, fil As File
Set fil = fso.GetFile("c:\test.txt")

Note, however, that you don't need to use the "get" methods for newly-created objects, since the "create" functions already return a handle to the newly-created object. For example, if you create a new folder using the CreateFolder method, you don't then need to use the GetFolder method to access its properties, such as Name, Path, Size, and so forth. Just set a variable to the CreateFolder function to gain a handle to the newly-created folder, then access its properties, methods, and events:

Private Sub Create_Folder()
   Dim fso As New FileSystemObject, fldr As Folder
   Set fldr = fso.CreateFolder("C:\MyTest")
   MsgBox "Created folder: " & fldr.Name
End Sub

-----------------------------------
3b. Accessing the Object's Properties

Once you have a handle to an object, you can access its properties. For example, say you want to obtain the name of a particular folder. First you create an instance of the object, then you get a handle to it with the appropriate method (in this case, the GetFolder method, since the folder already exists):

Set fldr = fso.GetFolder("c:\")

Now that you have a handle to a Folder object, you can check its Name property:

Debug.Print "Folder name is: "; fldr.Name

If you want to find out the last time a file was modified, use the following syntax:

Dim fso As New FileSystemObject, fil As File
Set fil = fso.GetFile("c:\detlog.txt")  ' Get a File object to query.
Debug.Print "File last modified: "; fil.DateLastModified ' Print info.
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
From MSDN:
---------------------------------------
The FSO object model has these objects:

Drive:
Allows you to gather information about drives attached to the system, such as how much room is available, what its share name is, and so forth. Note that a "drive" isn't necessarily a hard disk. It can be a CD-ROM drive, a RAM disk, and so forth. Also, drives aren't required to be physically attached to the system; they can be also be logically connected through a LAN.

Folder:
Allows you to create, delete, or move folders, plus query the system as to their names, paths, and so on.

File:
Allows you to create, delete, or move files, plus query the system as to their names, paths, and so on.

FileSystemObject:
The main object of the group, full of methods that allow you to create, delete, gain information about, and generally manipulate drives, folders, and files. Many of the methods associated with this object duplicate those in the other objects.

TextStream:
Enables you to read and write text files.

0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
From MSDN:
-------------------------------
Working with Drives and Folders


With the FSO object model you can work with drives and folders programmatically just as you can in the Windows Explorer interactively. You can copy and move folders, get information about drives and folders, and so forth.

Getting Information About Drives
The Drive object allows you to gain information about the various drives attached to a system, either physically or over a network. Its properties allow you to obtain information about:

1. The total size of the drive in bytes (TotalSize property)

2. How much space is available on the drive in bytes (AvailableSpace or FreeSpace properties)

3. What letter is assigned to the drive (DriveLetter property)

4. What type of drive it is, such as removable, fixed, network, CD-ROM, or RAM disk (DriveType property)

5. The drive's serial number (SerialNumber property)

6. The type of file system the drive uses, such as FAT, FAT32, NTFS, and so forth (FileSystem property)

7. Whether a drive is available for use (IsReady property)

8. The name of the share and/or volume (ShareName and VolumeName properties)

9. The path or root folder of the drive (Path and RootFolder properties)

---------------------------------
Example Usage of the Drive Object

The example below shows how to use the Drive object to gather information about a drive. Remember that you won't see a reference to an actual Drive object in the following code; rather, you use the GetDrive method to get a reference to an existing Drive object (in this case, drv):

Private Sub Command3_Click()
   Dim fso As New FileSystemObject, drv As Drive, s As String
   Set drv = fso.GetDrive(fso.GetDriveName("c:"))
   s = "Drive " & UCase("c:") & " - "
   s = s & drv.VolumeName & vbCrLf
   s = s & "Total Space: " & FormatNumber(drv.TotalSize / 1024, 0)
   s = s & " Kb" & vbCrLf
   s = s & "Free Space: " & FormatNumber(drv.FreeSpace / 1024, 0)
   s = s & " Kb" & vbCrLf
   MsgBox s
End Sub

Using CurDir, ChDrive, ChDir, or App.Path

If you use the CurDir function, the ChDrive and ChDir statements, or the Path property (App.Path), be aware that they may return a UNC path (that is, \\Server\Share…) rather than a drive path (such as E:\Folder), depending on how you run your program or project.

App.Path returns a UNC path:

When you run a project after loading it from a network share, even if the network share is mapped to a drive letter.

When you run a compiled executable file from a network share (but only if it is run using a UNC path).
ChDrive cannot handle UNC paths, and thus raises an error when App.Path returns one. You can handle this error by adding On Error Resume Next before the ChDrive statement, or by testing the first two characters of App.Path to see if they are backslashes:

On Error Resume Next
ChDrive App.Path
ChDir App.Path

This modification handles all cases in which the program is started from Windows using a UNC path (for example, in the Run dialog accessed from the Start menu), because Windows sets the current directory to a UNC path. ChDir handles changes between UNC paths correctly. (The failure of ChDrive can be ignored, because there is no drive letter for a UNC path.)

However, the above code above won't work if you run the program by entering a UNC path at MS-DOS command prompt. This is because the command prompt always has a drive path for the current directory, so CurDir is set to a drive path. ChDir does not raise an error, but it fails to change the directory from a drive path to a UNC path. The only workaround for this situation is to locate a local drive that's mapped to the share specified in the UNC path, or to use network commands to create such a mapping.

If the project is loaded into the Visual Basic IDE from a network share – either a UNC path or a mapped drive path – then App.Path returns a UNC path when the project is run and ChDrive fails and raises an error. ChDir doesn't raise an error, but the directory is not changed. The only workaround is to manually set the drive and directory:

Const PROJECTSHARE = "E:\VBPROJ\MYPROJECT"
#Const Debug = True
#If Debug Then
    ChDrive PROJECTSHARE
    ChDir PROJECTSHARE
#Else
    On Error Resume Next
    ChDrive App.Path
    ChDir App.Path
#End If

If more than one person might open the project on the network share, a DOS environment variable can be used to allow each person to have their own mapping for the share:

#Const Debug = True
#If Debug Then
    ChDrive Environ("MYPROJECTDIR")
    ChDir Environ("MYPROJECTDIR")
#Else
    On Error Resume Next
    ChDrive App.Path
    ChDir App.Path
#End If

The value of MYPROJECTDIR specifies the mapped drive letter and the path, for example:

SET MYPROJECTDIR=M:\VBProj\MyProject

-------------------------------------------
Working with Folders

This list shows common folder tasks and the methods for doing them:

1. Create a folder: FileSystemObject.CreateFolder  

2. Delete a folder: Folder.Delete or FileSystemObject.DeleteFolder  

3. Move a folder: Folder.Move or FileSystemObject.MoveFolder  

4. Copy a folder: Folder.Copy or FileSystemObject.CopyFolder  

5. Retrieve the name of a folder: Folder.Name

6. Find out if a folder exists on a drive: FileSystemObject.FolderExists  

7. Get an instance of an existing Folder object: FileSystemObject.GetFolder

8. Find out the name of a folder's parent folder: FileSystemObject.GetParentFolderName  

9. Find out the path of system folders: FileSystemObject.GetSpecialFolder  


Example:

This example demonstrates usage of the Folder and FileSystemObject objects to manipulate folders and gain information about them:

Private Sub Command10_Click()
   ' Get instance of FileSystemObject.
   Dim fso As New FileSystemObject, fldr As Folder, s As String
   ' Get Drive object.
   Set fldr = fso.GetFolder("c:")
   ' Print parent folder name.
   Debug.Print "Parent folder name is: " & fldr
   ' Print drive name.
   Debug.Print "Contained on drive " & fldr.Drive
   ' Print root file name.
   If fldr.IsRootFolder = True Then
      Debug.Print "This folder is a root folder."
   Else
      Debug.Print "This folder isn't a root folder."
   End If
   ' Create a new folder with the FileSystemObject object.
   fso.CreateFolder ("c:\Bogus")
   Debug.Print "Created folder C:\Bogus"
   ' Print the base name of the folder.
   Debug.Print "Basename = " & fso.GetBaseName("c:\bogus")
   ' Get rid of the newly-created folder.
   fso.DeleteFolder ("c:\Bogus")
   Debug.Print "Deleted folder C:\Bogus"
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
From MSDN:
--------------------------
Working With Files

You can work with files in Visual Basic by using the new object-oriented FSO objects such as Copy, Delete, Move, and OpenAsTextStream, among others, or by using the older existing functions such as Open, Close, FileCopy, GetAttr, and so forth. Note that you can move, copy, or delete files regardless of their file type.

For more information on usage of the older existing functions, see "Processing Files with Older File I/O Statements and Functions" in this chapter. The rest of this section describes using the new FSO objects, methods, and properties to work with files.

There are two major categories of file manipulation:

1. Creating, adding, or removing data, and reading files

2. Moving, copying, and deleting files

----------------------------------
1a. Creating Files and Adding Data with File System Objects

There are three ways to create a sequential text file (sometimes referred to as a "text stream"). One way is to use the CreateTextFile method. To create an empty text file:

Dim fso As New FileSystemObject, fil As File
Set fil = fso.CreateTextFile("c:\testfile.txt", True)

Note   The FSO object model does not yet support the creation of random or binary files. To create random and binary files, use the Open command with either the Random or Binary flag. Full information on how to manipulate random and binary files is contained in "Using Random File Access" and "Using Binary File Access" in this chapter.

Another way is to use either the OpenTextFile method of the FileSystemObject object with the ForWriting flag set:

Dim fso As New FileSystemObject, ts As TextStream
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting)

Or you can use the OpenAsTextStream method with the ForWriting flag set:

Dim fso As New FileSystemObject, fil As File, ts As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("test1.txt")
Set fil = fso.GetFile("test1.txt")
Set ts = fil.OpenAsTextStream(ForWriting)

Adding Data to the File:

Once the text file is created, you can add data to it in three steps:

a. Open the text file for the writing of data.

b. Write the data.

c. Close the file.

To open the file, you can use either of two methods: the OpenAsTextStream method of the File object, or the OpenTextFile method of the FileSystemObject object.

To write data to the open text file, use either the Write or WriteLine methods of the TextStream object. The only difference between Write and WriteLine is that WriteLine adds newline characters to the end of the specified string.

If you want to add a newline to the text file, use the WriteBlankLines method.

To close an open file, use the Close method of the TextStream object.

Here's an example of how to open a file, use all three write methods to add data to the file, then close the file:

Sub Create_File()
    Dim fso, txtfile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtfile = fso.CreateTextFile("c:\testfile.txt", True)
    txtfile.Write ("This is a test. ") ' Write a line.
    ' Write a line with a newline character.
    txtfile.WriteLine("Testing 1, 2, 3.")
    ' Write three newline characters to the file.      
    txtfile.WriteBlankLines(3)
    txtfile.Close
End Sub

1b. Reading Files with File System Objects:

To read data from a text file, use the Read, ReadLine, or ReadAll methods of the TextStream object:

1. Read a specified number of characters from a file Read

2. Read an entire line (up to, but not including, the newline character) ReadLine

3. Read the entire contents of a text file ReadAll  


If you use the Read or ReadLine method and you want to skip to a particular portion of data, you can use the Skip or SkipLine method.

The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string operators (such as Left, Right, and Mid), concatenated, and so forth.

Note   The vbNewLine constant contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage-return/linefeed). Be aware that the ends of some strings may have such nonprinting characters.

Example:
Sub Read_Files()
    Dim fso As New FileSystemObject, txtfile, _
      fil1 As File, ts As TextStream
    fso.CreateTextFile "c:\testfile.txt", True
    MsgBox "Writing file"
    ' Write a line.
    Set fil1 = fso.GetFile("c:\testfile.txt")
    Set ts = fil1.OpenAsTextStream(ForWriting)
    ts.Write "Hello World"
    ts.Close
    ' Read the contents of the file.
    Set ts = fil1.OpenAsTextStream(ForReading)
    s = ts.ReadLine
    MsgBox s
    ts.Close
End Sub

-----------------------------------------
2. Moving, Copying, and Deleting Files

The FSO object model has two methods each for moving, copying, and deleting files:

1. Move a file: File.Move or FileSystemObject.MoveFile

2. Copy a file File.Copy or FileSystemObject.CopyFile

3. Delete a file File.Delete or FileSystemObject.DeleteFile

Example:
This example creates a text file in the root directory of drive C, writes some information to it, moves it to a directory called \tmp, makes a copy of it in a directory called \temp, then deletes the copies from both directories.

To run this example, make sure that you have directories named \tmp and \temp in the root directory of drive C.

Sub Manip_Files()
    Dim fso as New FileSystemObject, txtfile, fil1, fil2
    Set txtfile = fso.CreateTextFile("c:\testfile.txt", True)
    MsgBox "Writing file"
    ' Write a line.
    txtfile.Write ("This is a test.")
    ' Close the file to writing.
    txtfile.Close
    MsgBox "Moving file to c:\tmp"
    ' Get a handle to the file in root of C:\.
    Set fil1 = fso.GetFile("c:\testfile.txt")
    ' Move the file to \tmp directory.
    fil1.Move ("c:\tmp\testfile.txt")
    MsgBox "Copying file to c:\temp"
    ' Copy the file to \temp.
    fil1.Copy ("c:\temp\testfile.txt")
    MsgBox "Deleting files"
    ' Get handles to files' current location.
    Set fil1 = fso.GetFile("c:\tmp\testfile.txt")
    Set fil2 = fso.GetFile("c:\temp\testfile.txt")
    ' Delete the files.
    fil1.Delete
    fil2.Delete
    MsgBox "All done!"
End Sub
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
Thats it for now.. <smile> and a <huge yaaaaaaaawwwwwwwwwwwwwwn>.. Had enough?.. <lol>
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
wsh2,
Just a test of my new code:
Start standard exe project. Add reference to Microsoft Scripting Runtime (VB menu -> Project -> References... -> Microsoft Scripting Runtime (SCRRUN.DLL))
Dim FSO As New FileSystemObject
Press F2
Enjoy :-)
0
 

Expert Comment

by:catdaddy123
Comment Utility
there are some examples at http://616.org/
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 300 total points
Comment Utility
This is a simple sample program that performs most of the properties of the file, folder, and drive objects by using FSO.


Place three labels -- lstDrives, lstFolders, and lstFiles -- control array of the textboxes -- txt(0) to txt(11) -- control array of the labels -- lbl(0) - lbl(14) -- on the form.



Option Explicit

'Module-level filesystem object:
Dim m_FileSys As FileSystemObject

'Show drives and folders
Private Sub Form_Load()
 
  Set m_FileSys = New FileSystemObject
  Dim Drive As Drive
  For Each Drive In m_FileSys.Drives
    lstDrives.AddItem Drive.Path
  Next
 
  lstDrives.ListIndex = 1
 
  Set Drive = m_FileSys.Drives(lstDrives.Text)
 
  FillFolderList Drive
End Sub

'Show Folders that are children of the root folder in the drive identified by DriveName parameter
Private Sub FillFolderList(ByVal Drive As Drive)

  lstFolders.Clear
 
  Dim Root As Folder
  Set Root = Drive.RootFolder
 
  Dim Folder As Folder
  For Each Folder In Root.SubFolders
    lstFolders.AddItem Folder.Name
  Next
End Sub

'Fill the file listbox with the names of files in the Folder parameter
Private Sub FillFileList(ByVal Folder As Folder)
 
  Dim File As File
  lstFiles.Clear
 
  For Each File In Folder.Files
    lstFiles.AddItem File.Name
  Next
End Sub

'Display details about a folder
Private Sub ShowFolderDetails(ByVal Folder As Folder)
  lbl(0) = "Attributes:"
  txt(0) = GetFileAttributeString(Folder.Attributes)
  lbl(1) = "Created:"
  txt(1) = Folder.DateCreated
  lbl(2) = "Last Accessed:"
  txt(2) = Folder.DateLastAccessed
  lbl(3) = "Last Modified:"
  txt(3) = Folder.DateLastModified
  lbl(4) = "Root Folder ?:"
  txt(4) = Folder.IsRootFolder
  lbl(5) = "Name:"
  txt(5) = Folder.Name
  lbl(6) = "Parent Folder:"
  txt(6) = Folder.ParentFolder
  lbl(7) = "Path:"
  txt(7) = Folder.Path
  lbl(8) = "Short Name:"
  txt(8) = Folder.ShortName
  lbl(9) = "Short Path:"
  txt(9) = Folder.ShortPath
  lbl(10) = "Size:"
  txt(10) = Folder.Size
  lbl(11) = "Type:"
  txt(11) = Folder.Type
End Sub

'Display details about a drive
Private Sub ShowDriveDetails(ByVal Drive As Drive)
  lbl(0) = "Available Space:"
  txt(0) = Drive.AvailableSpace
  lbl(1) = "Drive Letter:"
  txt(1) = Drive.DriveLetter
  lbl(2) = "Drive Type:"
  txt(2) = GetDriveTypeString(Drive.DriveType)
  lbl(3) = "Filesystem:"
  txt(3) = Drive.FileSystem
  lbl(4) = "Free Space:"
  txt(4) = Drive.FreeSpace
  lbl(5) = "Ready:"
  txt(5) = Drive.IsReady
  lbl(6) = "Path:"
  txt(6) = Drive.Path
  lbl(7) = "Rootfolder:"
  txt(7) = Drive.RootFolder.Name
  lbl(8) = "Serialnumber:"
  txt(8) = Drive.SerialNumber
  lbl(9) = "Share Name:"
  txt(9) = Drive.ShareName
  lbl(10) = "Total Size:"
  txt(10) = Drive.TotalSize
  lbl(11) = "Volume Name:"
  txt(11) = Drive.VolumeName
End Sub

'Show details about a file
Private Sub ShowFileDetails(ByVal File As File)
  lbl(0) = "Attributes:"
  txt(0) = GetFileAttributeString(File.Attributes)
  lbl(1) = "Created:"
  txt(1) = File.DateCreated
  lbl(2) = "Last Accessed:"
  txt(2) = File.DateLastAccessed
  lbl(3) = "Last Modified:"
  txt(3) = File.DateLastModified
  lbl(4) = "Drive:"
  txt(4) = File.Drive
  lbl(5) = "Name:"
  txt(5) = File.Name
  lbl(6) = "Parent Folder:"
  txt(6) = File.ParentFolder
  lbl(7) = "Path:"
  txt(7) = File.Path
  lbl(8) = "Short Name:"
  txt(8) = File.ShortName
  lbl(9) = "Short Path:"
  txt(9) = File.ShortPath
  lbl(10) = "Size:"
  txt(10) = File.Size
  lbl(11) = "Type:"
  txt(11) = File.Type
End Sub

'Show child folders and drive details when user clicks on a drive
Private Sub lstDrives_Click()
On Error GoTo ERR_ROUTINE

  Dim Drive As Drive
  Set Drive = m_FileSys.Drives(lstDrives.Text)
 
  If Not Drive.IsReady Then
    MsgBox "Drive not ready !", vbOKOnly Or vbCritical
    Exit Sub
  End If

  FillFolderList Drive
  ShowDriveDetails Drive
 
Exit Sub
ERR_ROUTINE:
  MsgBox Err.Description
  Resume Next
End Sub

'Show file details when user clicks on a particular file
Private Sub lstFiles_Click()
On Error GoTo ERR_ROUTINE

  Dim Drive As Drive
  Set Drive = m_FileSys.Drives(lstDrives.Text)
 
  If Not Drive.IsReady Then
    MsgBox "Drive not ready !", vbOKOnly Or vbCritical
    Exit Sub
  End If

  Dim Root As Folder
  Set Root = Drive.RootFolder
 
  Dim Folder As Folder
  Set Folder = Root.SubFolders(lstFolders.Text)

  Dim File As File
  Set File = Folder.Files(lstFiles.Text)
 
  ShowFileDetails File
 
Exit Sub
ERR_ROUTINE:
  MsgBox Err.Description
  Resume Next
End Sub

'Show folder details and fill file listbox with the names of files in the folder clicked
Private Sub lstFolders_Click()
On Error GoTo ERR_ROUTINE

  Dim Drive As Drive
  Set Drive = m_FileSys.Drives(lstDrives.Text)
 
  If Not Drive.IsReady Then
    MsgBox "Drive not ready !", vbOKOnly Or vbCritical
    Exit Sub
  End If

  Dim Root As Folder
  Set Root = Drive.RootFolder
 
  Dim Folder As Folder
  Set Folder = Root.SubFolders(lstFolders.Text)
  ShowFolderDetails Folder
  FillFileList Folder
 
Exit Sub
ERR_ROUTINE:
  MsgBox Err.Description
  Resume Next
End Sub

'Convert a DriveTypeConst to a string expression for display purposes
Private Function GetDriveTypeString(ByVal dType As DriveTypeConst) As String
 
  Select Case dType
    Case CDRom
      GetDriveTypeString = "CDRom"
    Case Fixed
      GetDriveTypeString = "Fixed Disk"
    Case RamDisk
      GetDriveTypeString = "Ram Disk"
    Case Remote
      GetDriveTypeString = "Remote Disk"
    Case Removable
      GetDriveTypeString = "Removable Disk"
    Case Else
      GetDriveTypeString = "Unknown Type"
  End Select
End Function

'Convert Attribute flag field to string expression for display purposes
Private Function GetFileAttributeString(ByVal Attr As FileAttribute) As String
  Dim s As String
 
  If Attr And Alias Then s = s & "Alias "
  If Attr And Archive Then s = s & "Archive "
  If Attr And Compressed Then s = s & "Compressed "
  If Attr And Directory Then s = s & "Directory "
  If Attr And Hidden Then s = s & "Hidden "
  If Attr And Normal Then s = s & "Normal "
  If Attr And ReadOnly Then s = s & "ReadOnly "
  If Attr And System Then s = s & "System "
  If Attr And Volume Then s = s & "Volume "
  GetFileAttributeString = s
End Function
0
 

Author Comment

by:vbrobinson
Comment Utility
Thanx Wsh2 & Ruchi
Wsh2 You have suggested too many readings for me and I don't have time to read. However, you get the 1/2 of 300 points. Need to answer to the new question.
Ruchi I pasted a quick example and it worked like a charm!
Thanx,
Robinson
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
Robinson: You're most welcome! I'm glad that I could be of any help to you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now