Re: python, I'm being dumb... again!

2019-05-13 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: python, I'm being dumb... again!

@5, that's odd -- it always seemed like os.walk was non-recursive to me. Maybe it was the examples I was looking at.

URL: https://forum.audiogames.net/post/433454/#p433454




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-13 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: python, I'm being dumb... again!

@5, that's odd since all the "recursive directory iterators" in Python always recursively called themselves with os.walk to "simulate recursion.". I wish that function was more obvious in what it did; at least C++ has recursive_directory_iterator in std::filesystem so you know without looking at the references that "hey, this is recursive".

URL: https://forum.audiogames.net/post/433454/#p433454




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : Sam_Tupy via Audiogames-reflector


  


Re: python, I'm being dumb... again!

@Ethin os.walk is indeed recursive. @1, basically when you loop through output from os.walk, you are getting a list with 3 items in it. This is usually represented by something like for root, dirs, files in os.walk(directory). However you can also execute for i in os.walk(directory) to get the above mensioned list. The first item, or root, is the root of the directory currently being walked. The second element or dirs, is a list of directories in the folder being walked, and the 3rd element, or files, is a list of files in the current directory being walked. So for example if you walk through documents and you have a folder called music within your documents folder, as well as a file called school_report.txt, and in the music folder you have a file called track1.mp3, the first iteration of the loop will give you the list ["documents", ["music"], ["school_report.txt"]]. Then music being the only directory, the next iteration will give you the list ["documents\\music", [], ["track1.mp3"]]. So yes os.wwalk will automatically scan subfolders, just to clear up that confusion. If you wish to scan a directory non recursively, you can use the os.listdir function, which simply returns a list of the files and the directories of the folder you give it. To see whether something is a directory or a file, you will have to call os.path.isdir and os.path.isfile on each item indivisually. Usually os.walk is the way to go!

URL: https://forum.audiogames.net/post/433315/#p433315




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : Sam_Tupy via Audiogames-reflector


  


Re: python, I'm being dumb... again!

@Ethin os.walk is indeed recursive. @1, basically when you loop through output from os.walk, you are getting a list with 3 items in it. This is usually represented by something like for root, dirs, files in os.walk(directory). However you can also execute for i in os.walk(directory) to get the above mensioned list. The first item, or root, is the root of the directory currently being walked. The second element or dirs, is a list of directories in the folder being awlked, and the 3rd element, or files, is a list of files in the current directory being walked. So for example if you walk through documents and you have a folder called music within your documents folder, as well as a file called school_report.txt, and in the music folder you have a file called track1.mp3, the first iteration of the loop will give you the list ["documents", ["music"], ["school_report.txt"]]. Then music being the only directory, the next iteration will give you the list ["documents\\music", [], ["track1.mp3"]]. So yes os.wwalk will automatically scan subfolders, just to clear up that confusion. If you wish to scan a directory non recursively, you can use the os.listdir function, which simply returns a list of the files and the directories of the folder you give it. To see whether something is a directory or a file, you will have to call os.path.isdir and os.path.isfile on each item indivisually. Usually os.walk is the way to go!

URL: https://forum.audiogames.net/post/433315/#p433315




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: python, I'm being dumb... again!

No, it won't. Os.walk doesn't do that either.

URL: https://forum.audiogames.net/post/433251/#p433251




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: python, I'm being dumb... again!

Thanks for the quick reply. I looked at os.scandir and it only seems to loop through the folders and work on the root of the folder. So if I have my documents folder and I use os.scandir on it, if I have any folders within documents it won't show the files inside it.

URL: https://forum.audiogames.net/post/433248/#p433248




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: python, I'm being dumb... again!

Root is the directory your walking. drs is the directories within that folder. Files are the actual files in that folder. It is possible using the drs return value to create a recursive directory scanner. As a side note, I'd recommend using os.scandir() instead of os.walk.

URL: https://forum.audiogames.net/post/433239/#p433239




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


python, I'm being dumb... again!

2019-05-12 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


python, I'm being dumb... again!

So, for the life of me, I can't figure out what does the os.walk(directory) do. I know it scans the files in some way, but I just don't understand... how?I saw a loop that had 3 arguments when using os.walk. Something like this.for root, drs, files in os.walk("documents")What is the root? What is drs? What are files? How does it all connect to windows file system, what do I use if I want to get information about a file... what about storing a path to something I found?I'm sure I'm being dumb once again, but can someone help out here?

URL: https://forum.audiogames.net/post/433237/#p433237




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector