?
Solved

Automate Opening Saving large number of txt files in Notepad

Posted on 2008-10-15
9
Medium Priority
?
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

771 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