Jump to content

unable to open files


Recommended Posts

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
Link to comment
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 *

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
Share on other sites

  • Developers

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)

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

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...

Link to comment
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 *

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...