technical architecture.

Tag: VB

Recursive file size listing output to excel

by on Dec.30, 2009, under Admin, Batching, Scripting, vbscript

Today I had to find all JPG files over a certain size in a large directory tree of a few thousand images, to find some poorly compressed jpg’s, fix the compression, and replace them on a website. Todays cavaet, the CMS is pretty weak and only lets you update 1 image at a time, so you can’t just blindly resave everything and reupload, todays Second cavaet, I dont have server level access to said website, so all the normal automated ways are out of luck.


So I found a little snip of code online, and threw a pretty simple hack job together to narrow the scope some. (PS: If you do end up doing any vbscript, I’d suggest VbsEdit for an IDE)

Anyway! the code:

It searches through a directory tree of your choosing
for any file matching the filetype: “jpg”
that is above a size threshold: fileSizeThreshold (In this case, 2kb.. so essentially everything)
and outputs it into an excell sheet with full path and size information
so that you can easily Sort, Filter, Delegate, or use as data for further automating!

' // **************************************
' //    ComputerHighGuys recursive search
' //     
' //    Date Created: 20 Aug 07
' //
' //
' //	Adjusted to a jpg file search and 
' //	added excel output for easy sorting/filtering
' //	
' // **************************************
' // If we'd like to save the output into an excel sheet
WriteExcel = "True"
Dim objexcel
' // value the filesize needs to exceed to be visible in the output
If WriteExcel = "True" Then
	' // Create the Excel sheet to drop the information into
	Set objExcel = createobject("Excel.application")   
	objexcel.Cells(1, 1).Value = "Folder Name"
	objexcel.Cells(1, 2).Value = "Filename"
	objexcel.Cells(1, 3).Value = "Filesize"
	objexcel.Cells(1, 4).Value = "Filesize Unit"
	objexcel.Visible = True
	Wscript.Sleep 300
End If
' // Directory to search
searchDir = "C:\"
set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(searchDir)
Set colFiles = objFolder.Files
' // Launch the function
' // recursive function that will search through all subfolders for a specified
' // filetype and output some information about the files to an Excel Sheel
Sub scanSubFolders(objFolder)
	' // Grab sub folders    
    Set colFolders = objFolder.SubFolders
    For Each objSubFolder In colFolders
    	' // the files to search
        Set colFiles = objSubFolder.Files
        For Each objFile in colFiles
            ' // the extension of the filetype to search for  
            If lcase(Right(objFile.Name,3)) = "jpg" Then
                ' // Getting File size in KB
                If round(objFile.Size/1024,1) > fileSizeThreshold Then
                	' // echo the files to the console
                	WScript.Echo objSubFolder.Path & "  " & objFile.Name & "  " & round(objFile.Size/1024,1)  & "KB"
					' // write various shit to excel~                    
                    If WriteExcel = "True" then
                        wscript.Echo objSubFolder.Path & "  " & objFile.Name & "  " & round(objFile.Size/1024,1)  & "KB"
                    	objexcel.Cells(excelRow, 1).Value = objSubFolder.Path
    					objexcel.Cells(excelRow, 2).Value = objFile.Name
    					objexcel.Cells(excelRow, 3).Value =  round(objFile.Size/1024,1)
    					objexcel.Cells(excelRow, 4).Value =  "KB" 
                    End If
                End if    
            End If
End Sub
2 Comments :, , , , , more...

process execution across a network

by on Dec.02, 2008, under Admin, Batching

A couple simple tricks you can do with the remote process execution of the Slave Utils for fun. (Also corresponding commandlines for use with the psexec, which is what the slave utils is batching

you can start a remote command line on any of the machines in your list simply by doing a cmd.exe in the ‘ProcessToStart’ line.. its a small thing, but its helpful for certain things.. ie: copying files from one remote machine to another remote machine.. its *MUCH* faster if you do something like that FROM one of the remote machines, and skip the middleman.

How to start VNC on a remote machine, and have it work interactively… when you’re not allowed to install it as a service! (Read: Our IT uses its own copy of vnc that we aren’t allowed to Co-Opt for our own uses.. so we end up with 2 copies running!)

Apparently its tricky to run interactive remote processes that are allowed to interact with the desktop under full local privileges?! Go figure. Anyway, This is what you would enter to launch the vnc with the same privileges as if you were at that computer and hit the shortcut.

cmd.exe /c start “c:\program files\Realvnc\winvnc\winvnc.exe” “c:\program files\Realvnc\winvnc\winvnc.exe”

what this converts to in actual command line is something along the lines of:

psexec \\computer -i -d -u DOMAIN\Login -p password cmd.exe /c start “c:\program files\Realvnc\winvnc\winvnc.exe” “c:\program files\Realvnc\winvnc\winvnc.exe”

so it used the login and pass to launch the remote cmd.exe, but then used the local system privileges with the start command. allowing it to have full network and desktop interaction privileges.

More to come later.

Leave a Comment :, , more...

Farm Management with VB (?!@#)

by on Aug.11, 2008, under Batching

Here’s a small utility I’d written in ’05 in HTA using mostly VBScript to replace the hordes of dos BAT files utilizing pstools that i had laying around for starting and stopping and checking services/processes/logs on remote machines on our network. Primarily it was used with managing a small farm with 3dsmax/vray. the discussion about the utility on the Vray Forums as i was building it.
Farm Management Utilities 10.6

Farm Management Utilities 10.6

  • Run the .HTA once.. it will create 2 files for you
  • “Computers.ini” which you will will need to edit to contain 1 slave computer per line in it (either IP address or computer Name work, use for your local system)
  • “SlaveutilsOptions.ini” which will have slots for various paths and options. read the file and edit the lines accordingly.
    • (Path to your VNC client,
    • whether to use alternate credentials or not,
    • and what the login/password would be if you did use them.

Note: Its been brought to my attention that some virus scanners will flag this download (Understandably in my opinion) as ‘Greyware’ because it contains VBScript that uses the WMI (Windows Management Interface) to affect changes to remote computers, enclosed in an HTA (Read: Executable Webpage). the full code is in there and easily readable.

I’ve been experimenting with a few other ways to package it, either via Maxscript, or Python, but they tend to get constrained to ‘free’ time as this functions perfectly 🙂

3 Comments :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!