vbscript - Search for newer/higher version of Folder through VBS -
i want write script search newer version of folder. however, have no idea how start it. have 3 folders in directory.
15.0.4727.1002, 15.0.4701.1002, 15.0.4675
i search folder has newer or higher version. in case it's
15.0.4727.1002
as need 1 element (folder) collection (subfolders), sorting overkill. need convert folder name (correctly) sortable. subtask addressed in answers linked to.
the conversion can done formatting (padding) parts of folder names:
option explicit dim ofs : set ofs = createobject("scripting.filesystemobject") dim osb : set osb = createobject("system.text.stringbuilder") dim slst : slst = "" ' smallest possible value dim olst : set olst = nothing dim odir each odir in ofs.getfolder("..\f").subfolders dim aparts : aparts = split(odir.name, ".") redim preserve aparts(3) osb.appendformat_4 "{0,6}{1,6}{2,6}{3,6}", (aparts) dim skey : skey = osb.tostring() : osb.length = 0 if slst < skey slst = skey set olst = odir end if next if not olst nothing wscript.echo "latest:", olst.name end if
output:
cscript 31720684.vbs latest: 15.0.4727.1002
update wrt comment:
by setting olst
nothing before loop, can test after loop guard against empty/no subfolders directory. or: if want use olst.name
should make sure olst
(usable) object.
Comments
Post a Comment