How to open a random folder within a directory
1,512
>>> import random
>>> import os
>>> files = os.listdir('/tmp')
>>> dirs = [f for f in files if os.path.isdir(f)]
>>> random.sample(dirs,1)
['tempdir']
Related videos on Youtube
Author by
Sunny Shah
Updated on November 23, 2022Comments
-
Sunny Shah over 1 year
I was wondering how I would use a batch file or Python to open a random folder from a selection of many folders within a directory?
-
Tinellus almost 12 yearsYou should be able to elegantly reboot your system by pressing Alt - SysRq (both at the same time) and combine with these, one after the other: r e i s u b (aka the magic SysRq key en.wikipedia.org/wiki/Magic_SysRq_key). Could you report back if this works for you or not? You could also check in var/log/syslog and var/log/kern.log (open the log files in gedit) if something out of the ordinary has happened at the time of the freeze/lockup. If there is something, copy the relevant messages to pastebin.com and post the link in your question.
-
Bruno Pereira almost 12 yearsYou should report this issue as a bug in launchpad.net, they will guide you and help you sort out if there is another bug already open with it.
-
artfulrobot almost 12 years@Tinellus Will try the magic SysRq thing on my box that has a SysRq button (the laptop doesn't). There is nothing in syslog, guess it doesn't have time to write it. @Bruno i guess you mean
ubuntu-bug linux
? -
jpetersen almost 12 yearsif you have a "Print Screen" button you can use Ctrl + Alt + PrtScrn....just incase you were overlooking that key on your laptop
-
artfulrobot almost 12 yearsThanks, not had much success with that in the past, perhaps I'm running out of fingers!. Will report back when I crash it today.
-
artfulrobot almost 12 yearsYep, unresponsive to Alt-SysRq.
-
vchyzhevskyi about 11 years1) get list of all folder within a directory 2) random.choice(<list of folders>) 3) open directory 4) PROFIT!
-
bereal about 11 yearsFirst of all, what do you mean by opening a folder?
-
Sunny Shah about 11 yearsSorry I meant a batch file
-
MattDMo about 11 years@coirius - really? It should be 4) ... 5) PROFIT! The "..." is the most important step of all!
-
-
artfulrobot over 11 yearsinteresting! I do use Chromium sometimes. However, have def. had freezes without it.
-
artfulrobot over 11 yearsah, shucks, back again. filed bug