|
Post by angelo2449 on Feb 17, 2019 18:14:24 GMT -5
Hi Guys,
I have a problem with the checking the existence of folders, this example works:
nomainwin
dim info1$(0, 0) 'as for fileExists function, should be DIMmed before use
if dirExists("D:\AltProvvisori\Felipe", "GPS") then
Notice "Info" + chr$(13) + "Esiste!"
end if
end
' -------------------------------------------------
function dirExists(path$, dirname$)
files path$, chr$(0), info1$() 'file name is invalid by design, so we get only folders
'and info1$(0,0)) always 0
dirExists = 0
If Val(info1$(0,1)) > 0 Then
For i = 1 To Val(info1$(0,1))
If info1$(i, 1) = dirname$ Then
dirExists = 1
Exit Function
End If
next
end if
end function
The same code entered in a program does not works :
................. ................. ..................
[LavoroEsistente]
dim info1$(0, 0)
if dirExists("D:\AltProvvisori\Felipe", "Libretti") then
Notice "Info" + chr$(13) + "Esiste!"
wait
' ----------------------------------
function dirExists(path$, dirname$)
files path$, chr$(0), info1$()
dirExists = 0
if val(info1$(0,1)) > 0 then
For i = 1 to val(info1$(0,1))
if info1$(i, 1) = dirname$ then
dirExists = 1
exit function
end if
next
end if
end function
The folder and the subfolder exist but nothing happens!
Thank You.
|
|
|
Post by metro on Feb 17, 2019 19:53:12 GMT -5
hmm, works for me I did add "end if" to the code and changed the path to C: where I created the folders
if dirExists("D:\AltProvvisori\Felipe", "Libretti") then
Notice "Info" + chr$(13) + "Esiste!" END IF wait
|
|
|
Post by angelo2449 on Feb 18, 2019 4:14:26 GMT -5
Thank You,
I stupidly forgot to put> end if <which however exists in the original.
But it does not work!
The sub routine is included in a relatively large program but I do not think this could be a problem.
I simulated the program with this code and everything works!
In the biggest program it does not work!
Yet everything is right!
In the code, after the asterisks, there is the extract of the code of the largest program.
I do not understand why it does not pretend!
Thank you.
nomainwin
dim info1$(0, 0) 'as for fileExists function, should be DIMmed before use
dim info$(10, 10)
button #main.prova, "Esiste", [Esiste], UL, 20, 30, 100, 30
open "Prova" for window as #main
#main, "font courier_new 10 16 bold"
#main, "trapclose [quit.Main]"
wait
' ------------------------------
[Esiste]
if dirExists("D:\AltProvvisori\Felipe", "GPS") then
Notice "Info" + chr$(13) + "Esiste!"
end if
wait
' ------------------------------
[quit.Main]
close #main
end
' -------------------------------------------------
function dirExists(path$, dirname$)
files path$, chr$(0), info1$() 'file name is invalid by design, so we get only folders
'and info1$(0,0)) always 0
dirExists = 0
If Val(info1$(0,1)) > 0 Then
For i = 1 To Val(info1$(0,1))
If info1$(i, 1) = dirname$ Then
dirExists = 1
Exit Function
End If
next
end if
end function
'***************************************************************************************
dim Riga$(300), RigaAnn$(300), RifComp$(300), COx(300)
dim RigaWgs$(300), COy(300), PuntoBuono$(300), RigaEcef$(300)
dim info$(10, 10)
dim info1$(0, 0) ' <<<<<<<<<<<<<<<< dim nome$(300)
dim colore$(16)
dim Linea$(300)
dim scale(64), mapX(64), mapY(64)
........................ ........................ ........................ button #messco.esistente, "Esistente", [LavoroEsistente], UL, 160, ya + 300, 150, 35 ........................ ........................ [LavoroEsistente]
if dirExists("C:\AutocadSupporto", "Config") then
Notice "Info" + chr$(13) + "Esiste!"
end if
Azione$ = "LavoroEsistente"
CartellaCreata$ = "CreataSi" ' + Azione$
wait ........................ ........................ ........................ function dirExists(path$, dirname$)
files path$, chr$(0), info1$()
dirExists = 0
if val(info1$(0,1)) > 0 then
For i = 1 to val(info1$(0,1))
if info1$(i, 1) = dirname$ then
dirExists = 1
exit function
end if
next
end if
end function
|
|
|
Post by Rod on Feb 18, 2019 6:08:13 GMT -5
Both your functions work for me. So, in the real program use the debugger to set a break point in the function (right click on left margin) then click on show globals. Now be sure the variables, globals and arrays (list them out to debug) contain what you think they should.
The one other possibility is that you don't have permission to view the folder. If the folder belongs to another user Windows wont let you access it. But if you can see it while debugging that isn't the problem, your code simply isn't doing what you think it is.
|
|
|
Post by angelo2449 on Feb 18, 2019 9:02:15 GMT -5
Thank You, I do not understand this behavior! Apparently there are no errors, the folder is freely accessible, however the error occurs with all the signs. Also the sizing of the variable is correct, the debugging does not report errors.
I am desperate!
|
|
|
Post by Rod on Feb 18, 2019 9:18:34 GMT -5
As there appears to be nothing wrong with your function it is how you access and manage the program flow that will be the problem. Do you have a timer statement running? What happens if you replace the notice command with a simple print statement. You should insert debugging print statements every step of the way and use mainwin to see where your program actually goes.
|
|
|
Post by Brandon Parker on Feb 18, 2019 9:32:20 GMT -5
Try using this function below....
NOTE: You will either need to create the Info$() array or change the code to use the one you have defined. You will need to either define the Global variables False and True as I have or replace them with 0 and 1 (or with whatever you use).
This is the function I use to search for folders and it never fails for me.
Global False : False = 0 Global True : True = 1
Dim Info$(0, 0)
result = searchForFolder("C:\Your_Directory\Goes\Here, "Folder_To_Look_For")
Function searchForFolder(directory$, folder$) On Error GoTo [Error] directory$ = directory$ + "\" Files directory$, "*", Info$() If Val(Info$(0,1)) > 0 Then For i = 1 To Val(Info$(0,1)) If Lower$(Info$(Val(Info$(0,0)) + i, 1)) = Lower$(folder$) Then searchForFolder = True Exit For End If Next i End If ReDim Info$(0, 0) [Error] End Function
{:0)
Brandon Parker
|
|
|
Post by angelo2449 on Feb 18, 2019 11:38:51 GMT -5
Thank You, I have already tried your function: Global False : False = 0 Global True : True = 1
dim Riga$(300), RigaAnn$(300), RifComp$(300), COx(300) dim RigaWgs$(300), COy(300), PuntoBuono$(300), RigaEcef$(300) dim info$(10,10) dim Info$(0,0) ................ ................ [LavoroEsistente]
result = searchForFolder("D:\AltProvvisori\Angelo", "DWG")
print "result >>>>>> "; result
wait ................. ................. Function searchForFolder(directory$, folder$) On Error GoTo [Error] directory$ = directory$ + "\" Files directory$, "*", Info$() If Val(Info$(0,1)) > 0 Then For i = 1 To Val(Info$(0,1)) If Lower$(Info$(Val(Info$(0,0)) + i, 1)) = Lower$(folder$) Then searchForFolder = True Exit For End If Next i End If ReDim Info$(0, 0) [Error] End Function
I get : result >>>>>> 0 ??
|
|
|
Post by Chris Iverson on Feb 18, 2019 12:01:09 GMT -5
Then somehow, what LB is seeing is different from what you're seeing.
Try this. Open a FILEDIALOG using LB, navigate to the folder in the filedialog, and then print the result, to show what LB sees the folder name as.
filedialog "Choose file", "", file$ print file$
Run this, find the file you want to access, and then see what path gets shown at the end.
|
|
|
Post by angelo2449 on Feb 18, 2019 12:34:25 GMT -5
If I use fildialog to open the folder in question in both> Open <and> Save <mode, everything works fine, the folder opens and the contents are shown. Now I try to extract the part of the program that interests to reduce it to a minimum. Let's see.
|
|
|
Post by Chris Iverson on Feb 18, 2019 12:43:38 GMT -5
What's the path that the filedialog returns? The path that gets shown after you choose the file?
|
|
|
Post by angelo2449 on Feb 18, 2019 13:25:38 GMT -5
The returned path is right, it is one of those present in the code. Even here, with the minimum code, it does not seem to me to work!
nomainwin dim Riga$(300), RigaAnn$(300), RifComp$(300), COx(300) dim RigaWgs$(300), COy(300), PuntoBuono$(300), RigaEcef$(300) dim info$(10,10) dim Info$(0,0)
WindowWidth = 900 WindowHeight = 700
UpperLeftX = (DisplayWidth - WindowWidth) / 2 UpperLeftY = (DisplayHeight - WindowHeight) / 2 + 20
ForegroundColor$ = "white" ListboxColor$ = "darkblue"
xxa = 0
texteditor #main.edit, -200, -500, 830, 25 ' campo nascosto x clipboard listbox #main.list, Riga$(), [listRighe], 30, 35, 820, 430
xa = 0 y1a = -85 yb = 485
loadbmp "ButVertoR", "VertoR.bmp" loadbmp "ButVertoG", "VertoG.bmp" loadbmp "ButConveRgoG", "ConveRgoG.bmp" loadbmp "ButConveRgoR", "ConveRgoR.bmp"
button #main.pulisci, "Iniziamo", [INIZIO], UL, 30, 7, 100, 20 button #main.appunti, "Appunti", [Main.Appunti], UL, 150, 7, 100, 20 button #main.appunti, "Apri", [Apri.File], UL, 270, 7, 100, 20
button #main.pulisci, "Pulisci", [Main.Pulisci], UL, 390, 7, 100, 20 button #main.str1, "", [nil], UL, 510, 7, 100, 20 button #main.nuovo, "", [nil], UL, 628, 7, 104, 20 button #main.altezza, "H. Ellisso", [Calcolo.Altezza], UL, 750, 7, 100, 20
button #main.esistente, "Esistenti", [LavoroEsistente], UL, 40, y1a + 600, 100, 40
TextboxColor$ = "darkblue" textbox #main.test, 30, y1a + 665, 820, 25
open "Applicazione > GPS Trasformer < per Calcolo Coordinate GPS & Pregeo by Montoli Angelo Ambrogio - " + Ver$ for window as #main #main, "font courier_new 10 16 bold" #main, "trapclose [quit.Main]" #main.list, "singleclickselect" #main.list, "enable"
wait
' -------------------
[quit.Main]
close #main
wait
' -------------------
[LavoroEsistente]
' D:\AltProvvisori\Angelo\Contatori ' D:\AltProvvisori\Angelo\DWG ' D:\AltProvvisori\Angelo\DXF ' D:\AltProvvisori\Angelo\GPS ' D:\AltProvvisori\Angelo\Immagini ' D:\AltProvvisori\Angelo\Libretti ' D:\AltProvvisori\Angelo\PF ' D:\AltProvvisori\Angelo\Varie
result = searchForFolder("D:\AltProvvisori\Angelo", "Contatori")
#main.test, "result >>>>>> "; result
wait
' -------------------
Function searchForFolder(directory$, folder$) On Error GoTo [Error] directory$ = directory$ + "\" Files directory$, "*", Info$() If Val(Info$(0,1)) > 0 Then For i = 1 To Val(Info$(0,1)) If Lower$(Info$(Val(Info$(0,0)) + i, 1)) = Lower$(folder$) Then searchForFolder = True Exit For End If Next i End If ReDim Info$(0, 0) [Error] End Function
' ----------------------------------
|
|
|
Post by Chris Iverson on Feb 18, 2019 13:35:08 GMT -5
Hmm, this is getting weirder.
What if you use the FILEDIALOG code to get the path you need, and try to use that, just as a test?
Like, use the FILEDIALOG to navigate to the folder/file you need, then use the string returned from the FILEDIALOG as the basis of the rest of the program.
Also, see if this code gets you a directory listing of all the files in that folder, or if you get nothing.
folderPath$ = "D:\AltProvvisori\Angelo" print folderAction(folderPath$)
Function folderAction(path$) 'If there's a trailing path separator, remove it if right$(path$, 1) = "\" then path$ = left$(path$, len(path$) - 1)
dim folderActionInfo$(1, 1) files path$, folderActionInfo$()
numFiles = val(folderActionInfo$(0, 0)) numFolders = val(folderActionInfo$(0, 1))
'Print out the name of the folder we're currently working with. 'Move this to just before the [end] branch to perform the action AFTER going through 'subfolders. print path$ x = 0
'Print the name of each regular file found if numFiles > 0 then do x = x + 1 print path$;"\";folderActionInfo$(x, 0) loop while x < numFiles
end if
if numFolders > 0 then do 'Convert the list of folder names in the array to a local string 'This is done because arrays are global in LB, they are not locally-scoped. 'If we didn't do this, we would lose all of the folder names when we called 'the function recursively. if folderList$ <> "" then folderList$ = folderList$ + "|" x = x + 1 folderList$ = folderList$ + folderActionInfo$(x, 1) loop while (x - numFiles) < numFolders
'For each folder, call folderAction() again ' 'Note that this contains an error reporting mechanism: 'if something goes wrong with the action you want to take on a file or folder, 'set the return value of folderAction() to any non-zero value. ' 'This will stop the recursion instantly and back all the way out 'to the code that initially called folderAction(). For x = 1 to numFolders folder$ = word$(folderList$, x, "|") a = folderAction(path$ + "\" + folder$) if a then ERRFLAG = a exit for end if Next x if ERRFLAG then folderAction = ERRFLAG
'We do a goto [end] to skip any post-processing actions. 'This can be removed if you still want to perform them, or you 'can put custom actions here to handle the case of an error before 'returning to the calling code. goto [end] end if End If 'folderAction = rmdir(path$) [end] End Function
|
|
|
Post by angelo2449 on Feb 18, 2019 14:41:10 GMT -5
OK this code returns all the folders contained in the folder : "D:\AltProvvisori\Angelo" and one "0"
|
|
|
Post by Brandon Parker on Feb 18, 2019 17:39:20 GMT -5
In the reply just above where you posted the "minimum code" and used the function I provided you did not initialize the True and False variables.
I just took that code, removed some BMPButtons, added the True/ False initialization, changed the paths to something that existed and everything worked as expected. I also commented out the Dim info$(10, 10) (lower case info$() array) statement since it is not used in the snippet.
Try this code with no alterations....
This should work with no issues or else something is just straight up wrong with your folder structure.
Global False : False = 0 Global True : True = 1
nomainwin dim Riga$(300), RigaAnn$(300), RifComp$(300), COx(300) dim RigaWgs$(300), COy(300), PuntoBuono$(300), RigaEcef$(300) 'dim info$(10,10) dim Info$(0,0)
WindowWidth = 900 WindowHeight = 700
UpperLeftX = (DisplayWidth - WindowWidth) / 2 UpperLeftY = (DisplayHeight - WindowHeight) / 2 + 20
ForegroundColor$ = "white" ListboxColor$ = "darkblue"
xxa = 0
texteditor #main.edit, -200, -500, 830, 25 ' campo nascosto x clipboard listbox #main.list, Riga$(), [listRighe], 30, 35, 820, 430
xa = 0 y1a = -85 yb = 485
loadbmp "ButVertoR", "VertoR.bmp" loadbmp "ButVertoG", "VertoG.bmp" loadbmp "ButConveRgoG", "ConveRgoG.bmp" loadbmp "ButConveRgoR", "ConveRgoR.bmp"
button #main.pulisci, "Iniziamo", [INIZIO], UL, 30, 7, 100, 20 button #main.appunti, "Appunti", [Main.Appunti], UL, 150, 7, 100, 20 button #main.appunti, "Apri", [Apri.File], UL, 270, 7, 100, 20
button #main.pulisci, "Pulisci", [Main.Pulisci], UL, 390, 7, 100, 20 button #main.str1, "", [nil], UL, 510, 7, 100, 20 button #main.nuovo, "", [nil], UL, 628, 7, 104, 20 button #main.altezza, "H. Ellisso", [Calcolo.Altezza], UL, 750, 7, 100, 20
button #main.esistente, "Esistenti", [LavoroEsistente], UL, 40, y1a + 600, 100, 40
TextboxColor$ = "darkblue" textbox #main.test, 30, y1a + 665, 820, 25
open "Applicazione > GPS Trasformer < per Calcolo Coordinate GPS & Pregeo by Montoli Angelo Ambrogio - " + Ver$ for window as #main #main, "font courier_new 10 16 bold" #main, "trapclose [quit.Main]" #main.list, "singleclickselect" #main.list, "enable"
wait
' -------------------
[quit.Main]
close #main
wait
' -------------------
[LavoroEsistente]
' D:\AltProvvisori\Angelo\Contatori ' D:\AltProvvisori\Angelo\DWG ' D:\AltProvvisori\Angelo\DXF ' D:\AltProvvisori\Angelo\GPS ' D:\AltProvvisori\Angelo\Immagini ' D:\AltProvvisori\Angelo\Libretti ' D:\AltProvvisori\Angelo\PF ' D:\AltProvvisori\Angelo\Varie
result = searchForFolder("D:\AltProvvisori\Angelo", "Contatori")
#main.test, "result >>>>>> "; result
wait
' -------------------
Function searchForFolder(directory$, folder$) On Error GoTo [Error] directory$ = directory$ + "\" Files directory$, "*", Info$() If Val(Info$(0,1)) > 0 Then For i = 1 To Val(Info$(0,1)) If Lower$(Info$(Val(Info$(0,0)) + i, 1)) = Lower$(folder$) Then searchForFolder = True Exit For End If Next i End If ReDim Info$(0, 0) [Error] End Function
' ----------------------------------
{:0)
Brandon Parker
|
|