Tag Archive: FSO

Aug 16 2012

Show all Files in a Folder Recursively

Sometimes one needs to produce a list of files in a directory hierarchy. Here is one possible solution that uses a recursive subroutine.

Sep 02 2008

Attributes String from File

file attributes are like switches. If the switch for Hidden is on, the file is a hidden file. If the switch for Hidden is off, the file is not a hidden file. This analogy can be carried further by noting that light switches are typically under your control: you can choose to turn them on, …

Continue reading »

Mar 31 2008

Determine the Size of a Folder

the WMI class Win32_Directory and noticed the property FileSize. Based on that, you might think, “Well, obviously I could just write a WMI script to get the folder size.” In turn you might write a script very similar to this one, which tries to determine the size of the folder C:\Scripts on the computer atl-ws-01: …

Continue reading »

Mar 31 2008

Delete all Files Older than a Specific Date

Option Explicit Public Function DeleteOldFiles( ByVal folderPath, ByVal daysOld ) Dim fso, folder, files, file Dim dateCreatedStr, daysDiff DeleteOldFiles = -1 Set fso = CreateObject( “Scripting.FileSystemObject” ) If Not fso.FolderExists( folderPath ) Then Reporter.ReportEvent micWarning, “DeleteOldFiles”, “Folder -> ” & folderPath & ” was not found.” Exit Function End If Set folder = fso.GetFolder( folderPath …

Continue reading »

Mar 31 2008

Change a read-only file to a read-write file

Option Explicit Const ReadOnly = 1 Dim fso, file Dim filePathStr filePathStr = “C:\MyFile.txt” Set fso = CreateObject( “Scripting.FileSystemObject” ) If fsoutil.FileExists( filePathStr ) Then Set file = fso.GetFile( filePathStr ) If file.Attributes And ReadOnly Then file.Attributes = file.Attributes Xor ReadOnly End If Else Reporter.ReportEvent micWarning, “Change Attributes”, “File -> ” & filePathStr & ” …

Continue reading »

Mar 31 2008

Delete Specific File Ttypes from ‘My Pictures’ Folder

Option Explicit On Error Resume Next Const MY_PICTURES = &H27 Const DeleteReadOnly = True Dim fso, shell, folder, folderItem Dim pathStr, filesStr, i Set fso = CreateObject( “Scripting.FileSystemObject” ) Set shell = CreateObject( “Shell.Application” ) Set folder = shell.Namespace( MY_PICTURES ) Set folderItem = folder.Self pathStr = folderItem.Path filesStr = pathStr & “\*.txt” fso.DeleteFile filesStr, …

Continue reading »

Mar 31 2008

Convert File Size to Different Size Units

Public Sub FileSizeStrings( ByVal fileSize, ByRef sizes ) Const K_SIZE = 1024 Set sizes = CreateObject( “Scripting.Dictionary” ) fileSize = CDbl( fileSize ) sizes.Add “Bytes”, Cstr( fileSize ) tmpSize = CDbl( fileSize / K_SIZE ) sizes.Add “KB”, Cstr( tmpSize ) tmpSize = CDbl( tmpSize / K_SIZE ) sizes.Add “MB”, Cstr( tmpSize ) tmpSize = CDbl( …

Continue reading »