Solved

Automate Opening Saving large number of txt files in Notepad

Posted on 2008-10-15
9
440 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article shows how to convert a multi-page PDF file into multiple image files, with one image file created for each page of the PDF. It does this by utilizing an excellent, free software package called GraphicsMagick. The solution is amazingly s…
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

762 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

19 Experts available now in Live!

Get 1:1 Help Now