19
1
Goal:
Create a program to find the smallest file in the current folder.
- File size may be measured in bytes or characters.
- If multiple files have the same size, you can either choose one or display all of them.
- You can assume there will be at least one file in the folder, and no files will have a size of 0.
Assume that all files in the folder can be loaded by the language you're using.
Assume that there are no folders in the current directory.
Input:
The program should not take any input from the user, unless:
- If your language doesn't have a "current folder", it may ask the user for a folder name/path.
- If your language cannot directly access files on your computer, it may allow the user to upload files. (JavaScript, for example)
Output:
The name of the smallest file should be displayed.
- Leading/trailing symbols are allowed, as long as it's clear which file has been chosen.
- (Printing a list of all the files is against the rules).
Notes:
- Standard Loopholes are not allowed.
- You cannot modify/create/delete files in the folder to change the result.
- This is code-golf; shortest answer (in bytes) wins.
1Can we assume files can have a size of 0? – Rɪᴋᴇʀ – 2017-01-27T21:27:42.413
Also, what does "assume that all files in the folder can be accessed" mean? does that mean hidden files don't need to be shown? – Rɪᴋᴇʀ – 2017-01-27T21:28:02.747
What if there are multiple files of the same size? does any work? – Rɪᴋᴇʀ – 2017-01-27T21:28:41.617
Can we assume files can have a size of 0?: sure "assume that all files in the folder can be accessed": If your language is only able to access, for example,
.png
files (for some reason), you can still post an answer. What if there are multiple files of the same size?: You can display one or all of them. – 12Me21 – 2017-01-27T21:34:57.213So if your language can only support it, not if it just takes more bytes? – Rɪᴋᴇʀ – 2017-01-27T23:06:33.893
2Can I assume there are no folders on the current folder? It makes all the difference if you have a language function that returns both files and folders instead of only files! – sergiol – 2017-01-28T01:39:45.800
Whenever possible you should avoid making edits that invalidate existing answers. Also, I don't know what work if there are other folders means. Should it simply not break or should it search recursively for the smallest file? – Dennis – 2017-01-28T03:18:20.737
The only other choice was to leave an ambiguity in the question. – 12Me21 – 2017-01-28T03:20:39.043
1Not necessarily. You may assume that there are no directories inside the current directory is unambiguous and doesn't invalidate any answers. – Dennis – 2017-01-28T03:31:43.057
Now that I think about it, that would be closer to the original intent of the challenge. – 12Me21 – 2017-01-28T03:32:56.533
You never answered my question about more bytes vs actually impossible. For example, bash's
ls
can access hidden files, but it takes the-a
flag. Are we required to use that? You say "If your language is only able to access .png", but that's a bit unclear. – Rɪᴋᴇʀ – 2017-01-29T14:25:29.8401(sorry I haven't replied sooner, my internet connection was down for a few days) The problem I have with allowing you to skip hidden files is that it seems to open a lot of loopholes. Allowing you to skip files that are "slightly harder to access" would mean people could do something like only checking the first 9 files because it saves a few bytes. – 12Me21 – 2017-01-30T13:59:28.530