Hi.

I'm a new VBscripter, so probably this my question may be a little stupid.

I'm trying to create a simple 'batch' file to copy files from CD to
hard-disk. The problem is that the files on hard disk will have the ReadOnly
flag set.
I tryed the following code (recursive to run on subfolders too), but it
don't work. I call it with WSCRIPT.

Can someone help me ?

Thank You very much.
Alberto.


' Main call
call VBS_ClearReadOnlyFlag ("C:\FOLDER_EXAMPLE")


' Subroutine
Sub VBS_ClearReadOnlyFlag (szFolder)

Dim oFolder, oSubFolder, oFiles, f, f1

' Check if folder exist
If (oFS.FolderExists (szFolder) = 0) Then
Exit Sub
End If

Set oFolder = oFS.GetFolder (szFolder)

Set oSubFolder = oFolder.SubFolders
For Each f in oSubFolder
call VBS_ClearReadOnlyFlag (f.Path)
Next

Set oFiles = oFolder.Files
For Each f in oFiles
Set f1 = oFS.GetFile (f.Path)
f1.Attributes = f1.Attributes - ReadOnly
Next

End Sub

Re: Clear the ReadOnly flag. by Alexander

Alexander
Mon May 08 03:07:43 CDT 2006

Alberto N. schrieb:

> I'm trying to create a simple 'batch' file to copy files from CD to
> hard-disk. The problem is that the files on hard disk will have the ReadOnly
> flag set.
> I tryed the following code (recursive to run on subfolders too), but it
> don't work. I call it with WSCRIPT.
>
> Can someone help me ?

First, you need to declare the ReadOnly-constant explicitly.
VBScript itself doesn't know enumerated constants declared in
typelibraries, if not embedded into a WSF-reference context.
Second instead of arithmeticly subtracting the ReadOnly-bit, subtract
it bitwise. Arithmetic subtraction will fail, if the bit isn't set.

MfG,
Alex

> ' Main call

Const ReadOnly = 1

> call VBS_ClearReadOnlyFlag ("C:\FOLDER_EXAMPLE")
>
>
> ' Subroutine
> Sub VBS_ClearReadOnlyFlag (szFolder)
>
> Dim oFolder, oSubFolder, oFiles, f, f1
>
> ' Check if folder exist
> If (oFS.FolderExists (szFolder) = 0) Then
> Exit Sub
> End If
>
> Set oFolder = oFS.GetFolder (szFolder)
>
> Set oSubFolder = oFolder.SubFolders
> For Each f in oSubFolder
> call VBS_ClearReadOnlyFlag (f.Path)
> Next
>
> Set oFiles = oFolder.Files
> For Each f in oFiles
> Set f1 = oFS.GetFile (f.Path)

'# Change this line

> f1.Attributes = f1.Attributes - ReadOnly

'# to:

f1.Attributes = f1.Attributes And Not ReadOnly

> Next
>
> End Sub
>
>

Re: Clear the ReadOnly flag. by Alberto

Alberto
Mon May 08 04:31:04 CDT 2006

Thank you, now it work.

Strange, because the starting sample was taken from online help of VC++ 6.0
(keyword: Attributes property -> VBS)

Alberto.


"Alexander Mueller" <millerax@hotmail.com> ha scritto nel messaggio
news:uarP9ZncGHA.1260@TK2MSFTNGP05.phx.gbl...
> Alberto N. schrieb:
>
>> I'm trying to create a simple 'batch' file to copy files from CD to
>> hard-disk. The problem is that the files on hard disk will have the
>> ReadOnly flag set.
>> I tryed the following code (recursive to run on subfolders too), but it
>> don't work. I call it with WSCRIPT.
>>
>> Can someone help me ?
>
> First, you need to declare the ReadOnly-constant explicitly.
> VBScript itself doesn't know enumerated constants declared in
> typelibraries, if not embedded into a WSF-reference context.
> Second instead of arithmeticly subtracting the ReadOnly-bit, subtract
> it bitwise. Arithmetic subtraction will fail, if the bit isn't set.
>
> MfG,
> Alex
>
>> ' Main call
>
> Const ReadOnly = 1
>
>> call VBS_ClearReadOnlyFlag ("C:\FOLDER_EXAMPLE")
>>
>>
>> ' Subroutine
>> Sub VBS_ClearReadOnlyFlag (szFolder)
>>
>> Dim oFolder, oSubFolder, oFiles, f, f1
>>
>> ' Check if folder exist
>> If (oFS.FolderExists (szFolder) = 0) Then
>> Exit Sub
>> End If
>>
>> Set oFolder = oFS.GetFolder (szFolder)
>>
>> Set oSubFolder = oFolder.SubFolders
>> For Each f in oSubFolder
>> call VBS_ClearReadOnlyFlag (f.Path)
>> Next
>>
>> Set oFiles = oFolder.Files
>> For Each f in oFiles
>> Set f1 = oFS.GetFile (f.Path)
>
> '# Change this line
>
>> f1.Attributes = f1.Attributes - ReadOnly
>
> '# to:
>
> f1.Attributes = f1.Attributes And Not ReadOnly
>
>> Next
>>
>> End Sub
>>


Re: Clear the ReadOnly flag. by Alexander

Alexander
Mon May 08 05:23:15 CDT 2006

Alberto N. schrieb:

> Thank you, now it work.
>
> Strange, because the starting sample was taken from online help of VC++ 6.0
> (keyword: Attributes property -> VBS)
>

Never mind, probably there was some proof for the ReadOnly flag
being set, in which case subtraction is fail-safe,
s-th like:

If file.Attributes And ReadOnly = ReadOnly Then
file.Attributes = file.Attributes - ReadOnly
End If



MfG,
Alex