Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

VBScript help please


  • Please log in to reply
18 replies to this topic

#1 Stephen W

Stephen W

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 28 October 2012 - 06:34 AM

Hi. I'm looking for somebody who can help me out with some simple VBScript. I use a Web Generator program to organise my photos but it does not do things exactly how I like them. So a while back, and I can't remember where, a kind person helped write me a script to modify things after the Web Generator had done most of the work. I'm now looking to add some extra functions to that script. The Web Generator creates resized verions of my .jpg files, a .css file and a .alb file. I would like the script to delete all those files from the working directory but not from sub-folders. Can anoybody tell me the code I need to add to do this?

Also, I sometimes have files that I would like to rename by script. For example, Photo1(2).jpg, Photo2(2).jpg, Photo3(2).jpg
I would like to become Photo1.jpg, Photo2.jpg, Photo3.jpg
Could anybody write me a script to do this?

Many thanks if anybody can help.

BC AdBot (Login to Remove)

 


#2 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 29 October 2012 - 10:55 AM

Hello Stephen.

The Web Generator creates resized verions of my .jpg files, a .css file and a .alb file. I would like the script to delete all those files from the working directory but not from sub-folders. Can anoybody tell me the code I need to add to do this?

You want a script that simply deletes all files that have .jpg, .css, or .alb as an extension from the folder the script is run from?

Also, I sometimes have files that I would like to rename by script. For example, Photo1(2).jpg, Photo2(2).jpg, Photo3(2).jpg
I would like to become Photo1.jpg, Photo2.jpg, Photo3.jpg

Are all such files named NameOfPhoto(2).jpg , or is there some variation in the number or extension? Are these files in subdirectories too?

Please be very precise about what you want to script.

With Regards,
The Panda

#3 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 29 October 2012 - 10:59 AM

Also, please tell me if you have any experience writing VBScript or Windows Batch files. If at all possible, I would like this to be somewhat of an learning experience, rather than simply giving you the script. However, if programming is completely outside your area of interest and you just want to get this done, I'd be okay with doing that for you too.

#4 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 29 October 2012 - 02:19 PM

Hi PP. With regards to issue one, yes, the script I would like just needs to delete all files, within the folder from where the script is executed (but not sub-folders), with the extensions .jpg, .css, or .alb. But I would like to be able to add the code for this script to the end of my existing script. I'm not sure if it is as simple as just pasting the new code at the bottom of the existing script? Or do certain variables or functions need to be defined higher up in the script in order to do this? I can post my existing script if need be.

In regard to the second issue, (2) was just an example. It could be that the file names have an underscore or _1 at the end, or any other such variation. I would be happy to go into the script and alter this string to whatever it is that I want to replace or delete. But generally it would be a series of files with similar names and an identical part of the name that I would want to remove or possibly replace.

My experience with VBScript and Batch files is very limited, but I do use Matlab at work on a daily basis which uses a very high level programming language which is easy to read and understand. I would not object to this being a learning experience at all. My feeling is that the code required would be very easy for somebody who is experienced with VBScript. So I don't mind whether you want to 'give me the answer' or help guide me through doing it myself.
Thanks for your help either way.
Steve

#5 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 29 October 2012 - 03:48 PM

Hello Steve.

The first task is simple enough that you can just throw this code onto the end of your current script. You can also make a separate script file and test it out first. Note that it will delete files in the current directory of the VBS. This is usually the containing folder, but it may not be if you run the script using Run as Administrator, or call the script some other way.

For each ext in array("jpg","css","alb")
    WScript.CreateObject("WScript.shell").run "cmd.exe /K DEL /Q /F *." & ext & " && Exit" ,2 , false
Next
I'm sure this looks somewhat familiar.

