• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

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.
0
capital052798
Asked:
capital052798
1 Solution
 
kwstairCommented:
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
 
scrathcyboyCommented:
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
 
AmazingTechCommented:
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
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
capital052798Author Commented:
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
 
AmazingTechCommented:
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
 
capital052798Author Commented:
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
 
AmazingTechCommented:
Glad it worked. We use the same script here to remove problem characters.
0
 
capital052798Author Commented:
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
 
AmazingTechCommented:
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now