Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 6th, 2008, 08:17 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
VBScript - Converting several binary files into one

Good afternoon,

I am wondering how I would put a script together that would take several binary files, and copy them into one file.
Using DOS, I normally type this out like so;
Code:
copy /b file01.wav+file02.wav+file03.wav OneFile.wav

with my script, I got to this point:
Code:
'Initialization Section

Option Explicit
Const cTitle = "Binary File Conversion Wizard"
Dim objFSObject, objFolder, file, strFileList
Set objFSObject = CreateObject("Scripting.FileSystemObject")

'Main Processing Section

objFolder = InputBox("Enter directory where Binary files are found: ", cTitle)
Set objRootDir = objFSObject.GetFolder(objFolder)

'Procedure Section

For Each file In objRootDir.Files
   file.copy /b 
Next

and realized, I don't know how I would make this work properly.
How would you make something like this work ??
Code:
 file.copy /b file & "+" & file & "+" & ... 

Reply With Quote
  #2  
Old August 7th, 2008, 03:35 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Perhaps the easiest way is to use the same concept. VBS can grab the file names and dynamically create your command line.
vb Code:
Original - vb Code
  1. Set objFSObject = CreateObject("Scripting.FileSystemObject")
  2. Set WshShell = CreateObject("WScript.Shell")
  3.  
  4. 'Main Processing Section
  5.  
  6. strFolder = InputBox("Enter directory where Binary files are found: ", cTitle)
  7. Set objRootDir = objFSObject.GetFolder(strFolder)
  8.  
  9. 'Procedure Section
  10.  
  11. For Each file In objRootDir.Files
  12.    strFiles = strFiles & file.Name & "+"
  13. Next
  14.  
  15. strFiles = Left(strFiles, Len(strFiles) - 1)
  16.  
  17. strCommand = "copy /b " & strFiles & " OneFile.wav"
  18.  
  19. WshShell.Run strCommand,, True
The more "programmatic" approach of doing this would involve reading and writing actual binary streams.
vb Code:
Original - vb Code
  1. Set objFso = CreateObject("Scripting.FileSystemObject")
  2. strFolder = InputBox("Enter directory where Binary files are found: ", cTitle)
  3. Set objRootDir = objFSO.GetFolder(strFolder)
  4.  
  5. Const adTypeBinary = 1
  6. Set objOStream = CreateObject("ADODB.Stream")
  7. objOStream.Type = adTypeBinary
  8. objOStream.Open
  9.  
  10. For Each objFile In objRootDir.Files
  11.     objOStream.Write ReadByteArray(objFile.Path)
  12. Next
  13.  
  14. objOStream.Close
  15. objOStream.SaveToFile "OneFile.wmv"
  16.  
  17. Function ReadByteArray(strFile)
  18.     Set objIStream = CreateObject("ADODB.Stream")
  19.     With objIStream
  20.         .Type = adTypeBinary
  21.         .Open
  22.         .LoadFromFile strFile
  23.         ReadByteArray = .Read
  24.     End With
  25. End Function
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Last edited by Nilpo : August 12th, 2008 at 06:18 AM.

Reply With Quote
  #3  
Old August 7th, 2008, 05:27 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
Quote:
Originally Posted by Nilpo
Perhaps the easiest way is to use the same concept. VBS can grab the file names and dynamically create your command line.
vb Code:
Original - vb Code
  1.  
  2. For Each file In objRootDir.Files
  3.    strFiles = strFiles & file.Name & "+"
  4. Next

I eventually figured this part (above) out, although it took me a bit of time in research. It was the file.Name that was throwing me.

vb Code:
Original - vb Code
  1.  
  2. strFiles = Left(strFiles, Len(strFiles) - 1)
  3. strCommand = "copy /b " & strFiles & " OneFile.wav"
  4. WshShell.Run strCommand,, True

And this part (above) is the other piece I was really struggling with. I like the way you made the WshShell.Run command work.

I am understanding most of what is coded here. What it does and how it works. I am however, at a loss for the 'Left ... ' you have in the strFiles line. What does that do ??

The rest of the stuff below is gibberish at the moment. I have a lot more to read up on before I will understand any of that. Although it looks good.
Quote:
Originally Posted by Nilpo
The more "programmatic" approach of doing this would involve reading and writing actual binary streams.
vb Code:
Original - vb Code
  1. Set objFso = CreateObject("Scripting.FileSystemObject")
  2. strFolder = InputBox("Enter directory where Binary files are found: ", cTitle)
  3. Set objRootDir = objFSO.GetFolder(strFolder)
  4.  
  5. Const adTypeBinary = 1
  6. Set objOStream = CreateObject("ADODB.Stream")
  7. objOStream.Type = adTypeBinary
  8. objOStream.Open
  9.  
  10. For Each objFile In objRootDir.Files
  11.     objOStream.Write ReadByteArray(objFile.Path)
  12. Next
  13.  
  14. objOStream.Close
  15. objOStream.SaveToFile "OneFile.wmv"
  16.  
  17. Function ReadByteArray(strFile)
  18.     Set objIStream = CreateObject("ADODB.Stream")
  19.     With objIStream
  20.         .Type = adTypeBinary
  21.         .Open
  22.         .LoadFromFile strFile
  23.         ReadByteArray = .Read
  24.     End With
  25. End Function

Last edited by Nilpo : August 12th, 2008 at 06:18 AM.

Reply With Quote
  #4  
Old August 7th, 2008, 06:58 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Left is a VBS function that returns the leftmost portion of a string for a given number of characters. I'm using it to strip off an extra + character at the end of the string if filenames. Here's the same code commented. This should help.
vb Code:
Original - vb Code
  1. Set objFSObject = CreateObject("Scripting.FileSystemObject")
  2. Set WshShell = CreateObject("WScript.Shell")
  3.  
  4. 'Main Processing Section
  5.  
  6. strFolder = InputBox("Enter directory where Binary files are found: ", cTitle)
  7. Set objRootDir = objFSObject.GetFolder(strFolder)
  8.  
  9. 'Procedure Section
  10.  
  11. 'Create a string of file names separated by a + sign.
  12. For Each file In objRootDir.Files
  13.     'append current file name to the end of string of names
  14.     strFiles = strFiles & file.Name & "+"
  15. Next
  16. 'strFiles is something like:
  17. ' file1.wmv+file2.wmv+file3.wmv+
  18.  
  19. 'Remove the extra + by returning the length of the string minus 1 character
  20. strFiles = Left(strFiles, Len(strFiles) - 1)
  21.  
  22. 'Construct a DOS copy command.
  23. strCommand = "copy /b " & strFiles & " OneFile.wav"
  24.  
  25. 'Execute the command like typing it in the Run... dialog box
  26. WshShell.Run strCommand,, True

Last edited by Nilpo : August 12th, 2008 at 06:18 AM.

Reply With Quote
  #5  
Old August 7th, 2008, 07:13 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
Ahhh, very nice indeed. Thank you Nilpo.
I can think of what I want, (basically what you had put down in the code), but I can't get it onto paper yet.
Thank you very much for the instruction.

Reply With Quote
  #6  
Old August 7th, 2008, 07:38 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Quote:
Originally Posted by Hangman
Ahhh, very nice indeed. Thank you Nilpo.
I can think of what I want, (basically what you had put down in the code), but I can't get it onto paper yet.
Thank you very much for the instruction.
No problem. It takes a little time.

Reply With Quote