As it turns out, over 63% of visitors have been to one of just 2 articles (Sweet VBScript – command line parameters and VBScript Current Directory or Folder) I’m puzzled. These are brilliantly useful articles, but is there anything else people are trying to get done? VBScript? Powershell? Windows Installer? If you have questions or requests, put them up!
What next? Requests?
January 9, 2012 by leereid
Is there anyway to export the contents of a folder to an xml file through a batch script?
I guess it depends what you’re trying to export. Is it filenames? File contents? Does it need to be a batch file?
On the command prompt, you could use something like DIR to get file names or FOR to do commands recursively.
In VBScript or powershell there are a few options for navigating folders. Let me know what you’re trying to get as output.
I’m just trying to export the file names and date and time of creation. And yes it has to be a batch file as I will need to run it quite often for different folders. 🙂
I’ll provide a method for doing this in VBScript. Hey Scripting Guy provides some datecreated logic.
‘ First declare some variables
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
foldername = “C:\Temp”
Set folder = objFSO.GetFolder(foldername)
Set files = folder.Files
‘ Next process each file in the folder
For each file In files
thisFilename = file.Name ‘ Get the file name
Set objFile = objFSO.GetFile(foldername & “\” & thisFilename) ‘ Create a file object
strDate = Left(objFile.DateCreated, 10) ‘ Get the date created and return only the date
Wscript.Echo thisFilename & ” – ” & strDate
Next
From here you can do whatever manipulation you need to output the file how you want
Thanks a lot… 🙂
ok… Now what if I want to save a status sort of thingie for each file. I mean a person should be able to open the webpage n see the current status of a file (eg stage 1, 2, etc.) and change the status and save it for future.
Then instead of (or as well as) using WScript.Echo you may want to write to a file like
Dim OutStream: Set OutStream = objFSO.OpenTextFile(outputFileName, 2, True)
OutStream.Write thisFilename & ” – ” & strDate
I’m not clear on what else you’re working through, if you can break it down into small units you may have more success
Thanks a lot!! You’ve been a great help!! 🙂 Can you tell me how do I check if a string exists in an xml file using vbScript?
You want me to post my VBScript issues? Oh alright, don’t say I didn’t warn you, though (ok, I didn’t but still…)
So, I’m just starting out with VBScript, meaning that dumb questions are all I’ve got. I’m using it to modify FileZilla Server user settings XML file (“FileZilla Server.XML”) via the command line (so I can pass command-line params from another application). So far I can add a user account (I even have an MD5 Hash function for the password) and I can delete, but I’m stuck trying to mod an existing password. I basically need to mod a string, but the username is on one line (search string), and the password is on the next, thus:
04f3ca09710750d131f8491233f4b4f7
I can pass the username as a parameter/variable, and like I say I have the hash ready to go, but… Any pointers how to go about it? I keep telling myself I need a LEN/SUBSTRING/PATINDEX kind of deal, but then I have a T-SQL background, so I would…
So you’re trying to get 04f3ca09710750d131f8491233f4b4f7 out of the string below?
{Option Name=”Pass”}04f3ca09710750d131f8491233f4b4f7{/Option}
You’re looking for what comes after and before then.
There’s 2 main options I’d consider:
1. InStr – Find if is in the string you’re searching and return where it starts. Then add on the length of and you should have a string starting with your password. Then you can do some fiddling to remove the /Option bit from the end.
Try putting this in a script
myinput=”04f3ca09710750d131f8491233f4b4f7″
WScript.Echo myinput
value = “”
WScript.Echo value
startPos = InStr(myinput,value)
WScript.Echo startPos
WScript.Echo startPos + Len(value)
WScript.Echo Right(myinput,Len(myinput)-(startPos + Len(value))+1)
2. Split – Use what you’re searching for as a delimiter to split the string up. Usually this is used for splitting up strings like: “ID123,Username,Town”, but you can use whatever you like to split the strings. You’ll need to be careful to check for errors if your input isn’t what you expect.
Try putting this in a script
myinput=”04f3ca09710750d131f8491233f4b4f7″
WScript.Echo myinput
value = “”
WScript.Echo value
myarray = Split(myinput,value)
WScript.Echo myarray(1)
secondarray = Split(myarray(1),””)
WScript.Echo secondarray(0)
3. Good luck!
oops! Maybe this will look better:
‘
’04f3ca09710750d131f8491233f4b4f7
{User Name=”KevCorp”}
{Option Name=”Pass”}04f3ca09710750d131f8491233f4b4f7{/Option}
So sorry, like a dumbass I left the chevrons in, and I think WordPress is trying to do something with them!
For the annoying number of entries above, { is a left chevron, and } is the closing one…