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!
Advertisement
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?