WScript.CreateObject("WScript.shell").run This let's us run a Windows command. This is equivalent to opening up the Run box (Windows+R) and typing in what follows. You can use this command to run any type of file, not just batch scripts. You could, for instance, decide to open one of the photos in question.
"cmd.exe /K DEL /Q /F *." & ext & " && Exit"
We invoke the command line interpreter, cmd.exe, which is very suited to perform these kind of tasks. We use DEL (delete) and pass "*.ext" as the parameter. Notice that the ampersand symbol is used for string concatenation.
If this were the only thing we wanted to perform, we could simply write a batch script with the DEL command in it. We could also do this by using the file system methods available through VBScript, though it's somewhat of a hassle.

As for the second task, we still need to narrow it down. Do we always want to perform a string replace (this includes removing, which is really just replacing with a null string) on the file name? What should we do if the a file already exists with the new name?

With Regards,
The Panda

#6 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 29 October 2012 - 04:41 PM

Thanks for that. If I put the code into a vbs file on its own, it seems to do what I want. However, when I tried adding it in at the end of my existing script, it did not seem to work. In the existing script there are various subroutines, so I tried to copy was was happening with those and put:

Public Sub DelFiles()
For each ext in array("jpg","css","alb")
WScript.CreateObject("WScript.shell").run "cmd.exe /K DEL /Q /F *." & ext & " && Exit" ,2 , false
Next
End Sub

But that did not work either. Do you know what I should do to make this run as part of the existing script, as the last function to be carried out?



For issue 2, you are correct that we do always want to do a string replace. If the replacement filename all ready exists I think it would be best to leave the name of the file as it is and move on to the next one. I can sort out any like that manually and it should not happen often.

#7 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 29 October 2012 - 07:23 PM

Hello.

That code should work as long as it's the last thing in the script. The only reason it would fail is if the files we're trying to delete are still in use while that code is being run. What is going on in the script before you want to delete the files?

Alternatively to calling cmd.exe from within the vbscript, we can create a batch file to first run the vbscript, then carry out the two tasks you specified. This still requires the files we're dealing with not to be in use when we reach the final two tasks.

With Regards,
The Panda

#8 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 30 October 2012 - 01:49 PM

There is some file renaming that goes on and moving of some files to a sub-folder. Perhaps you are right that the files are still in use. I tried the script again but the code does not work when placed at the end of the file. None of the files are deleted. I will paste the whole script below so that you can see what might be going on.



Dim CFN 'Current Folder Name
Dim CF ' Current Folder, Object
Dim FileNames ' File names in current folder. '
Dim FN ' Name of the file. '
Dim ParseFile ' Entire Contents of HTML file. '
Dim ArraySize : ArraySize = 5 ' Size of PicName arrays.
Dim FakePicName()
Dim RealPicName()
ReDim FakePicName(ArraySize) ' Array of the fake name of the Pictures, used for searching. '
ReDim RealPicName(ArraySize) ' Array of the Real name of the Pictures, used for replacing. '
Dim NumOfPicNames : NumOfPicNames = 1 ' The number of unique image names, ignoring _small '
Dim AllFileNames ' The HTML files that have been processed
Dim CreatedFolder ' Whether the folder thumbs was created.
Dim AllPics ' Records all pictures moved
Dim TS : TS = "_small.jpg" ' The string constant _small.jpg
Dim DelStr ' ornj advert to remove'
DelStr = "<p class="+chr(34)+"footnote"+chr(34)+">Photo album created with <a href="+chr(34)+"http://www.ornj.net/"+chr(34)+">Web Album Generator</a></p>"
Dim IndexCount: IndexCount = 1 ' Variable holding the highest X for files IndexX.html

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Get Current Folder '
ScriptPath = Wscript.ScriptFullName
Set objScriptPath = objFSO.GetFile(ScriptPath)
CFN = objFSO.GetParentFolderName(objscriptPath)

' Find the number of IndexX.html files.
Do
NextIndex = true
If objFSO.fileexists(CFN&"\Index"&Cstr(IndexCount + 1)&".html") or objFSO.fileexists(CFN&"\Index"&Cstr(IndexCount + 1)&".htm") then
IndexCount = IndexCount + 1
else
NextIndex = false
end if
Loop until NextIndex = false


