Jump to content

Help converting VBS to autoit


Recommended Posts

Can anybody convert this visual basic script to autoit. (It basically deletes files older than 10 days from the indicated directory). Shortening the routine would also be greatly appreciated.

'work in this folder
path = "G:\Image"

'delete files/folders older than 10 days
killdate = date() - 10

set fso = createobject("scripting.filesystemobject")

arFiles = array()
count = -1

SelectFiles path, killdate

dcount = 0
for each file in arFiles
  s = s & file.name & vbcrlf
  on error resume next
  file.delete true
  if err.number = 0 then dcount = dcount + 1
  err.clear
  on error goto 0
next

DeleteEmptyFolders path,false

'msgbox count+1 & " files found, " & dcount & " deleted."

sub SelectFiles(sPath, vKillDate)

  set folder = fso.getfolder(sPath)
  set files = folder.files

  for each file in files
    dtlastmodified = null
    on error resume Next
    dtlastmodified = file.datelastmodified
    on error goto 0
    if not isnull(dtlastmodified) Then
      if dtlastmodified < vKillDate then
        count = count + 1
        redim preserve arFiles(count)
        set arFiles(count) = file
      end if
    end if
  next

  for each fldr in folder.subfolders
    SelectFiles fldr.path, vKillDate
  next

end sub

sub DeleteEmptyFolders(sPath,bDeleteThisFolder)

  set folder = fso.getfolder(sPath)

  for each fldr in folder.subfolders
    DeleteEmptyFolders fldr.path,true
  next

  if (folder.files.count = 0) and _
     (folder.subfolders.count) = 0 and _
     bDeleteThisFolder then
    folder.delete
    exit sub
  end if

end sub
Link to comment
Share on other sites

To get you started:

  • Change set fso = createobject("scripting.filesystemobject") to $fso = ObjCreate("scripting.filesystemobject")
  • start all of your variables with a '$' and don't use 'set'
  • the rest of the syntax will be pretty similar
Give it a try, post your results and specific questions.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Also look for a VBScript to AutoIt Converter. There is one in the Scripts and Scraps section. I never seem to have the link handy either.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...