Solved

How can I modify this script so that the output does not add the undesired character?

Posted on 2014-09-24
11
135 Views
Last Modified: 2014-10-15
This is the script I am working with:

Set fso = CreateObject("Scripting.FileSystemObject")

data = Split(fso.OpenTextFile("file.txt").ReadAll, "AIS*00*")
For i = 1 To UBound(data)
  fso.OpenTextFile("new" & i & ".txt", 2, True).Write "AIS*00*" & data(i)
Next


After splitting the files and creating new ones, one of the files contains a very small right arrow, which for some reason I cannot copy and paste into this box.  

That right arrow does not belong.

How can I modify the script so that the output does not contain the right arrow?
0
Comment
Question by:100questions
  • 6
  • 5
11 Comments
 
LVL 28

Expert Comment

by:Bill Bach
Comment Utility
If you look at the source data with a hex editor, does it show a Ctrl-Z at the end?  Some text editors are known to put this DOS EndOfFile character at the end of the file. If it is not a 26(decimal), then what is it?
0
 

Author Comment

by:100questions
Comment Utility
It's a small right arrow character.
I tried to copy it below however it's not showing up...
I inserted an image so you can see it.  

IEA*1*00000~


Open in new window


rightarrow.png
When combining text files together it adds this small arrow at the end of the files.  

I can't have this show up
0
 

Author Comment

by:100questions
Comment Utility
I found out that the script above does not cause the undesired character.
If one of the original text files themselves have the character when splitting the files using the above script, it just kept that character.
If there is a way to modify the script so that it will remove the character in a file then that would be fine.
0
 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
Comment Utility
I checked, and this is definitely an ASCII EOF marker.  As Wiki states: "In some operating systems, Control+Z is used to signal an end-of-file, and thus known as the EOF character (more accurately: the EOF control code), when typing at a terminal, terminal emulator, MS-DOS command line, or Win32 console. Early DEC operating systems used this convention, which was borrowed by CP/M, and was later in turn borrowed and continued in the MS-DOS and Microsoft Windows operating systems."

Obviously, this is not needed any more, but some programs still create it.  My guess is that it ONLY appears on the LAST file your script creates?  This would be because the INPUT file contains the Ctrl-Z character as an EOF marker.  Where are you getting the file from?  Can you request that they give you a "clean" file with no EOF marker?

If you don't see the EOF marker in your source data, then perhaps the OpenTextFile function is adding it for you, because you are opening in ASCII mode.  Use the optional format parameter to open the file as BINARY instead:
    object.OpenTextFile(filename[, iomode[, create[, format]]])
That may make it go away.

If the EOF marker is there and you still cannot get this working, then another option is to open the source file in BINARY mode, determine the file's length, and rewrite it to a temporary file name, but write one byte short.  For smaller files, this won't add too much overhead, but it could have an impact on larger files.
0
 

Author Comment

by:100questions
Comment Utility
I've requested that this question be deleted for the following reason:

The script does not produce the EOF marker.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 28

Expert Comment

by:Bill Bach
Comment Utility
Why are you closing this?  While the script didn't "create" the EOF marker, it is still possible to "modify the script so that the output does not contain" the EOF marker, as indicated in my last post.  If you need me to actually write the file copy function for you, then I can certainly do that, too, but it was unclear if that level of detail was required yet.
0
 

Author Comment

by:100questions
Comment Utility
The last file is the one that contained the EOF marker.
If this script can be modified so that it removed the EOF marker in any file it find, then yes, a modified script would be welcome.   Thank you.
0
 
LVL 28

Expert Comment

by:Bill Bach
Comment Utility
Your original category ALSO included Batch files -- Do you have a batch file that calls this splitter?  This simple command would work, and very very fast:
    type file.txt>file2.txt
Then, just import FILE2.TXT instead.  You could also issue a shell command in VBScript with the same command if needed, but if there is a batch file in front of it, the one-liner would be easiest.
0
 

Author Comment

by:100questions
Comment Utility
The above is part of the batch file which runs.  

I don't understand.  Do I insert the command into my script?
0
 
LVL 28

Expert Comment

by:Bill Bach
Comment Utility
No -- insert the command into the batch file that calls the VBScript, immediately prior to the call.

If you are confusing the concept of "batch file" and "VBScript", then you may only have a VBScript, and no batch file calling it.  In that case, the following sequence should work to issue the same statement, which can be placed inside the VBScript file:

Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "type c:\data\file.txt>c:\data\file2.txt"
Set objShell = Nothing

Note that you'll need to set the right path and file names here, too.
0
 

Author Closing Comment

by:100questions
Comment Utility
The script does not produce the EOF character, therefore there is no problem with the script.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now