View Full Version : File Attributes- Please, Help me!
david_binda
05-11-2002, 10:39 PM
As I can change file attributes by VScript?
I can´t delete a files, which are read-only.
I’m not sure I understand what is it that you want to do!
Do you mean you want to change file attributes in a script so you can delete them?
If that’s what you mean, then, you’ll have to use the “file.Attributes” method to get the file attribute and also to set it.
For example, if you wanted to remove the Read-Only attributes from a file, you’ll have to set it’s attributes to “0”,
file.Attributes = 0
If you want to do that for all files in a folder, you’d do;
‘_____________________ FileAttrib.vbs ___________________
Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder("C:\TestFolder)
<font color=blue>For Each</font color=blue> file In MyFolder.Files
<font color=blue>If</font color=blue> file.Attributes > 0 Then
file.Attributes = 0
<font color=green>‘ You can then delete the file.</font color=green>
File.delete
<font color=blue>End If</font color=blue>
<font color=blue>Next</font color=blue>
‘--------------------------------------End -----------------------------------
File attributes can have one of the following values;
'0 - No Attributes
'1 - Read Only
'2 - Hidden
'3 - Hidden & Read Only
'32 - Archive
'33 - Read Only & Archive
'34 - Hidden & Archive
Good Luck
Jama
adamdelves
05-12-2002, 06:47 AM
To do this without clearing all other file attributes, just clear the bit:
<pre>
set fileHwnd = fs.getfile(cFilePath)
fileHwnd.attributes = (fileHwnd.attributes AND NOT 1)
</pre>
david_binda
05-12-2002, 06:25 PM
Thanx a lot! I´m beginer in this and I was very sad
aroun that. david_binda
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.