Solved

.vbs script creat read/write folder problem

Posted on 2004-09-01
6
2,299 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
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.

 
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

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

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

757 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

21 Experts available now in Live!

Get 1:1 Help Now