Link to home
Start Free TrialLog in
Avatar of capital052798
capital052798Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Automate Opening Saving large number of txt files in Notepad

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.
Avatar of kwstair
kwstair

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/
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
Avatar of AmazingTech
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

Avatar of capital052798

ASKER

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


ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
Glad it worked. We use the same script here to remove problem characters.
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.
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