Jump to content
Sign in to follow this  
AMS

New to AutoIt

Recommended Posts

AMS

I need to open an external program and within that program I need to open a file, copy all the text in it, paste it into a new Notepad document, save the Notepad document with the file's original name and then loop this. How would I go about doing this?

;~ Read in a file ->FileFindFirstFile ( "filename" )

;~ Check if file exists ->FileExists ( "path" )

;~ Open file ->FileOpen ( "filename" [, mode ] )

;~ Get file name -> FileRead ( "filehandle/filename" [, count] )

;~ Get text/data from file

;~ open new notepad document

;~ notepad receives data

;~ notepad saves new document as original file name

; repeat ->FileFindNextFile ( search )

This is what I attempted to plan out, but I just started using AutoIt yesterday so I'm not really sure if I'm doing it right.

Thanks for any help you might be able to lend me ;)

Share this post


Link to post
Share on other sites
boshi

_FileReadToArray and _FileReadFromArray might be other useful function.

Share this post


Link to post
Share on other sites
AMS

_FileReadToArray and _FileReadFromArray might be other useful function.

Ok, but my current problem is that I can't seem to be able to open a file inside the program. Do you know how I could do that?

Share this post


Link to post
Share on other sites
TonyP

Um, probably is easier to open a file with a program rather than open a file from inside the program.

FileOpen() if it is a txt file.

Which leads to the question of what program are you trying to open.

Edited by xenon2050

Share this post


Link to post
Share on other sites
AMS

Um, probably is easier to open a file with a program rather than open a file from inside the program.

FileOpen

But then won't the program have to close and then open again once I set the loop up? I was hoping I could just leave the program open and it would batch process them so to speak. I'll try that though and see how it goes.

Share this post


Link to post
Share on other sites
TonyP

But then won't the program have to close and then open again once I set the loop up? I was hoping I could just leave the program open and it would batch process them so to speak. I'll try that though and see how it goes.

Well I'm no Autoit guru so I'm not sure of the best way to do that. Another option is using notepad's command line way to open a file: notepad.exe TextFileName

You could try using shortcut keys ControlSend, but then I don't know how you could select the file you are trying to open.

Share this post


Link to post
Share on other sites
kaotkbliss

If it's a text file, use fileread

You will be able to read the entire contents of the file without physically opening it, make changes and save a new file with the changes.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
TonyP

If it's a text file, use fileread

You will be able to read the entire contents of the file without physically opening it, make changes and save a new file with the changes.

Oh yeah, completely forgot about that. But he still hasn't said if its actually a text file yet.

Share this post


Link to post
Share on other sites
seandisanti

There are a lot of ways to skin that particular cat. Personally i'd say read in the file and close it, with any of the options given already, or just _FileReadToArray and make one continuous string with _ArrayToString. at that point you'll have one nice delimited string of the file contents that you can chop up and replace any way you like using StringRegExp or StringReplace() etc -and then just do filewrite, or ControlSetText("Untitled - Notepad","",15,$YourModifiedString) especially if you want to proofread the document before saving the first couple of times.

Share this post


Link to post
Share on other sites
seandisanti

Oh yeah, completely forgot about that. But he still hasn't said if its actually a text file yet.

probably a good bet if he was originally looking to do the work in notepad ;)

Share this post


Link to post
Share on other sites
AMS

probably a good bet if he was originally looking to do the work in notepad ;)

It's a program called BobCAD and the file format is .cnc, what appears to be a proprietary format. That's why things like Notepad can not open these files without it looking all crazy like. It needs to be open within BobCAD to be rendered properly :)

Share this post


Link to post
Share on other sites
seandisanti

It's a program called BobCAD and the file format is .cnc, what appears to be a proprietary format. That's why things like Notepad can not open these files without it looking all crazy like. It needs to be open within BobCAD to be rendered properly ;)

and you want to export from that to notepad? does it have an export/save as text functionality within the program?

Share this post


Link to post
Share on other sites
CNCMONKEY

and you want to export from that to notepad? does it have an export/save as text functionality within the program?

is this file a binary file perhaps? and not a encrypted txt?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×