Sign in to follow this  
Followers 0
Zithen

unable to open files

9 posts in this topic

i dont know what i am missing, i have tried many many ways to do this but all are failing at the same spot, the fileopen is returning -1. it will find the first file correctly but wont open. anyone have any insight?

heres a snipet of code

;maps v: for pulling files
DriveMapAdd("V:","\\server\dir\")

; Shows the filenames of all files in the current directory
$rootpath= "V:\logs\"
$remotepath="N:\logxp\"
$searchpath= $rootpath & "*.txt"
$linesread = 0
$begin = TimerInit()
$numfiles = 0
$read = 0
$skip = 0

$search = FileFindFirstFile("$rootpath")  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $numfiles = $Numfiles +1
    $filename = FileFindNextFile($search) 
;If @error Then ExitLoop
        
       $file = FileOpen($filename, 0)
       
;this shows the first file name but $file returns -1 everytime
;MsgBox(0,"err",$filename & @cr & $file)

; Check if file opened for reading OK
If $file == -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

Share this post


Link to post
Share on other sites



...the first I saw:

...
$search = FileFindFirstFile("$rootpath")  
...

(no quotes)

...
$search = FileFindFirstFile($rootpath)  
...

(try again)

Share this post


Link to post
Share on other sites

i dont know what i am missing, i have tried many many ways to do this but all are failing at the same spot, the fileopen is returning -1. it will find the first file correctly but wont open. anyone have any insight?

It's not fileopen() but findfilefirstfile() that fails!

Wrong:

$search = FileFindFirstFile("$rootpath")

Correct:

$search = FileFindFirstFile($rootpath)

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It's not fileopen() but findfilefirstfile() that fails!

Wrong:

$search = FileFindFirstFile("$rootpath") 

Correct:

$search = FileFindFirstFile($rootpath) 

Cheers

Kurt

<{POST_SNAPBACK}>

actually, i think this is the way to go...

$search = FileFindFirstFile($searchpath)

since $searchpath is given the file mask...

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

aye...without quotes failed also, i have tried even writing the hole path out and that failed as well. the time it works is when i have the search field empty and run the file within the logs directory, but alas i cant keep that file there due to other people needed to run it

Share this post


Link to post
Share on other sites

aye...without quotes failed also, i have tried even writing the hole path out and that failed as well. the time it works is when i have the search field empty and run the file within the logs directory, but alas i cant keep that file there due to other people needed to run it

<{POST_SNAPBACK}>

the $filename variable will only contain the filename but is missing the whole path.

try:

$file = FileOpen($rootpath & $filename, 0)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

the $filename variable will only contain the filename but is missing the whole path.

try:

$file = FileOpen($rootpath & $filename, 0)

<{POST_SNAPBACK}>

here's corrected code... tested it myself... i changed the filefindfirstfile() per my suggestion above, and changed the assignment to $filename to include the path...

;maps v: for pulling files
;DriveMapAdd("V:","\\server\dir\")

; Shows the filenames of all files in the current directory
$rootpath= "S:\AGNTSTATS\"
;$remotepath="N:\logxp\"
$searchpath= $rootpath & "*.csv"
$linesread = 0
$begin = TimerInit()
$numfiles = 0
$read = 0
$skip = 0

$search = FileFindFirstFile($searchpath)  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $numfiles = $Numfiles +1
    $filename = $rootpath & FileFindNextFile($search)
    MsgBox(0,"filename",$filename)
;If @error Then ExitLoop
        
       $file = FileOpen($filename, 0)
       
;this shows the first file name but $file returns -1 everytime
;MsgBox(0,"err",$filename & @cr & $file)

; Check if file opened for reading OK
If $file == -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
WEnd

had to change paths to paths i actually had to test...


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

actually, i think this is the way to go...

$search = FileFindFirstFile($searchpath)

correct!

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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