Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script editing - base64 for files in folder

Status
Not open for further replies.

jahelka

IS-IT--Management
Feb 9, 2007
2
CZ
Hi, the script only converts one file. Can you help me edit it for folder? Convert all files in the source folder to target folder (same file name as in the source folder). Thank you for your help.

Script:

inputFile = "D:\Folder\files_row_1_dmEncodedContent.blob"
outputFile = "D:\Folder2\files_row_1_dmEncodedContent.blob"

Set fso = CreateObject("Scripting.Filesystemobject")
Set input=fso_OpenTextFile(inputFile,1)
contents = input.ReadAll()
input.Close

Set oXML = CreateObject("Msxml2.DOMDocument")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = contents

Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = 1 'adTypeBinary
BinaryStream.Open
BinaryStream.Write oNode.nodeTypedValue
BinaryStream.SaveToFile outputFile
 
Hi,
Here is an working example how to process all files in a folder.
Modify and try the example, so it prints all file paths in your folders. Then relocate your code in the subroutine ConvertFile and it should do the work.

convert_files.vbs
Code:
inputFolder [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"c:\folder"[/color]
outputFolder [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"c:\folder2"[/color]

[COLOR=#804040][b]Set[/b][/color] fso [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Scripting.FileSystemObject"[/color][COLOR=#804040][b])[/b][/color]
countFiles [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]for[/b][/color] [COLOR=#804040][b]each[/b][/color] file [COLOR=#804040][b]in[/b][/color] fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]GetFolder[/color][COLOR=#804040][b]([/b][/color]inputFolder[COLOR=#804040][b]).[/b][/color][COLOR=#a020f0]Files[/color] 
  inputFile [COLOR=#804040][b]=[/b][/color] fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]BuildPath[/color][COLOR=#804040][b]([/b][/color]inputFolder[COLOR=#804040][b],[/b][/color] file[COLOR=#804040][b].[/b][/color][COLOR=#804040][b]Name[/b][/color][COLOR=#804040][b])[/b][/color]
  outputFile [COLOR=#804040][b]=[/b][/color] fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]BuildPath[/color][COLOR=#804040][b]([/b][/color]outputFolder[COLOR=#804040][b],[/b][/color] file[COLOR=#804040][b].[/b][/color][COLOR=#804040][b]Name[/b][/color][COLOR=#804040][b])[/b][/color]
  [COLOR=#804040][b]call[/b][/color] ConvertFile[COLOR=#804040][b]([/b][/color]inputFile[COLOR=#804040][b],[/b][/color] outputFile[COLOR=#804040][b])[/b][/color]
  countFiles [COLOR=#804040][b]=[/b][/color] countFiles [COLOR=#804040][b]+[/b][/color] [COLOR=#ff00ff]1[/color]
[COLOR=#804040][b]next[/b][/color]
wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Done. "[/color] [COLOR=#804040][b]&[/b][/color] countFiles [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]" files converted."[/color]  

[COLOR=#804040][b]sub[/b][/color] ConvertFile[COLOR=#804040][b]([/b][/color]inputFile[COLOR=#804040][b],[/b][/color] outputFile[COLOR=#804040][b])[/b][/color]
  wscript[COLOR=#804040][b].[/b][/color]echo [COLOR=#ff00ff]"Converting """[/color] [COLOR=#804040][b]&[/b][/color] inputFile [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]""""[/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]VbCrLF[/color] [COLOR=#804040][b]& _[/b][/color]
               [COLOR=#ff00ff]"        to """[/color] [COLOR=#804040][b]&[/b][/color] outputFile [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]""""[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top