vbscript - Rename files without copying in same folder -
i have files following naming convention.
re12356_gj123456789.dat
i need rename file re12356_gj123456790.dat without copying files using vbs i.e. need increment 1, everytime when run vbs file. please me. thanks!
the filesystemobject has method .getfile(filespec) returns object file filespec. objects have (writable) .name property. .name, modify it, , write/assign new one.
to give ideas (looping on files in folder, finding file(s) change, extracting number increment):
option explicit dim gofs : set gofs = createobject( "scripting.filesystemobject" ) wscript.quit demomain() function demomain() demomain = 0 ' assume success dim sddir : sddir = gofs.getabsolutepathname(".\") dim revictim : set revictim = new regexp revictim.ignorecase = true revictim.pattern = "^(victim)(\d+)(\.txt)$" dim ofile each ofile in gofs.getfolder(sddir).files if revictim.test(ofile.name) wscript.echo "found: ", ofile.name ofile.name = revictim.replace(ofile.name, getref("finc")) wscript.echo "renamed:", ofile.name end if next end function ' demomain function finc(sm, sg1, sg2, sg3, np, ss) finc = sg1 & right(100 + sg2 + 1, 2) & sg3 end function
output:
cscript finc.vbs found: victim00.txt renamed: victim01.txt cscript finc.vbs found: victim01.txt renamed: victim02.txt cscript finc.vbs found: victim02.txt renamed: victim03.txt
how copy overflow of counter left exercise.
Comments
Post a Comment