BUG - Enumeration of Files???

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 17 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
BiTESUK
Posts: 13
Last visit: Tue Aug 04, 2015 12:06 am

BUG - Enumeration of Files???

Post by BiTESUK »

Hello. I am trying to enumerate the files in a folder by using the FileSystemObject. The first time that I run my script in the PrimalScript IDE the script correctly enumerates the files in the directory that I supply. The problem occurs the 2nd time that I run the script. It seems like my "parentFolder" variable is ignored and instead the contenct of "C:Program FilesSAPIENPrimalScript Professional" are enumerated instead. I have run my code in a WScript Shell and the script runs fine. I have pasted the function below. Can someone please let me know if this is a bug with PrimalScript v4.1.532. Thanks in advance.
Private Sub EnumSubFolders(ByVal parentFolder) On Error Resume Next Dim subF, f Dim pF : Set pF = oFSO.GetFolder(parentFolder) If Err <> 0 Then WScript.echo Err.Number & Err.Description & VbCrLf & parentFolder Err.Clear On Error GoTo 0 Exit Sub End If WScript.Echo "Checking " & parentFolder 'Check each file in the parent folder for the OSD file For Each f In pF.Files 'WScript.Echo "Found: " & UCASE(f.name) WScript.Echo f.path Next ' For Each subF In pF.SubFolders 'Call recursively for subfolders' EnumSubFolders(subF)' Next Set pF = Nothing On Error GoTo 0End Sub BlUNt2007-01-25 03:48:38
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

BUG - Enumeration of Files???

Post by Alexander Riedel »

When you say you "run" the script inside PrimalScript,
do you click Script -> Run Script or are you executing the script in the debugger?

In general, when you just run the script, it simply executes it with CScript just as you would. So I think we would need to see the outer code too.

Alex
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
BiTESUK
Posts: 13
Last visit: Tue Aug 04, 2015 12:06 am

BUG - Enumeration of Files???

Post by BiTESUK »

Hey Alex.

I generally just press F5 to run the script within the IDE, but even if I put a watch on the vars and debug (step through) with breakpoints I get the same result.
I am pretty sure I have left the script engine as CScript (default). Not on that PC now, but will update you tomorrow on that.

The outer code (i.e. calling the routine) is really simple, there are no args or anything like that.

EnumSubFolders("C:")

for example, and is in fact what I have been using to produce the problem.

I find it very strange, as when you re-run the script, the function will correctly echo the "Checking " & parentFolder.. as being "C:". The error handler doesn't get hit, so my guess is that the oFSO.GetFolder function is somehow binding to the working dir as that is being enumerated. Even the watch on var pF shows as being "C:". wierd!!

If I open a cmd shell and type:

wscript myscript.vbs

or

cscript myscript.vbs

then it works fine...

1 thing I haven't tried is to only close and reopen the script, I have been having to restart PrimalScript to get the script working again, but I am not too sure if that really makes a difference anyway.
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

BUG - Enumeration of Files???

Post by donj »

Are you able to share the script that this sub is being used within? The sub isn't self-contained; it doesn't declare the oFSO object variable, for example. Primarily, I'm interested in seeing what's being passed into parentFolder from the calling script - I ran this several times on my machine, passing in "C:," and it worked exactly the same each time.
I'm wondering if parentFolder is being sent a dynamic value, such as the current directory, which could in fact change between executions of the script.
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

BUG - Enumeration of Files???

Post by donj »

Here's what I ran, and it worked 100% the same every time:

Set oFSO = CreateObject("Scripting.FileSystemObject")EnumSubFolders("c:")

Private Sub EnumSubFolders(ByVal parentFolder) 'On Error Resume Next Dim subF, f Dim pF : Set pF = oFSO.GetFolder(parentFolder) If Err <> 0 Then WScript.echo Err.Number & Err.Description & VbCrLf & parentFolder Err.Clear On Error GoTo 0 Exit Sub End If WScript.Echo "Checking " & parentFolder 'Check each file in the parent folder for the OSD file For Each f In pF.Files 'WScript.Echo "Found: " & UCASE(f.name) WScript.Echo f.path Next ' For Each subF In pF.SubFolders 'Call recursively for subfolders' EnumSubFolders(subF)' Next Set pF = Nothing On Error GoTo 0End Sub
User avatar
BiTESUK
Posts: 13
Last visit: Tue Aug 04, 2015 12:06 am

BUG - Enumeration of Files???

Post by BiTESUK »

Hi.. Sorry it has taken me a couple of days to get back to you..
The outer portion of the script is essentially what you have written..

Dim parentFolder : parentFolder = InputBox("Enter the full path to your source folder", ,"'ServerShareFolder' or 'C:MyFolder'")
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(parentFolder) Then EnumSubFolders parentFolderEnd If
I can reproduce the problem by leaving the backslash off the drive letter. The FileSystemObject doesn't need the last backslash.
If I pass c: then the code runs perfectly every time. If I pass c: then the code only works first time within the IDE.
I have tried enumerating mapped network drives (U:, U:, H:, H:) and these all work fine. I have also passed UNC paths through and again these work fine. I only see this problem when enumerating C:
Do you get the same result?
Cheers.BlUNt2007-01-29 03:51:03
User avatar
donj
Posts: 416
Last visit: Thu May 29, 2008 5:08 am

BUG - Enumeration of Files???

Post by donj »

Passing C: is an explicit reference to the root folder of the C: drive. Passing just C:, however, refers not to the root drive, but rather to the "current folder" on the C: drive. Because PrimalScript is periodically accessing the disk, the IDE's "current folder" does change over time. "C:" by itself, however, is not a valid reference to a specific folder.

U: works consistently for you because the IDE isn't changing the "current folder" of that drive.
This topic is 17 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.