Jump to content

Recommended Posts

Posted

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.

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

$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

Posted
  • 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
Posted

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

Posted

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?

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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.

Posted

$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)

Posted

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

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

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 ),(, ?

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
×
×
  • Create New...