Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Eternal trap loop with SetFolder() and 'media' folder

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 20th Feb 2016 13:32 Edited at: 20th Feb 2016 13:40
Hello everybody.

I am currently trying make a program that read the content of a hard drive, and make a list of it's files and folders.
Then it will make boxes to represent each files and folders, which will form a 'file city'
I managed to do this in DBPro, and transferred the project to AGK.

However, I stumbled upon a brick wall.

Now, the program requires reading of thousands of folders content and make a list of them, stored in an array.
To do this, we need to call SetRawWritePath() and SetFolder() every time we want to look into a new folder.
No problem with this.

But, the problem is, AppGameKit read the content of a specified folder, THEN it automatically proceeds with reading the 'project' folder.
When it does that, our 'media' folder will be read every time we call SetRawWritePath() and SetFolder() (meaning every time we look into a different folder)
That 'media' folder will be registered into the array that we used to store files info, as legitimate file.
We don't want this, because the folder we originally specified to explore, is not our project folder.

Now things got more dicey.
Every loop, my program will look for folders that was not being turn into 'buildings/boxes' yet, and create a 3D box to represent them.
It then explore the unexplored folders, and make a llist for its content. This will repeat until all files and folders in a hard drive is registered.
Now, every loop, the program will detect that 'media' folder that was not intended to be detected, but was registered anyhow because how AppGameKit reads files (as explained above)
The program will try to explore that 'media' folder. SetRawWritePath() and SetFolder() will be called.
But by calling those commands, AppGameKit will again try to list the files in our 'project' folder, and will detect the 'media' folder, again, and will register it again.
Then, in the next loop, when the program tries to find an unexplored folder to explore, it will detect that 'media' folder again. And it will register 'media' folder again and again.

This will continue forever without end, and results in an eternal trap loop.
The path will look like this D:\Music\English\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media\media to infinity

Now we can solve this problem by identify that 'media' folder, and prevent the program by reading them.
We do this by getting the 'media' folder name, and it's directory name
With this, we can detect if the program is picking up that specific 'media' folder which is our 'project', and prevent the program from going into an eternal loop.

But we can't do this in AppGameKit, because there is no way to return directory address for the 'media' folder.

The only directory address that we can return is the current working directory, that we specify using SetRawWritePath().
But, the 'media' folder is NOT in that path.
But the program will read the 'media' folder anyway, automatically, as if it was in the directory that we specified.
The real 'media' folder is in the 'project' folder, in which the location could be anywhere, different for different user. There is no way to return its directory address using commands.
So, we can't tell if that folder named 'media' is the problematic folder, or just normal folder outside the 'project folder'.
If we cannot confirm the identity of the media folder, then we cannot prevent the program from going into that eternal loop.

The only way I can get around this is by disabling reading from all folder bearing the name 'media' altogether.
But this also means the program will not be able to detect other normal folders named 'media'
The program will be severely handicapped.

So, I desperately request so that AppGameKit will be given an option to disable reading from the 'project' folder, unless specified.
Let the commands only read from the file specified using SetRawWritePath(), and not automatically read the 'project' folder
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Feb 2016 15:51 Edited at: 20th Feb 2016 15:55
This is also being discussed here.
Thinking about it a little bit more, I think the solution is to allow your algorithm to enter the Raw Write Path + "media", and if no files or folders are returned, assume the media folder doesn't actually exist. It's a small waste of processing time but may resolve the problem.

I tried GetErrorOccured() on a non-existent folder with SetRawWritePath(), but it didn't generate an error
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 20th Feb 2016 18:08
I think AppGameKit is the wrong tool for the job.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 20th Feb 2016 22:19
BatVink

Did you call SetErrorMode( 1 ) at the top of your code?
I believe that GetErrorOccured() will not be triggered unless you use SetErrorMode( 1 ).
The other alternative is to build in debug mode otherwise AppGameKit skips reporting errors.

hakimfullmetal
Can you make a small code sample. I think AppGameKit can do what you want.
The coffee is lovely dark and deep,and I have code to write before I sleep.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 20th Feb 2016 23:10
I tried with SetErrorMode(1), and it still doesn't report an error.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 21st Feb 2016 11:09 Edited at: 21st Feb 2016 11:44
Stab In The Dark

This is the code that scan our intended directory. It's basically about the same as BatVink code above.
The code is divided into 3 parts:

