Solved

Automate Opening Saving large number of txt files in Notepad

Posted on 2008-10-15
9
445 Views
Last Modified: 2008-10-20
I have a large number of files that I have down loaded from a mainframe.
As the files have come from the mainframe - embedded within the text are
chara's containing null (code=0). This is causing problems with my text editor
when I wish to copy chunks of the data elsewhere.
I have since discovered that if I open the files using Notepad.exe and then save the files from
Notepad - this somehow gets rid of the null(code=0) charas.
I can then use my more heavy duty text editor - to manipulate the data as I please.
I have played around with using an old DOS batch programme whereby I can open the files automatically
in Notepad but I can't seem to be able to save and close Notepad files with DOS commands.
Does anyone have a suggestion on how I can tackle this problem?
Thank you.
0
Comment
Question by:capital052798
9 Comments
 

Expert Comment

by:kwstair
ID: 22723851
Try a free program you can download called AutoIT.  It is an easy to learn programming tool that has examples that should help you do what you want.  Download the editor that comes with it as it makes it much easier learning the language.

It can be found at http://www.autoitscript.com/
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22727040
Notepad has a unique ability to strip out ALL formatting and odd characters that almost all other editors try to preserve, even notepad clones.  

You would have to setup a routine that opened every file in a folder with notepad and saved to a different name.  Here is a list of notepad command line arguments -- you see the open, but no save-as command.

/A <filename> open file as ansi
/W <filename> open file as unicode
/P <filename> print filename
/PT <filename> <printername> <driverdll> <port>
/.SETUP enumerates the systemdir and opens notepad without the minimize option.

So no, it probably isn't possible to create a fully automated batch file.  You would have to have a keystroke recorder once the program is opened.  But look at these anyway --

http://notepad-plus.wiki.sourceforge.net/Command+Line+Switches
www.tomshardware.com/forum/53953-45-notepad-command-line-switch-encoding-method
support.microsoft.com/kb/66083
www.tek-tips.com/viewthread.cfm?qid=541425&page=7
forums.techguy.org/all-other-software/133030-notepad-command-line-dos-switches.html
www.codeguru.com/forum/showthread.php?t=354234
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22735534
Save the attached code as .vbs something like OpenSave.vbs

Adjust the wscript.sleep with enough of a delay that notepad has opened the file.

Using a batch file or from the DOS prompt you can execute the script.

eg.

C:
CD \UNIXFiles
for /f "tokens=*" %a in ('dir /b *.txt') do cscript c:\scripts\opensave.vbs "%a"

or into a batch file.

C:
CD \UNIXFiles
for /f "tokens=*" %%a in ('dir /b *.txt') do cscript c:\scripts\opensave.vbs "%%a"

Set objShell = CreateObject("Wscript.Shell")
 
ret = objShell.run("Notepad.exe " + chr(34) + WScript.Arguments.item(0) + chr(34))
wscript.sleep 1500
 
objshell.SendKeys "^s", True
 
objshell.SendKeys "%{F4}", True

Open in new window

0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:capital052798
ID: 22739043
Thanks for all the replies.
AmazingTech - I do not have VisualBasic - which I am guessing I need to run the code you suggest.
Anyway I have tried it but I am getting the error message
                         Input Error there is no file extension in C:\UNIXFiles\dir
I didn't have directory UNIXFiles - so I set one up - but as there is nothing in there I don't think it is doing anything.
Also re
 ('dir /b *.txt')
Do I use forward or backward slash for the path I want? Which is
C:\Closures\2005\04Apr
Also my files are *.SR1.
Thanks again


0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 125 total points
ID: 22741426
This is not VisualBasic it is VBScript which is included with XP. It seems to be doing something on you computer if you are getting those errors. Here's it updated with your specifics.

Place the code in a .bat file.

OpenSave.vbs you put this in C:\scripts folder correct?
C:
CD \Closures\2005\04Apr
for /f "tokens=*" %%a in ('dir /b *.sr1') do cscript c:\scripts\opensave.vbs "%%a"

Open in new window

0
 

Author Comment

by:capital052798
ID: 22741902
AmazingTech
Hey! Magic - it works great.
I thought the file directory needed to replace 'dir /b but now I can see differently.
Many thanks (also to kwstair and scrathcyboy)
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22742517
Glad it worked. We use the same script here to remove problem characters.
0
 

Author Comment

by:capital052798
ID: 22757370
AmazingTech
Sorry to ask this now the question is closed - and reply if it only takes a few seconds to answer but
is it possible to get the script to process all files in a series of sub subdirectories?
I actually have daily files going back 10 years!
So I have c:\closures, then as a sub-directories, c:\closures\1998 etc through to c:\closures\2008
then as subdirectories - the months e.g. c:\closures\2007\01Jan through 12Dec.
The actual base files *.SR1 are then stored within the monthly directories.
It would be nice to set the routine off by telling it to process all the files within sub/subdirectories.
I have actually copied the routines 240 times over with each specific file directory and it seems to work on a small test sample. It is just that the code is not very elegant.
Thanks again for your help.
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22758887
Yup. Try this.
:
CD \Closures\2005\04Apr
for /f "tokens=*" %%a in ('dir /s /b *.sr1') do cscript c:\scripts\opensave.vbs "%%a"
 

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Let’s list some of the technologies that enable smooth teleworking. 
The viewer will learn common shortcuts with easy ways to remember them. The viewer will then learn where to find all of the keyboard shortcuts, how to create/change them, and how to speed up their workflow.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

839 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