File System Object Property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code that creates a folder. After the folder is created,
I want to set the attributes to 'hidden'. I have tried fs.attrib = hidden and
fs.attribute= hidden but get syntax errors. What do I need to do? Thank you.

Dim fs As FileSystemObject 'declare file system object
Set fs = New FileSystemObject 'instantiate object
If Not fs.FolderExists("C:\Program Files\My Bike Log\BikeLogText") Then
fs.CreateFolder "C:\Program Files\My Bike Log\BikeLogText"
End If
 
It's not necessary to introduce the overhead of FSO to do what you're trying
to do.

The VBA SetAttr statement will do what you're trying to do:

SetAttr "C:\Program Files\My Bike Log\BikeLogText", vbHidden

VBA is also capable of determining whether or not a particular folder
exists, and to create it if it doesn't:

Dir("C:\Program Files\My Bike Log\BikeLogText\", vbDirectory)

will return an empty string if the directory doesn't exist, and

MkDir ""C:\Program Files\My Bike Log\BikeLogText\"

will create a directory.

The only caveat is that you cannot create C:\Program Files\My Bike
Log\BikeLogText if "C:\Program Files\My Bike Log doesn't already exist.
 
Should FileSystemObject still be the preferred way, I think something
like
this might do:

Dim fs As Scripting.FileSystemObject 'declare file system
object
Dim fld as scripting.folder
Set fs = New scripting.FileSystemObject 'instantiate object
If Not fs.FolderExists("C:\Program Files\My Bike Log\BikeLogText") Then
set fld = fs.CreateFolder "C:\Program Files\My Bike
Log\BikeLogText"
fld.attributes = fld.attributes or hidden
End If


Douglas J. Steele wrote in message
 
Back
Top