' Work through HTML files '
Set CF = objFSO.GetFolder(CFN)
Set files = CF.Files
For each objFile In files
FN = objFile.name
If Lcase(right(FN,4)) = ".htm" or lcase(right(FN,5)) = ".html" then
If objFile.size > 0 then
Set objReadFile = objFSO.OpenTextFile(CFN & "\" & FN, 1) ' Reads contents of file into string parsefile '
ParseFile = objReadFile.ReadAll
objReadFile.Close

ClearET()
If IndexCount > 1 and Lcase(FN) = "index.html" then ExtendIndex()
If IndexCount > 1 then ResetIndexLinks()
PopulatePicNames()
SortPicNames()
HunterSeeeker()
EvacuateThumbs()
KillText(delstr)
BurnToDisk()
If Not Lcase(FN) = "index.html" then RenameFile()
Clean()
AllFileNames = AllFileNames & vbCrLf & FN
end if
end if
Next

' Creates Thumbs folder if it doesn't already exist
If Not objFSO.FolderExists(CFN & "\thumbs") Then
Set newfolder = objFSO.CreateFolder(CFN & "\thumbs")
CreatedFolder = "Created Folder: True"
Else
CreatedFolder = "Created Folder: False"
End If

' Second loop moves thumbnails if necessary'
For each objFile In files
FN = objFile.name
If Lcase(right(FN,10)) = TS then
objFSO.MoveFile CFN & "\" & FN, CFN & "\thumbs\"
AllPics = AllPics & vbCrLf & FN
end if
Next

MsgBox "File Parse Complete:" & vbCrLf & AllFileNames & vbCrLf & CreatedFolder & vbCrLf & AllPics
Wscript.quit






' Start of Subroutines '

Public Sub ExtendIndex()

'Read in IndexX pages

Dim IndexXFile ' Text of the Index file being processed
Dim TableStartPos ' Location of the end of <table>
Dim TableEndPos ' Location of the start of </table>
Dim TableContents ' Text between <table> and </table>
For X = 2 to IndexCount ' Run through each index file
Set objReadFile = objFSO.OpenTextFile(CFN & "\" & "index"&X&".html", 1) ' Reads contents of file into string parsefile '
IndexXFile = objReadFile.ReadAll ' Read in text
objReadFile.Close

TableStartPos = Instr(1, IndexXFile, "<table>")
If TableStartPos > 0 then
TableStartPos = TableStartPos + 9
else
MsgBox "<Table> Tag not found in index file. Aborting Parsing Index Files"
exit sub
end if

TableEndPos = Instr(TableStartPos, IndexXFile, "<td colspan="&chr(34)&"6"&chr(34)&"><div class="&chr(34)&"pages"&chr(34)&">Page:")
TableEndPos = InstrRev(IndexXFile, "<tr>", TableEndPos)
TableEndPos = TableEndPos - 1
If TableEndPos = -1 then
msgbox "Error reading Additional Index page"
wscript.quit
end if
TableContents = mid(IndexXFile, TableStartPos, TableEndPos - TableStartPos)


IndexEndTablePos = Instr(1, ParseFile, "</table>") ' Find location to instert TableContents
ParseFile = left(ParseFile, IndexEndTablePos - 1) & TableContents & vbCrLf & Right(ParseFile, len(ParseFile) - IndexEndTablePos + 1)

Next

' Delete additional Index Pages
For X = 2 to IndexCount
set DelIndex = objFSO.GetFile(CFN & "\index" & cstr(X) & ".html")
DelIndex.Delete
Next

'remove the link to later index pages

LinkStartPos = Instr(1, parsefile, "<td colspan="&chr(34)&"6"&chr(34)&"><div class="&chr(34)&"pages"&chr(34)&">Page:")
LinkStartPos = InstrRev(parsefile, "<tr>", LinkStartPos)
LinkEndPos = Instr(LinkStartPos, Parsefile, "</tr>")
Parsefile = Left(Parsefile, LinkStartPos - 1) + Right(ParseFile, Len(parsefile) - LinkEndPos - 6)

End Sub


Public Sub ResetIndexLinks()
Dim CHSp ' Crosshairs Start Position, where the target begins. '
Dim Searchterm '
Dim Replaceterm '
For X = Indexcount to 2 step - 1
Searchterm = "index" & cstr(X) & ".htm"
Replaceterm = "index.htm"
CHSp = 1
Do
CHSp = Instr(CHSp, ParseFile, Searchterm) - 1
If CHSp > -1 then
ParseFile = Left(ParseFile, CHSP) & Replaceterm & right(ParseFile, Len(ParseFile) - len(Searchterm) - CHSp)
CHSp = CHSp + len(ReplaceTerm)
end if
Loop until CHSp = -1
Next
end sub

Public Sub ClearEt()
Dim WrongEtStr : WrongEtStr = "&amp;"
Dim EtSp : EtSp = 1 ' Et Start point
Do
EtSp = Instr(EtSp, ParseFile, WrongEtStr) - 1
If not EtSp = -1 then
ParseFile = left(ParseFile, EtSP) & "&" & Right(ParseFile, Len(ParseFile) - EtSp - 5)
End if
Loop until EtSp = -1
End Sub

Public Sub PopulatePicNames()
Dim ISp: ISp = 1 ' Image Start Position '
Dim IEp ' Image End Position '
Dim LIEp: LIEp = 1 ' Last Image End Position '
Dim FPN ' Temporary holder Fake picture name, check that it isn't already in the array '
Dim RPN ' Temporary holder Real picture name, check that it isn't already in the array '

Do
' Get image text '
ISp = Instr(LIEp, ParseFile, "<img")
If ISp > 0 then
IEp = Instr(ISp, ParseFile, ".jpg" & chr(34) & " />") + 8
LIEp = IEp + 1
ImageText = mid(ParseFile, ISp, IEp-ISp)

' extract Fake and Real names from Image text '
FPN = FindFN(ImageText)
RPN = FindRN(ImageText)

AlreadyHasFPN = False
AlreadyHasRPN = False
If NumOfPicNames > 1 then
For X = 1 to NumOfPicNames - 1
If FPN = FakePicName(X) then AlreadyHasFPN = True
If RPN = RealPicName(X) then AlreadyHasRPN = True
Next
End if

IncNOPN = 0 ' A test that both are unique, or neither. '
If not AlreadyHasFPN then FakePicName(NumOfPicNames) = FPN : IncNOPN = 1
If not AlreadyHasRPN then RealPicName(NumOfPicNames) = RPN : IncNOPN = IncNOPN + 1
If IncNOPN = 2 then NumOfPicNames = NumOfPicNames + 1
If IncNOPN = 1 then Housten()
If NumOfPicNames = ArraySize then
ArraySize = ArraySize * 2
ReDim preserve FakePicName(ArraySize)
ReDim preserve RealPicName(ArraySize)
end if
End if
Loop until ISp = 0
NumOfPicNames = NumOfPicNames - 1
End Sub

Public Sub SortPicNames() ' Aranges pic names longest first, to avoid replacing Photo1 with the name associated with Photo. '
For X = 1 to NumOfPicNames - 1
For Y = 1 to NumOfPicNames - X
If Len(FakePicName(Y)) < Len(FakePicName(Y+1)) then
SortTemp = FakePicName(Y+1)
FakePicName(Y+1) = FakePicName(Y)
FakePicName(Y) = SortTemp
SortTemp = RealPicName(Y+1)
RealPicName(Y+1) = RealPicName(Y)
RealPicName(Y) = SortTemp
end if
Next
Next
End sub

Public Sub HunterSeeeker()
Dim CHSp ' Crosshairs Start Position, where the target begins. '
Dim Searchterm '
Dim Replaceterm '
For X = 1 to NumOfPicNames
For SearchCase = 1 to 3
Select Case SearchCase
Case 1
Searchterm = chr(34) & FakePicName(X) & ".jpg"
Replaceterm = chr(34) & RealPicName(X) & ".jpg"
Case 2
Searchterm = chr(34) & FakePicName(X) & "_small.jpg"
Replaceterm = chr(34) & RealPicName(X) & "_small.jpg"
Case 3
Searchterm = chr(34) & FakePicName(X) & ".htm"
Replaceterm = chr(34) & RealPicName(X) & ".htm"
end select
CHSp = 1
Do
CHSp = Instr(CHSp, ParseFile, Searchterm) - 1
If CHSp > -1 then
ParseFile = Left(ParseFile, CHSP) & Replaceterm & right(ParseFile, Len(ParseFile) - len(Searchterm) - CHSp)
CHSp = CHSp + len(ReplaceTerm)
end if
Loop until CHSp = -1
Next
Next
End Sub

Public Sub EvacuateThumbs()
Dim FS ' Numeric location of the string TS in UnParsedFile'
Dim FQ ' Numeric Location of the quote mark " before _small.jpg.'
Dim LFS ' Last location of the end of the last TS found'
LFS = 1
Do
FS = Instr(LFS, ParseFile, TS)
If FS > 0 then
FQ = FS
Do
FQ = FQ - 1
Loop until mid(ParseFile, FQ, 5) = "src=" + CHR(34)
FQ = FQ + 4
If not mid(Parsefile, FQ+1,7) = "thumbs\" then
ParseFile = left(ParseFile, FQ) & "thumbs\" & right(ParseFile, len(ParseFile) - FQ)
end if
LFS = FS + 7
end if
Loop until FS = 0
End Sub

Public Sub KillText(TextToRemove)

Dim FQ ' Numeric Location of the start of DelStr.'
Do
FQ = Instr(1, ParseFile, TextToRemove)
If FQ > 0 then
If len(ParseFile) > FQ + Len(TextToRemove) then
ParseFile = left(ParseFile, FQ - 1) & Right(Parsefile,len(ParseFile) - FQ - Len(TextToRemove) - 1)
else
ParseFile = left(ParseFile, FQ - 1)
end if
end if
Loop until FQ = 0
End Sub

Public Sub BurnToDisk()
Set objFile = objFSO.OpenTextFile(CFN & "\" & FN, 2, True)
objFile.writeline(ParseFile)
objFile.close
End Sub

Public Sub RenameFile()
Dim RealFileName ' Value from within <Title> element '
Dim FFN : FFN = left(FN, instr(1, lcase(FN), ".htm") - 1 ) ' Fake File Name, the name of the picture matching this HTML file '
RealFileName = FindRFN(ParseFile)
if Lcase(right(FN, 5)) = ".html" then objFSO.moveFile CFN & "\" & FN, CFN & "\" & RealFileName & ".html"
if Lcase(right(FN, 4)) = ".htm" then objFSO.moveFile CFN & "\" & FN, CFN & "\" & RealFileName & ".htm"
if objFSO.FileExists(CFN & "\thumbs\" & FFN & "_small.jpg") Then objFSO.moveFile CFN & "\thumbs\" & FFN & "_small.jpg" , CFN & "\thumbs\" & RealFileName & "_small.jpg"
if objFSO.FileExists(CFN & "\" & FFN & "_small.jpg") Then objFSO.moveFile CFN & "\" & FFN & "_small.jpg", CFN & "\" & RealFileName & "_small.jpg"
if objFSO.FileExists(CFN & "\" & FFN & ".jpg") Then objFSO.moveFile CFN & "\" & FFN & ".jpg" , CFN & "\" & RealFileName & ".jpg"
End Sub

public function FindRN(Img) ' Find the real name of an image from the title attribute '
Dim RN ' Real name '
Dim RNSp : RNSp = 1 ' Real Name Start Position, location of the " before the real name of the picture. '
Dim RNEp : RNEp = 1 ' Real Name End Position, location of the " after the real name of the picture. '

RNSp = Instr(1, Img, "title=") + 7
RNEp = RNSp
Do
RNEp = RNEp + 1
loop until mid(img, RNEp, 1) = chr(34)
RN = mid(img,RNSp, RNEp - RNSp)
FindRN = RN
End function

public function FindFN(Img) ' Find the Fake name of an image from the title attribute '
Dim FN ' Fake name '
Dim FNSp : FNSp = 1 ' Fake Name Start Position, location of the " before the fake name of the picture. '
Dim FNEp : FNEp = 1 ' Fake Name End Position, location of the " after the fake name of the picture. '

FNSp = Instr(1, Img, "src=") + 5
FNEp = Instr(FNSp, Img, "_small.jpg")
If FNEp = 0 then FNEp = Instr(FNSp, Img, ".jpg")
FN = mid(img,FNSp, FNEp - FNSp)
FindFN = FN
End function

Public Function FindRFN(Text) ' Find the preferred name of the html file from the Title '
Dim RFNSp: RFNSp = Instr(1, Text, "<title>") + 7 ' Real File Name Start Position '
Dim RFNEp: RFNEp = Instr(RFNSp, Text, "</title>") ' Real File Name End Position '
RFN = mid(Text, RFNSp, RFNEp - RFNSp)
FindRFN = RFN
End Function

Public Sub Housten()
MsgBox "Housten, We have a problem. Coming down to Earth, fast!"
MSgBox "Partial Picture Identifier match--two pictures share either the same real name of the same fake name but not both."
Wscript.quit
End sub

Public Sub Clean()
For X = 1 to ArraySize
FakePicName(X) = ""
RealPicName(X) = ""
Next
NumOfPicNames = 1
Parsefile = ""
Arraysize = 5
ReDim FakePicName(ArraySize)
ReDim RealPicName(ArraySize)
End Sub

Public Sub DelFiles()
For each ext in array("jpg","css","alb")
WScript.CreateObject("WScript.shell").run "cmd.exe /K DEL /Q /F *." & ext & " && Exit" ,2 , false
Next
End Sub

#9 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 30 October 2012 - 02:04 PM

Hello.

I'm thinking it'll be easier just to call the VBScript form a batch file, then use the rest of the batch file to perform the deletions. This way we can guarantee that no files are open. Does the .vbs file run from the same folder as the files we need to delete are in?

Is the folder where we must rename files completely separate? Do we need to rename for files in subfolders?

With Regards,
The Panda

#10 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 30 October 2012 - 02:08 PM

The 2nd problem of renaming files, by replacing a string, is entirely separate and can be a separate script. It is not related to the Web Generator software.

#11 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 30 October 2012 - 02:17 PM

Does the .vbs file run from the same folder as the files we need to delete are in?

#12 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 30 October 2012 - 02:20 PM

Correct

#13 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 30 October 2012 - 02:34 PM

Hello.

Then in the first problem, we can use this script.

Save this script as RunVbsAndDel.bat in the same folder as your vbscript. Replace "NameOfScript" with whatever the name of your .vbs is. You should also remove the code we added on to the end of the vbscript.
@ECHO OFF

NameOfScript.vbs

FOR %%A in (jpg css alb) DO (
    DEL /Q /F *.%%A
)

Does that work out?

With Regards,
The Panda

#14 Stephen W

Stephen W
  • Topic Starter

  • Members
  • 210 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Norwich, UK
  • Local time:01:43 PM

Posted 30 October 2012 - 04:59 PM

Although that would work, I can just execute the 2 scripts that I have now to achieve the same result. I would prefer to get the script all working in a single file if possible. I assume you can't see anything odd in the code I posted? Could we try putting a pause time near the end before executing the delete file code? If not, the solution I have with the 2 scripts is probably next best.
Thanks

#15 PropagandaPanda

PropagandaPanda


  • Malware Response Team
  • 10,433 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:43 AM

Posted 31 October 2012 - 12:32 PM

Hello Steve.

I think I see the problem. The VBscript exitted before it reached the code we added.

In the full code you posted, add
DelFiles()

Before
MsgBox "File Parse Complete:" & vbCrLf & AllFileNames & vbCrLf & CreatedFolder & vbCrLf & AllPics 
Wscript.quit
You need to keep the "Public Sub DelFiles()" function at the end of course.

That that work out?

With Regards,
The Panda




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users