Solved

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

Posted on 2014-09-24
11
139 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
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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