Solved

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

Posted on 2014-09-24
11
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40343208
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
ID: 40344116
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
ID: 40344189
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 28

Accepted Solution

by:
Bill Bach earned 500 total points
ID: 40344203
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
ID: 40352070
I've requested that this question be deleted for the following reason:

The script does not produce the EOF marker.
0
 
LVL 28

Expert Comment

by:Bill Bach
ID: 40352071
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
ID: 40352103
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
ID: 40352135
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
ID: 40352197
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
ID: 40352361
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
ID: 40382544
The script does not produce the EOF character, therefore there is no problem with the script.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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