Sign in to follow this  
Followers 0
idenniske

open my textfile

22 posts in this topic

Hello,

Im new with autoIT. i tried to open my file and do a couple of backspaces.

What is the correct way to open the file and do 4 backspaces? This is the path to the file:

C:\xampp\htdocs\test\kennislong.txt

i hope you guys can help me.

Share this post


Link to post
Share on other sites



I did, couldn't find it. You are the pro so please help me

Share this post


Link to post
Share on other sites

do 4 backspaces?

means "delete 4 characters"?

So your script would consist of

fileread (reads file into a single variable)

delete characters

filewrite (writes file from a single variable)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

$file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileClose($file)

It won't open my file

Share this post


Link to post
Share on other sites
  • Does the file exist?
  • Has it been opened by another application?
  • Can you open it with notepad?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I use:

windows xp professional and i am administrator

the file is not in use, the file exist and i can open it with notepad

Edited by idenniske

Share this post


Link to post
Share on other sites

means "delete 4 characters"?

So your script would consist of

fileread (reads file into a single variable)

delete characters

filewrite (writes file from a single variable)

Yes i want to delete 4 characters

Share this post


Link to post
Share on other sites

file open then winactivate then send {backspace} {backspace}{backspace}{backspace}


Share this post


Link to post
Share on other sites

file open then winactivate then send {backspace} {backspace}{backspace}{backspace}

Thanks

When I run this

$file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0)

If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
WinActivate("[CLASS:Notepad]", "")
Send ("{backspace}")
Send ("{backspace}")
Send ("{backspace}")
Send ("{backspace}")
FileClose($file)

my browser opens My Computer, wrong path?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thanks

When I run this

$file = FileOpen("C:\xampp\htdocs\test\kennislong.txt", 0)

If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
WinActivate("[CLASS:Notepad]", "")
Send ("{backspace}")
Send ("{backspace}")
Send ("{backspace}")
Send ("{backspace}")
FileClose($file)

my browser opens My Computer, wrong path?

Your code can't work. FileOpen opens the file to use with FileRead and FileWrite. You can't switch to Notepad because Notepad hasn't been started yet.

You're mixing to Autoit "concepts".

Concept 1: Read a file, change and write it with pure autoit

Concept 2: Open the file with another program (notepad) and do all the work using the GUI of the program.

So first you should decide how to do the job.

To get you started:

  • How large is your file?
  • Where are the characters you want to delete (the first 4 characters, the last, somewhere in the middle)?
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Your code can't work. FileOpen opens the file to use with FileRead and FileWrite. You can't switch to Notepad because Notepad hasn't been started yet.

You're mixing to Autoit "concepts".

Concept 1: Read a file, change and write it with pure autoit

Concept 2: Open the file with another program (notepad) and do all the work using the GUI of the program.

So first you should decide how to do the job.

To get you started:

  • How large is your file?
  • Where are the characters you want to delete (the first 4 characters, the last, somewhere in the middle)?

The file is 849kb and i want to delete the last 4 characters.

Share this post


Link to post
Share on other sites

oops my bad sorry


Share this post


Link to post
Share on other sites

oops my bad sorry

Don't you guys have a example that works so i can test it?

Share this post


Link to post
Share on other sites

$trimchar = 4
$eol = @CRLF

$file1 = "$$$test.txt"
$file2 = "$$$test trimmed " & $trimchar & " chars.txt"

If FileExists($file1) Then FileDelete($file1)
If FileExists($file2) Then FileDelete($file2)

$j = ""
For $i = 1 To 10000
    $j &= "This is line " & $i & " This is line " & $i & " This is line " & $i & " This is line " & $i & $eol
Next
FileWrite($file1, StringTrimRight($j, 2))
$start1 = TimerInit()
$text = FileRead($file1)
$readtime = Round(TimerDiff($start1)/1000, 3)
ConsoleWrite("file read time: " & $readtime & "sec" & @LF)

$start2 = TimerInit()
FileWrite($file2, StringTrimRight($text, $trimchar))
ConsoleWrite("create file " & $file2 & " with " & $trimchar & " chars removed from end, time: " & Round(TimerDiff($start2)/1000, 3) & @LF)

Share this post


Link to post
Share on other sites

is it posible to open the notepad so i can see what happens.

right now i have this:

$fileVariableName = FileOpen("input.txt", 0)

If $fileVariableName = -1 Then

MsgBox(0,Failure,Failed to open file)

Exit

EndIf

While 1

With a error called : parse error.

I'm hopeless

Share this post


Link to post
Share on other sites

is it posible to open the notepad so i can see what happens.

Usually it is more error prone to do something using the GUI. Couldn't you use picaxe's code and test if it does what you need? The stripped down code would look like:
$trimchar = 4

$inFile  = "C:\xampp\htdocs\test\kennislong.txt"
$outFile = "C:\xampp\htdocs\test\kennislong_trimmed.txt"

If FileExists($outFile) Then FileDelete($outFile)
$text = FileRead($inFile)
If $text = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite($outFile, StringTrimRight($text, $trimchar))

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Usually it is more error prone to do something using the GUI. Couldn't you use picaxe's code and test if it does what you need? The stripped down code would look like:

$trimchar = 4

$inFile  = "C:\xampp\htdocs\test\kennislong.txt"
$outFile = "C:\xampp\htdocs\test\kennislong_trimmed.txt"

If FileExists($outFile) Then FileDelete($outFile)
$text = FileRead($inFile)
If $text = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite($outFile, StringTrimRight($text, $trimchar))
Thanks guys this works.

i do have one more question.

It seems that i have a lot of white spaces, so the trimmed chars are spaces. Is it posible to pick out the last four chars ),(, ?

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  
Followers 0