troubleshooting Question

Recursive vbs script not truly changing files from read-only to normal?

Avatar of stephenlecomptejr
stephenlecomptejrFlag for United States of America asked on
VB ScriptOS SecurityMicrosoft Legacy OS
9 Comments2 Solutions1181 ViewsLast Modified:
Per the following code - I'm trying to make a vbs script that wherever it resides - goes through its root and all subdirectories under it and changes the file attributes from read-only to normal.  This works fine for the subdirectories - but it doesn't continue to change the subdirectories under the subdirectories.

For example under C:\Test - I have the following subfolders:  C:\Test\Test A, C:\Test\Test B and C:\Test\Test C - which any files found are changed correctly.   But I also have some subdirectories under C:\Test C....  as  C:\Test\Test C\Test D and C:\Test\Test C\Test E and under both those directories none of the files have changed.  Same situation for C:\Test\Test C\Test E\Test F.  So please note syntax below and let me know if I have something wrong - but I believe its correctly recursive!

I will also provide a sample to manipulate also...please review the following here:
https://filedb.experts-exchange.com/incoming/ee-stuff/8147-Test.zip

Option Explicit

Const ReadOnly = 1

Dim sFolder
sFolder = Left(WScript.ScriptFullName,(Len(WScript.ScriptFullName) - (Len(WScript.ScriptName) + 1))) 
Call Make_All_Files_Writeable(sFolder)


Public Sub Make_All_Files_Writeable(sWhere)

  Dim fs
  Dim dDirs
  Dim dDir
  Dim fFile
  Dim sFolderPath
  Dim sSubFolderPath
  
  sFolderPath = sWhere

  Set fs = CreateObject("Scripting.FileSystemObject")
  Set dDirs = fs.GetFolder(sFolderPath)
  
  If dDirs.Attributes = ReadOnly Then
    
    dDirs.Attributes = 0
    
  End If
  
  For Each fFile In dDirs.files
    'match filename to pdf extension
    
    If fFile.Attributes = fFile.Attributes AND 1 Then
      
        
	If fFile <> WScript.ScriptFullName Then
      
          fFile.Attributes = 0
      
        End If
      
    End If
    
    
    For Each dDir In dDirs.SubFolders
    
	
      sSubFolderPath = dDir.Path

      Call Make_All_Files_Writeable(sSubFolderPath)  ' Here is the recursion
      
    Next
  
  Next
  
End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros