Improve this question. JasonSmith JasonSmith Add a comment. Active Oldest Votes. Other than that, I do not understand why you see any problem with this solution. It is fine. Improve this answer.
Yuval Adam Yuval Adam k 87 87 gold badges silver badges bronze badges. Hey, guess why I landed on this page? If you want directories included, Yuval A's answer. Otherwise: import os, random random. Or if you want to emulate a wildcard : random. To get a random file anywhere beneath a directory:! Language agnostic solution: 1 Get the total no. Similarly language-agnostic: get the list of files in the directory, and pick one by random. Mork Mork 5, 4 4 gold badges 22 22 silver badges 23 23 bronze badges.
Here's one attempt: import os import random def getRandomFile path : """ Returns a random filename, chosen among the files of the given path. So, the algorithm to open a randomly chosen file in a given directory should: Actually open the file selected, and handle a failure, since the file might no longer be there Probably limit itself to a set number of tries, so it doesn't die if the directory is empty or if none of the files are readable.
Chris Norman Chris Norman 26 2 2 bronze badges. This answer could be improved by explaining what problem it solves that is not solved by the approach presented in the question. At the same time, this translates into the ability to carry Random File Picker with you on a removable storage device and use it on all compatible systems, without a trace left on the host system. The program is meant to help you make a choice whenever you are unable to do so based on your personal preferences.
If you cannot seem to decide which movie to watch, which social media profile picture to use or which wallpaper to set for today, Random File Picker can step in. To view the files inside a directory, you can just double-click it and the right-side panel will list them one by one.
For choosing a random entry, you can press the corresponding button in the panel and the result will be shown in the lower section. Keep in mind that setting the download location for one browser won't change it for any other browsers on your computer.
With Chrome, start by clicking the menu dots in the upper right corner. Choose 'Settings,' then 'Advanced,' and then 'Downloads. With Edge, start by clicking the menu dots in the upper right corner of your screen. Next, choose 'Settings' and scroll lower to 'Downloads. With Safari, start by clicking on 'Safari' in the top left corner. Select 'Preferences' and then 'General. Log in Social login does not work in incognito and private browsers.
Please log in with your username or email to continue. No account yet? Create an account. Edit this Article. We use cookies to make wikiHow great.
By using our site, you agree to our cookie policy. Cookie Settings. Learn why people trust wikiHow. Download Article Explore this Article methods. Tips and Warnings. Related Articles. Method 1. Open Google Chrome. It's a red, green, yellow, and blue sphere-shaped icon. This icon is in the top-right side of the Chrome window.
Click Settings. It's near the bottom of the drop-down menu. Scroll down and click Advanced. This option is at the bottom of the page. Doing so will open a window with your computer's folders displayed.
Select a folder. Click a folder into which you want downloads to save. It's in the bottom-right corner of the window. This will choose the folder you clicked as the default location for any subsequent downloads. You can also click Ask where to save each file before downloading to enable or disable a prompt for each download. Method 2. Open Firefox. This is the globe-shaped icon with an orange fox wrapped around it. It's in the top-right corner of the Firefox window.
This prompts a drop-down menu to appear. Click Options Windows or Preferences Mac. This gear-shaped icon is in the drop-down menu. Click the General tab. It's in the upper-left side of the window. Check the "Save files to" box. Click the circle to the left of the "Save files to" option to enable downloads for a specific location.
If you would prefer to be asked where to save a download every time you download something, click instead the "Always ask you where to save files" circle.
0コメント