1st - Declare all required arrays and variables at the program start
2nd - Scan the first layer of the files and folders in the specified directory, at the program start
3rd- This part is in the main loop. This part will detect which folder is not explored yet in our array, and scan the next layer of folders and files. Each loop, a new/deeper layer of files will be explored.

This example scans the D drive. Change this line in the 1st part of the code:
GLOBAL baseDir$ = "D:\"
to whatever directory you want it to scan.

*some of the variables and part of the array, such as prevDir$, leftclick, is redundant and not used, or used in the algorithm to create the file city, which is not related to our problem, sooooo

1st part


2nd part


3rd part
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 21st Feb 2016 11:23 Edited at: 21st Feb 2016 11:43
BatVink

I thought so too initially, but allowing our algorithm to enter the Raw Write Path + "media" will make AppGameKit automatically scan the 'project' folder again (in addition to the 'media' folder that is currently being scanned), and still results in eternal loop.

And allowing our algorithm to enter the Raw Write Path + "media" , is not possible because the path returned from Raw Write Path is never the directory of the 'media' folder.

Changing our directory while scanning is not finished in a folder, will results in eternal loop, because AppGameKit automatically scan the 'project' folder again each and every time.
And when we want to return to the directory that we initially scan (before exploring 'media' folder), AppGameKit will automatically re-scan the 'project' folder again. And And then AppGameKit will try to explore the 'media' folder again. It never ends.

Another way to solve this problem, is by having commands such as GetPathExist() available. (returns 1 if path exist, 0 if not)
This way we can determine if that Raw Write Path + "media" path really exist in our directory, or just a fake folder from 'project' folder.
Then we can exclude that folder, if its path does not really exist
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Feb 2016 14:57
Maybe I'm missing something, but can you use SetRawWritePath to the root of the drive, and then use SetFolder to traverse the entire structure? You may have to dump the contents of GetNextFolder into an array before you start to recurse so you can continue where you left off, but I can't foresee any problems with this approach.
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 24th Feb 2016 10:50
Err sorry, but I don't understand

I thought we need to call both SetRawWritePath and SetFolder to set a new directory, and explore that directory/folder?
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 24th Feb 2016 15:51
SetFolder will let you traverse as deep as you like through the directory structure, so if you use SetRawWritePath to access the root of the drive then you can go anywhere with SetFolder.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Feb 2016 16:18
I think the issue (at least for me) is that every folder looks like it contains a subfolder called "media".
Is there any logic that can be applied to eliminate the phantom media subfolder, without losing genuine media subfolders?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 24th Feb 2016 16:30
Only the root folder should look like it contains a media folder, for example SetRawWritePath("C:\") would make it look like C:\media exists, but when you use SetFolder("/Windows") it won't find C:\Windows\media
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Feb 2016 19:05
OK, that makes sense. I have been continually using SetRawWritePath() with a longer path, instead of using SetFolder() to drill down into the structure.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 25th Feb 2016 09:19 Edited at: 25th Feb 2016 22:59
Really? I'll give it a try when I'm home from work.

Just to be clear, we can use Setfolder() like this right?
Lets say I have 1 folder in D drive, which is "music", and inside "music" is another folder "English"
D --> Music --> English

Let's say we are in the root folder "D:\" that we specified using SetRawWritePath().
Now to navigate to "english" folder, we can do this right? Setfolder("Music\English"),

Or is it that we can only navigate to "English" by doing SetFOlder("Music"), and then call SetFolder("English")?



And also, help file mentioned 'Setting the path to a folder that does not exist will create that folder in the write path'
Does that mean if I do this SetFolder("Music\Japanese"), then AppGameKit will make a new folder named "Japanese" in the root path (which is "D:\" ?
And if I made the program repeat the mistake every loop, then the root path will be swarming with those folders?

*Seems to work so far. I'll test it further
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 25th Feb 2016 15:04
Quote: "Now to navigate to "english" folder, we can do this right? Setfolder("Music\English"), "

Yes, but use forward slashes instead of backward slashes

Quote: "help file mentioned 'Setting the path to a folder that does not exist will create that folder in the write path'"

Not immediately, but if you use OpenToWrite it will create the folder, I'll update the documentation to be clearer. SetFolder does not check if the folder you give it exists, it just sets an internal path that will be used for the next file command.

Login to post a reply

Server time is: 2024-11-25 09:18:44
Your offset time is: 2024-11-25 09:18:44