Sometimes one needs to produce a list of files in a directory hierarchy. Here is one possible solution that uses a recursive subroutine.
Tag Archive: Files
May 15 2008
Creating a ZIP Archive
Windows XP has a built-in ZIP mechanism integrated into its file-system. We can easily use this to create standard ZIP archives with only a few commands: 1: ‘Variable Declaration 2: Dim sSourceFolder 3: Dim sArchiveFile 4: 5: Dim oShell 6: Dim oZIP 7: Dim oSourceFolder 8: 9: ‘Variable Initalization 10: sSourceFolder = “C:\SomeFolder” 11: sArchiveFile …
May 15 2008
Extracting a ZIP File
Windows XP has a built-in ZIP mechanism integrated into its file-system. We can easily use this to extract standard ZIP files with only a few commands: 1: ‘Variable Definition 2: Dim sZIPFile 3: Dim sExtractToPath 4: 5: Dim oShell 6: Dim oZippedFiles 7: 8: ‘Variable Initialization 9: sZIPFile=”C:\Source.zip” 10: sExtractToPath=”C:\Dest\InnerDir\” 11: Set oShell = CreateObject(“Shell.Application”) …
Apr 03 2008
FTP your Scripts
FTP ( File Transfer Protocol ) Article based on http://en.wikipedia.org/wiki/FTP FTP or File Transfer Protocol is used to transfer data from one computer to another over the Internet, or through a network. Specifically, FTP is a commonly used protocol for exchanging files over any network that supports the TCP/IP protocol (such as the Internet or …
Mar 31 2008
Rename all Files in a Folder
Sometimes we need to rename all the files in a given folder, either by appending the date, changing the file extension. The following example simulates a backup operation, by renaming all files extensions in the LOG folder from .log to .bak. The Script assumes that you already have a folder under location C:\LOG and assumes …
Mar 31 2008
Get a List of all DLL Files in a Folder
Option Explicit Dim wmiService, fileList, file Dim dirName, machine dirName = “C:\Windows\System32″ machine = “.” Set wmiService = GetObject( “winmgmts:\\” & machine & “\root\cimv2″) Set fileList = wmiService.ExecQuery ( “ASSOCIATORS OF {Win32_Directory.Name=’” & dirName & “‘} Where ResultClass = CIM_DataFile” ) For Each file In fileList If file.Extension = “dll” Then Print file.FileName & “.dll; …
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 …
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 & ” …
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, …
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( …


Recent Comments