Solved

.vbs script creat read/write folder problem

Posted on 2004-09-01
6
2,304 Views
Last Modified: 2013-12-03
i am writing a script to crete a folder and populate it with some logs. Simple enough right? whenever I create this folder via .vbs, it is set to read-only attribute, and I can't write anything to it. I need this changed with script though, because it is part of another script running on 300 or so computers.  Here is the following two methods i've already used that keep defaulting to read only access

1#
Set FSO = CreateObject("Scripting.FileSystemObject")
   FSO.CreateFolder(c:\dufftest65)

2#
folder= "emma04fix"
path= "c:\"&folder
duffcmd= "cmd /c md "& path
Call Wshshell.run(duffcmd,0,0)

Any help as to something I need to add or change would be greatly appreciated! I think 125 pts should be more then enough but hopefully that will get me some quick answers!
0
Comment
Question by:duffbk4
6 Comments
 
LVL 1

Author Comment

by:duffbk4
ID: 11952194
Ok, I have pushed the points up cause I need this as soon as possible.  Thanks for any help!
0
 
LVL 16

Accepted Solution

by:
nonubik earned 500 total points
ID: 11952759
It is strange that is created read-only. You can set folder's attribute

Set FSO = CreateObject("Scripting.FileSystemObject")
   FSO.CreateFolder(c:\dufftest65)
   If FSO.attributes and 1 Then
      FSO.attributes = FSO.attributes - 1


1 is the value for readonly
0
 
LVL 86

Expert Comment

by:jkr
ID: 11952843
That should just work fine using

Function CreateFolderDemo
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.CreateFolder("c:\New Folder")
   CreateFolderDemo = f.Path
End Function

But, if the parent folder is set to 'read only' for your account and these settings are to be inherited by the contained objects, you'll end up with a newly created read-only folder. To change that, you could use

Function ToggleReadOnlyBit(filespec)
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(filespec)
   If f.attributes and 1 Then
      f.attributes = f.attributes - 1
      ToggleReadOnlyBit = "ReadOnly bit is cleared."
   Else
      f.attributes = f.attributes + 1
      ToggleReadOnlyBit = "ReadOnly bit is set."
   End If
End Function

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 16

Expert Comment

by:nonubik
ID: 11952888
heh, I was a little bit faster :o)
0
 
LVL 1

Author Comment

by:duffbk4
ID: 11953519
Thanks for the help! Both of you.
0
 

Expert Comment

by:uber-goober
ID: 12126948
I am having exactly the same problem.  My directory has the read-only flag blocked out, (not checked) and I get the permissions error when I try to copy a file to it.  I have used the following code to explicitly set the bits to 16 for my directory (directory - not read-only).  Can someone help?

Set BinFolder = FolderObject.CreateFolder(InstallDir & "\Support\" & EnvLabel & "\BIN")
                        
BinFolder.Attributes = NOT 239 'set attributes to 16
msgbox "BinFolder.Attributes = " & BinFolder.Attributes,,"DEBUG" 'verify attribute setting
      
FolderObject.CopyFile CurrentInstallDir & "\BIN\winstore.sec", BinFolder, TRUE 'HOSED!@

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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