Delete Files smaller than... [SOLVED]

Discussions concerning programming of SOFTIMAGE©
caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 14:13

Delete Files smaller than... [SOLVED]

Post by caledonian_tartan » 16 Nov 2012, 17:42

hi all
i have this script to delete files (on windows) smaller than 1KB.
Maybe you know how to get such files in your render directory. (if not, just abort your next render)

so.

i'd like to pimp the script a little more.

it already works, but i'd like to add 4 things.

- it should open a PPG with
- set scalar number of size (eg. 1 for delete files smaller than 1KB)
- a path browser with browse button (which as a default points to render output folder)
- a execute Button


here's the working VB script without PPG:

Code: Select all

Dim fso
Dim fold
Dim files
Dim file

lngSize = 100 ' The threshold in bytes (this is 100k)
strPath = "E:\_TEMP\scriptTest" 'The folder you want to start in

Set fso = CreateObject("scripting.filesystemobject")
Set fold = fso.GetFolder(strPath)
Set files = fold.files

For Each file In files
    If file.Size >= lngSize Then file.Delete True

next
to point to the project directory in VBS i can use something like ActiveProject2.Path & "\Render_Pictures"

BUT it would be much better to point to the Render Output directory of the scene options. [Project Path]/Render_Pictures
what's the VBS name of this?

i do have some troubles to add the path browser. i took an example from the SDK as a start but i don't really get it.
how can i define the browser property and then integrate into the PPG logic?

here's the attempt of the non working PPG version:

Code: Select all

'
' This example creates a custom property with a single parameter called "Data" and a button.
' Each time you click the button the value is randomized
'
set oPSet = ActiveSceneRoot.AddProperty( "CustomProperty", false, "Delete Files smaller than" )
oPSet.AddParameter3 "SizeKB", siDouble, 1, 0, 1000
oPSet.AddParameter3 "Path", siString, testdefaultvalue
set oLayout = oPSet.PPGLayout
oLayout.AddRow
oLayout.AddItem "Path", siControlFilePath, ActiveProject2.Path & "\Render_Pictures"
oLayout.EndRow
oLayout.AddRow
oLayout.AddItem "SizeKB"
oLayout.AddButton "Execute"
oLayout.EndRow
'Store a little VBScript code to react to the button press.
'If this code was more sophisticated we could read it out
'of a file
oLayout.Logic = "sub Randomize_OnClicked"   & vbCrlf & "   PPG.Data.Value = Rnd" & vbCrlf & "end sub"
oLayout.Language = "VBScript" 'Optional because this is the default
InspectObj oPSet
cheers
Last edited by caledonian_tartan on 18 Nov 2012, 22:10, edited 1 time in total.
SI 2015 @ WIN7-64

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: Delete Files smaller than...

Post by EricTRocks » 17 Nov 2012, 01:20

Use python instead of VB as not many folks still use VB unless its in a scripted operator or working with legacy plug-ins.. :)

Code: Select all

# Python
oLayout = oProjProp.PPGLayout
oItem = oLayout.AddItem("strProjPath", "Folder Path", c.siControlFolder) # note the siControlFolder UI type
Also look in the SDK guide for the other PPGItem attributes you can set. I believe there is one for initial directory. You should look into creating a self installing property as it will make the logic a lot easier to deal with.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 14:13

Re: Delete Files smaller than...

Post by caledonian_tartan » 18 Nov 2012, 22:09

thanks for the tips Eric!

unfortunately i wasn't capable of switching to python.
but i found out how to do it with vb script.


so here it is:

a script to delete small files on your harddisk with a given size threshold.

copy to ..\Application\Plugins




-- handle with care -- deletes files --


EDIT: due to Eric's suggestion i added a Message box where you can confirm your delete. only problem there is that i wanted to insert the number of how many items will be deleted. but this gets calculated later in the function so it's always zero... any workaround?
You do not have the required permissions to view the files attached to this post.
Last edited by caledonian_tartan on 19 Nov 2012, 08:42, edited 1 time in total.
SI 2015 @ WIN7-64

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: Delete Files smaller than... [SOLVED]

Post by EricTRocks » 18 Nov 2012, 22:23

If you don't have it already, I'd suggest a confirmation (Yes / No) pop up using xsi.MsgBox() to confirm the user really wants to delete the files. Glad you got it working.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

caledonian_tartan
Posts: 253
Joined: 17 Feb 2010, 14:13

Re: Delete Files smaller than... [SOLVED]

Post by caledonian_tartan » 19 Nov 2012, 08:44

ok. messagebox added.
thx
SI 2015 @ WIN7-64