Jump to content

[Resolved] FileRead, FileWrite


Recommended Posts

One of these years, I hope to have enough money to take some sort of programming course! I waste too much time some days going around in circles, and this morning has been one of them. I've studied the help file and looked at a whole lot of posts here re both FileRead and FileWrite but nothing has helped me figure out what in hell I'm doing wrong.

I'm trying to make some of my scripts flow better. Up till now I've used a manual workaround with copying text and dumping it into a text file. I'd like to go with FileRead and FileWrite instead -- but I'm obviously not understanding something that with my luck is probably simple <sigh> <g>.

Here is one of the scripts I'm trying to convert.

$TempFILE = @TempDir & "\FileInfodump.txt"
    If FileExists($TempFILE) THEN FileDelete($TempFILE)
$FILE = FileRead($Fldr_Programs_DriveLtr & "\AutoIt\APP- AutoIt v3.2.10.0\Include\_PartitionLetters.au3", 0)
FileWrite($TempFILE, $FILE)
ShellExecute($TempFILE, "", "", "Open", @SW_MAXIMIZE)
Even when I commented out the FileDelete above to be on the safe side, the text file comes up blank. There's no reason for me to have commented that out, really, since supposedly the information is written in after (supposedly) but sometimes what I think and what actually happens are 2 different things when it comes to AI <g>.

I'm not understanding something in the syntax, I guess. I've read the help and I've tried many variations, this is just the latest one. I can't see why this won't work.

Thanks! <g>

Edited by Diana (Cda)
Link to comment
Share on other sites

  • Developers

try this example and see if you see the issue:

$FILE = FileRead(@ScriptFullPath, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FILE = ' & $FILE & @crlf & '>Error code: ' & @error & @crlf);### Debug Console
$FILE = FileRead(@ScriptFullPath)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $FILE = ' & $FILE & @crlf & '>Error code: ' & @error & @crlf);### Debug Console

Jos :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

A little slow late but this works

;*********** User Input **********

$Fldr_Programs_DriveLtr = @HomeDrive

$ReadFile = "\Program Files\AutoIt3\Include\ButtonConstants.au3"

; your file
;$ReadFile = "\AutoIt\APP- AutoIt v3.2.10.0\Include\_PartitionLetters.au3"

$TempFILE = @TempDir & "\FileInfodump.txt"


;********** Functions *******************

If FileExists($TempFILE) Then FileDelete($TempFILE)

; file read "0" was reading "0" bytes of information
$FILE = FileRead($Fldr_Programs_DriveLtr & $ReadFile)

FileWrite($TempFILE, $FILE)

ShellExecute($TempFILE)

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

In my post I tried to follow the OP script/thought process. And would explain the use of Zedna's post more like this

;*********** User Input **********

$Fldr_Programs_DriveLtr = @HomeDrive

$ReadFile = "\Program Files\AutoIt3\Include\ButtonConstants.au3"

; your file
;$ReadFile = "\AutoIt\APP- AutoIt v3.2.10.0\Include\_PartitionLetters.au3"

$TempFILE = @TempDir & "\FileInfodump.txt"


;********** Functions *******************

If FileExists($TempFILE) Then FileDelete($TempFILE)

; make sure the file exists so you do not execute a file that is not actually there
If FileExists($Fldr_Programs_DriveLtr & $ReadFile) Then
    
    ; this helps tremendously with spaces in the location name for execution
    $ReadFile = FileGetShortName($Fldr_Programs_DriveLtr & $ReadFile)
    
    ; file read "0" was reading "0" bytes of information
    $FILE = FileRead($ReadFile)
    
    FileWrite($TempFILE, $FILE)
    ShellExecute($TempFILE)
Else
    MsgBox(0x0, "Sorry", "The following file was not found     " & @CRLF & $Fldr_Programs_DriveLtr & $ReadFile & "    ")
EndIf

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

One of these years, I hope to have enough money to take some sort of programming course! I waste too much time some days going around in circles, and this morning has been one of them. I've studied the help file and looked at a whole lot of posts here re both FileRead and FileWrite but nothing has helped me figure out what in hell I'm doing wrong.

...

Thanks! <g>

Last Seen: Today, 08:20 AM

8)

NEWHeader1.png

Link to comment
Share on other sites

In my post I tried to follow the OP script/thought process. And would explain the use of Zedna's post more like this ...

I'm still not exactly 100% sure what I was doing wrong except for that "0" perhaps. And it seems that I should separate the source file from the FileRead line. Still, it's working now. I did make one "major" change, saving the temporary file to an AU3 format. I'm going to scrap the text formats from this point forward for this type of thing. What this script type allows me to do is to access the info in my UDFs without touching the original files. And it's now faster and cleaner.

Here's how it now stands:

;------------------------------------------------------------------------------------------------------
$TempFILE = @TempDir & "\FileInfodump.au3"
    If FileExists($TempFILE) THEN FileDelete($TempFILE)
;------------------------------------------------------------------------------------------------------
$File2Read = $Fldr_Programs_DriveLtr & "\AutoIt\APP- AutoIt\Include\_PartitionLetters.au3"
;------------------------------------------------------------------------------------------------------
$FILE = FileRead($File2Read)
FileWrite($TempFILE, $FILE)
ShellExecute($LaunchSciTEhome, $TempFILE, "", "Open", @SW_MAXIMIZE)
The file delete if exists part is there in case a file was created earlier that I hadn't gotten rid of. I'm not yet confident enough in my AI skills so this way, I'm sure I'll get a file with no duplicate info. At least, that's the reasoning.

Thanks! And thanks for the time it took you. I understand how difficult it can be to get into the OP's head, trying to figure out what they were trying to do <g>.

Cheers! <g>

Edited by Diana (Cda)
Link to comment
Share on other sites

Last Seen: Today, 08:20 AM

8)

Yeah, yeah. Always someone who knows a lot about AI making fun <vbg>. Honestly, if money and health weren't issues, I'd have taken some sort of programming course long before now! <g> But thanks to this forum and, for the _most_ part, very friendly and helpful people like you and others, we manage to limp along our AI path!

<g>

Edited by Diana (Cda)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...