Find the smallest file

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 ; shortest answer (in bytes) wins.

12Me21

Posted 2017-01-27T21:16:26.203

Reputation: 6 110

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.213

So 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.840

1(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

Answers

7

Vim 12 bytes

!!ls -Sa
Gd{

Try it online!

Explanation:

!! is the filter command. It pipes the contents of the current line to an arbitrary system command, and sends the output back into the buffer. It's useful for using external tools for things that bash is better at than vim, for example !!rev to reverse the current line, or !Gxxd to hexdump the buffer. In our case, the buffer is empty so it's equivalent to :r!ls, which just feeds the output of the command into the current line.

Now the cursor is on line 1, and we want to delete every line but the last one. The naïve approach is

G       " Go to the last line
 k      " Go up one line
  d     " Delete:
   gg   "   Everything up to the first line

But we can do better. Like I explained in this tip, the { can usually (but not always) be equivalent to gg. Here, it's even better. Because the motion is character-based, not line-based like gg is, we don't have to go up a line first, leaving us with

Gd{

James

Posted 2017-01-27T21:16:26.203

Reputation: 54 537

16

Bash + coreutils, 13 bytes

ls -Sar|sed q

Explanation:

ls -Sar|sed q
ls            # list files
   -S         # sorted, biggest first
     a        # show hidden files
      r       # reversed (smallest first)
       |sed q # q is quit at first line that matches given regex, 
              # given regex is empty so guaranteed match.         

Rɪᴋᴇʀ

Posted 2017-01-27T21:16:26.203

Reputation: 7 410

Posted this as my own answer, but I think it's too similar to yours. ls -1Sa|tail -1 is 3 bytes shorter and has cleaner output. – orlp – 2017-01-27T21:32:16.503

@orlp thanks!.. – Rɪᴋᴇʀ – 2017-01-27T21:33:26.253

1I don't think you need the '-1', pipe automatically puts one file per line. – G B – 2017-01-27T21:35:17.893

@EasterlyIrk I think GB is right. if ls detects output is to the terminal it will format the output into multiple columns. But if output is a pipe it will just do 1 per line. Compare ls vs ls|cat – Digital Trauma – 2017-01-27T21:41:13.857

Two bytes shorter: ls -Sar|sed q – Digital Trauma – 2017-01-27T21:41:50.040

@DigitalTrauma ah, true. and thanks! – Rɪᴋᴇʀ – 2017-01-27T21:42:15.110

Doesn't this fall into the "using other programs" loophole? – Micheal Johnson – 2017-01-27T23:11:33.823

@MichealJohnson which one? That's not a loophole... It's perfectly allowed to import modules in a submission, and coreutils is basically a module for bash that doesn't need to be imported – Rɪᴋᴇʀ – 2017-01-27T23:12:37.650

8

PowerShell, 30 24 21 bytes

(ls|sort le*)[0].Name

Try it online!

ls is an alias for Get-ChildItem. That's piped to sort-object with the length attribute, so the files are sorted by size. We index into that with the (...)[0] to get the first (i.e., smallest), and then take the .Name thereof. Output via implicit Write-Output happens at program completion.

Saved 6 bytes since we're guaranteed that only files exist in the directory. Saved an additional 3 thanks to ConnorLSW.

AdmBorkBork

Posted 2017-01-27T21:16:26.203

Reputation: 41 581

2Can you not get rid of the -file since only files are in the current directory? – Mutantoe – 2017-01-28T11:13:58.227

@Mutantoe Yes -- that was edited into the challenge after I posted this answer. Thanks! – AdmBorkBork – 2017-01-29T19:19:05.307

you can use sort le* to shave some bytes since powershell will accept it. – colsw – 2017-01-30T14:48:05.960

@ConnorLSW Yes, of course. Thanks! – AdmBorkBork – 2017-01-30T14:56:47.447

8

Python 2 3, 94 76 74 54 bytes

-18 bytes thanks to @orlp
-2 bytes thanks to @Jonathan Allan
-20 bytes thanks to a change in challenge specs

from os import*
print(min(listdir(),key=path.getsize))

ovs

Posted 2017-01-27T21:16:26.203

Reputation: 21 408

print min(filter(path.isfile,listdir(".")),key=path.getsize) is cleaner and substantially shorter. – orlp – 2017-01-27T21:36:11.657

Save two bytes moving to Python 3 since "." is the default. print(min(filter(path.isfile,listdir()),key=path.getsize)) – Jonathan Allan – 2017-01-27T22:14:21.123

Also I count 76 not 77. – Jonathan Allan – 2017-01-27T22:19:36.913

@JonathanAllan I measured the byte count count with wc which gave me 1 byte more – ovs – 2017-01-27T22:30:08.630

The extraneous byte would be due to a trailing newline, which is not required for Python. Additionally, since the challenge was updated to state that there are no subdirectories present, the whole filter bit is unnecesary. This also doesn't work in Python 3, since print is a function. The following would work, and be substantially shorter: print(min(listdir(),key=path.getsize)) – Mego – 2017-01-28T04:34:33.817

7

Ruby, 61 40 38 37 bytes

Thanks G B and Value Ink

p Dir[?*,".*"].min_by{|x|File.size x}

dkudriavtsev

Posted 2017-01-27T21:16:26.203

Reputation: 5 781

You can use ?. instead of Dir.pwd, and min_by{} to get the smallest file. Dir.foreach(?.).min_by{|x|File.size x} gets the same result in 38 bytes. – G B – 2017-01-27T21:41:54.093

@GB Thanks!

– dkudriavtsev – 2017-01-27T23:03:26.287

It's a shame that "all" files the language can access must be looked at, because Dir[?*] is much shorter but doesn't include hidden Unix files like .bash_profile... – Value Ink – 2017-01-28T02:02:52.700

Maybe Dir[?,".?"] could work. I haven't tried. And it's shorter. – G B – 2017-01-28T15:09:56.433

@GB It'd actually be Dir[?*,".*"]. Glob string .?* won't match file .a if it exists. – Value Ink – 2017-02-01T23:11:41.777

6

Mathematica, 35 bytes

FileNames[]~MinimalBy~FileByteCount

FileNames[] produces a list of names of all the files (and directories) in the current directory; ~MinimalBy~FileByteCount selects the name of the file whose byte count is smallest. FileByteCount throws a bunch of errors when it's applied to directories, but the errors don't derail the program.

Greg Martin

Posted 2017-01-27T21:16:26.203

Reputation: 13 940

6

Java 7, 149 142 bytes

String f(){String n="";long s=-1>>>1,p;for(java.io.File f:new java.io.File(".").listFiles())if((p=f.length())<s){n=f.getName();s=p;}return n;}

Try it online!

-7 bytes thanks to CAD97

Poke

Posted 2017-01-27T21:16:26.203

Reputation: 3 075

I think you want File::length not File::getTotalSpace – CAD97 – 2017-01-29T07:24:22.297

Untested Java 8: ()->java.utils.stream(new java.io.File(".").listFiles()).max((a,b)->a.length()-b.length).get().getName() for 104 bytes – CAD97 – 2017-01-29T07:31:17.643

@CAD97 You're right! What was I thinking... – Poke – 2017-01-29T16:09:26.783

6

SH (Linux/Unix) 15 14 13 14 bytes

ls -aS|tail -1

-S sorts by size (descending),

-rreverses and tail -1 outputs the last file in the list.

@ Dennis Thanks for saving 1 byte @Dani_l Thanks for saving 1 byte.

Abel Tom

Posted 2017-01-27T21:16:26.203

Reputation: 1 150

That finds the largest file, no? – Dennis – 2017-01-28T05:52:29.157

Nevermind, I'm tired. You could use tail though instead of reversing, and -1 is a shorthand for -n1. – Dennis – 2017-01-28T05:55:13.653

@Dennis Updated – Abel Tom – 2017-01-28T05:58:26.660

@EasterlyIrk Now it should :) – Abel Tom – 2017-01-29T14:47:12.543

@AbelTom cool, thanks for fixing. – Rɪᴋᴇʀ – 2017-01-29T14:47:56.147

What's specific to BASH in your solution? – None – 2017-01-29T19:46:26.173

@yeti I'm not sure I understand exactly what you mean. The solution would also work on UNIX shell ( /bin/sh ), /bin/bash is the program that use on my machine. – Abel Tom – 2017-01-30T11:47:38.810

@AbelTom — BASH has more features than SH, so if you do not use them, label your solution with SH... that was the direction I wanted to point at... – None – 2017-01-31T20:27:40.970

@yeti Updated Sir. – Abel Tom – 2017-02-01T06:56:54.443

4

MATLAB / Octave, 52 48 bytes

d=dir;[~,n]=min([d.bytes]./~[d.isdir]);d(n).name

Explanation

This gets a directory listing of all files and folders in the current directory using dir. The output of dir is a struct containing the filename, whether it's a directory or not, the size (in bytes), etc.

We can then take an array of the sizes of each in bytes [d.bytes] and perform element-wise division with a boolean indicating whether it's a directory or not ~[d.isdir] which will yield Inf where it's a directory (division by zero) and the size in bytes otherwise (division by 1).

We find the index of the minimum of this array using the second output of min and use that to index into the initial struct and display the name with d(n).name

Suever

Posted 2017-01-27T21:16:26.203

Reputation: 10 257

You should add disp(...) around the output to properly print it. Otherwise if for example there was a file called ans that is not the smallest in the folder the output wouldn't be clear as to which file is the smallest to anyone unfamiliar with MATLAB. – Tom Carpenter – 2017-01-28T15:33:31.710

@TomCarpenter Hmmm I interpreted "Leading/trailing symbols are allowed, as long as it's clear which file has been chosen" to mean that the ans = is ok – Suever – 2017-01-28T15:37:05.287

I've just realised MATLAB adds the implicit . (current folder) and .. (folder above), so cant remove the directory check it seems. Sorry about that. – Tom Carpenter – 2017-01-28T15:38:06.130

4

Batch, 43 39 35 bytes

@dir/b/os|(set/pf=&call echo %%f%%)

Output includes a leading space for some reason, but fortunately that's allowed. Edit: Now assuming there are no directories to save 4 bytes.

Neil

Posted 2017-01-27T21:16:26.203

Reputation: 95 035

Oh, using /p like that, dang clever! – AdmBorkBork – 2017-01-27T22:11:29.653

@AdmBorkBork Ah, I hadn't noticed that was allowed, thanks! – Neil – 2017-01-27T23:52:38.357

You're guaranteed that no sub-directories exist (the challenge was updated) so you can eliminate the /a-d. – AdmBorkBork – 2017-01-29T19:30:36.333

4

J, 21 20 bytes

>{.,(/:2&{"1)1!:0'*'

Saved a byte thanks to @Conor.

Explanation

>{.,(/:2&{"1)1!:0'*'
                 '*' Glob all files in current directory
             1!:0    Table of file metadata in that directory
       2&{"1         Get the file size of each
     /:              Sort the files by that
   ,                 Flatten
 {.                  Get the first value
>                    Unbox

miles

Posted 2017-01-27T21:16:26.203

Reputation: 15 654

@ConorO'Brien Thanks – miles – 2017-03-08T02:52:36.053

4

Perl 6,  33 32 31  16 bytes

'.'.IO.dir.grep(*.f).min(*.s).put

Try it

put '.'.IO.dir.min:{try .s//Inf}

Try it

put $*CWD.dir.min:{try .s//Inf}

Try it

put dir.min: *.s

Try it

Expanded:

put        # print with trailing newline
dir        # the list of files in the current directory
.min:      # find the minimum by
  *.s      # calling the `s` method (size) in a Whatever lambda

Brad Gilbert b2gills

Posted 2017-01-27T21:16:26.203

Reputation: 12 713

The function form of dir defaults to $*CWD, and the task description says you can assume there won't be any folders, so I think you can shorten that to dir.min(*.s).put. – smls – 2017-01-29T20:42:45.017

When I wrote this, it said the program must ignore folders. – Brad Gilbert b2gills – 2017-01-29T21:36:28.220

4

Scala, 52 bytes

Old version, 79 bytes

new java.io.File(".").listFiles.map(a=>a.getName->a.length)sortBy(_._2)apply(0)

Adjusted according to jaxad0127's advice. It is only 52 bytes now.

new java.io.File(".").listFiles.sortBy(_.length)head

Aria Ax

Posted 2017-01-27T21:16:26.203

Reputation: 321

Using head instead of apply(0) is shorter. Also, the toString method of File is fine, no need to call get name. – jaxad0127 – 2017-01-29T06:42:44.607

3

BATCH File, 77 72 63 bytes

@FOR /F "tokens=*" %%G IN ('dir/o-s/b') DO @SET F=%%G
@ECHO %F%

There's no direct equivalent of head or tail in BATCH, at least to my knowledge, so here's a kludgy work-around. (with much assistance from @Neil - thanks!)

The dir command, with /o-s to sort in descending file size, and /b to output only the file names. We loop through those with FOR /F, setting the variable F to the file name each time. Finally, we output just the last one with ECHO %F%.

Saved 9 more bytes thanks to Neil and thanks to guarantees that no directories are present.

AdmBorkBork

Posted 2017-01-27T21:16:26.203

Reputation: 41 581

1Your FOR variable needs two %s to work in a script. Otherwise, a few golfing tricks: 1. Don't use @ECHO OFF on short scripts, add a @ to each line and after DO. 2. Delete the space before DO. 3. The spaces and :s aren't needed in the dir command. – Neil – 2017-01-27T21:54:52.217

1@Neil Ack, thanks. Sorry, pretty rusty since I've been doing PowerShell... Thanks! – AdmBorkBork – 2017-01-27T22:01:28.507

3

PHP, 84 62 bytes

$t=array_map(filesize,$g=glob('*'));asort($t);echo$g[key($t)];

Since the question was updated with the assumption that there will be no folders in the current directory, I was able to remove the file check stuff and golf this down.


Here is my old answer:

$t=array_map(filesize,$g=array_filter(glob('*'),is_file));asort($t);echo$g[key($t)];

This is the best I could do. Maybe there is a better way I'm missing.

$t=array_map(              # visit each array element and...
    filesize,              # map each filename to its filesize...
    $g=array_filter(       # using an array of...
        glob('*'),         # all files and directories...
        is_file            # filtered by files...
    )                      # 
);                         # 
asort($t);                 # sort the array of filesizes, then...
echo$g[key($t)];           # print element from the array of files using the first key of the sorted array as an index

Kodos Johnson

Posted 2017-01-27T21:16:26.203

Reputation: 776

2

SmileBASIC, 110 bytes

DIM F$[0]FILES"TXT:",F$FOR I=0TO LEN(F$)-1F$[I][0]="TXT:
S=LEN(LOAD(F$[I],0))IF!Z||S<Z THEN Z=S:B=I
NEXT?F$[B]

Only looks at TXT: files, since DAT: files cannot be loaded unless you already know their size, making it impossible to load a random one.

12Me21

Posted 2017-01-27T21:16:26.203

Reputation: 6 110

How do you load a DAT: file? Could you brute-force every name/file size in the folder? – Pavel – 2017-01-27T22:38:26.400

Trying to load a 3-dimensional DAT: file into a 2-dimensional array (for example) will cause an error, so you can't brute force it. You just have to know the number of dimensions beforehand, which you normally would. – 12Me21 – 2017-01-27T22:41:38.240

Could you load a 2-d DAT: file into a 3-d array? Then you could create a maximum size array. And you can't catch errors in any way? – Pavel – 2017-01-27T22:43:04.117

Nope, that will cause a Type mismatch error. And there's no way to catch errors either. – 12Me21 – 2017-01-27T22:45:11.610

2

Tcl, 88 bytes

set s Inf
lmap f [glob -ty f *] {if [set m [file si $f]]<$s {set n $f
set s $m}}
puts $n

Try it online!

sergiol

Posted 2017-01-27T21:16:26.203

Reputation: 3 055

2

Node.js (using walk), 114 bytes

Ignore newline:

require('walk').walk(__dirname).on('file',(r,s,n)=>
(m=s.size>m.size?m:s,n()),m=0).on('end',_=>console.log(m.name))

This invokes a walker that traverses through the current directory (__dirname) and for each file calls a function with its stat s and a function next n() that must be invoked to continue the traversal. Then at the end, it prints a filename with the minimum size in bytes found. s.size>m.size returns false when m.size is undefined, so after the first callback, m is equal to the first file found, and continues from there normally.

Patrick Roberts

Posted 2017-01-27T21:16:26.203

Reputation: 2 475

2

R, 36 bytes

x=file.info(y<-dir())$s;y[x==min(x)]

Explained

file.info() returns a data.frame of "file information" when given a character or character vector of file/folder names which when used on the list of files/folders in the current directory (dir()), looks something like:

                                                               size isdir mode               mtime               ctime               atime exe
Polyspace_Workspace                                               0  TRUE  777 2014-11-28 17:29:25 2014-11-28 17:29:25 2014-11-28 17:29:25  no
Python Scripts                                                    0  TRUE  777 2016-03-21 23:59:41 2016-03-21 23:59:41 2016-03-21 23:59:41  no
R                                                                 0  TRUE  777 2015-12-23 20:11:02 2015-12-23 20:11:02 2015-12-23 20:11:02  no
Rockstar Games                                                    0  TRUE  777 2015-04-14 12:23:05 2015-04-14 12:23:03 2015-04-14 12:23:05  no
TrackmaniaTurbo                                                   0  TRUE  777 2016-03-24 17:15:05 2016-03-24 13:13:48 2016-03-24 17:15:05  no
ts3_clientui-win64-1394624943-2014-06-11 03_18_47.004772.dmp 314197 FALSE  666 2014-06-11 02:18:47 2014-06-11 02:18:47 2014-06-11 02:18:47  no

Subsequently we just have the find the name of the file for which the size column (abbreviated using $s) is the smallest. Consequently, if there are more than one file with the smallest size, all will be returned.

Bonus: if we also wanted to disregard folders in the current directory we could simply search for size when isdir == FALSE: x=file.info(y<-dir());y[x$s==min(x$s[!x$i])] which turns out to be 44 bytes.

Billywob

Posted 2017-01-27T21:16:26.203

Reputation: 3 363

Bit late, but file.size is shorter because you don't have to do $s afterwards. – JAD – 2017-06-23T11:06:15.850

1

Groovy, 49 bytes

m={f->f.listFiles().sort{it.length()}[0].getName()}

Try it online!

Closure, usage: m(new File("location"))

Magic Octopus Urn

Posted 2017-01-27T21:16:26.203

Reputation: 19 422

1

C#, 277 bytes

Not the shortest, but what would you expect from C#?

Golfed

using System.Linq;using static System.IO.Directory;class P{static void Main(){var x=GetFiles(GetCurrentDirectory());var d=new long[]{}.ToList();foreach(var s in x){var b=new System.IO.FileInfo(s).Length;if(!d.Contains(b))d.Add(b);}System.Console.Write(x[d.IndexOf(d.Min())]);}}

Ungolfed

//Linq using for List.Min()
using System.Linq;
//Static using to save bytes on GetCurrentDirectory() and GetFiles()
using static System.IO.Directory;

class P
{
    static void Main()
    {
        //String array containing file paths
        var x = GetFiles(GetCurrentDirectory());
        //Creating a Long array and converting it to a list, less bytes than "new System.Collections.Generic.List<long>()"
        var d = new long[] { }.ToList();
        foreach (var s in x) //Loop through all file paths
        {
            //Getting file size in bytes
            var b = new System.IO.FileInfo(s).Length;
            if (!d.Contains(b))
                //If there isn't already a file with this size in our List, add the file path to list
                d.Add(b);

        }
        //Get index of the smallest Long in our List, which is also the index of the file path to the smallest file, then write that path
        System.Console.Write(x[d.IndexOf(d.Min())]);
    }
}

Metoniem

Posted 2017-01-27T21:16:26.203

Reputation: 387

1

Röda, 32 31 bytes

{ls""|sort key=fileLength|pull}

It's an anonymous function that sorts the files in the current directory by file length and selects then the first file with pull.

Use it like this: main{ {ls""|sort key=fileLength|pull} }

fergusq

Posted 2017-01-27T21:16:26.203

Reputation: 4 867

Apparently ls"" works just as well as ls".". I think you can save a byte from that – user41805 – 2017-03-07T18:30:05.997

@KritixiLithos It seems to. Thanks! – fergusq – 2017-03-07T18:35:17.163

0

SmileBASIC 3, 105 bytes (competing?)

Beats 12Me21's answer but still suffers from inability to load DAT files (which feels very cruel to be disqualifying considering the circumstances.)

DIM F$[0],T[0]FILES"TXT:",F$FOR I=0TO LEN(F$)-1F$[I][0]="TXT:
PUSH T,LEN(LOAD(F$[I]))NEXT
SORT T,F$?F$[0]

The shorter version above is annoying and prompts you on every file to load, but it does work. For two bytes more you can suppress the prompt; change line 2 to this:

PUSH T,LEN(LOAD(F$[I],0))NEXT

snail_

Posted 2017-01-27T21:16:26.203

Reputation: 1 982

0

Batch File, 33 bytes

Batch files are moderately competitive this time, oddly enough.

@dir/os/b>..\q&set/pa=<..\q&"%a%.

Output

enter image description here


Find a way to stop the creation of q prior to dir/os/b being run and you'll save a maximum of 6 bytes by not needing to put the output file in a separate directory.

@dir/os/b>q&set/pa=<q&"%a%

Will always output q as the smallest file (unless tied for another 0 byte file) as it is created as an empty file before dir/b/os gathers a list of files.

BDM

Posted 2017-01-27T21:16:26.203

Reputation: 369

0

Zsh, 18 14 bytes

echo *(DoL[1])

Try it online! Try it online!

  • (D) globs dotfiles
  • (oL) sorts by size
  • [1] selects the first match

GammaFunction

Posted 2017-01-27T21:16:26.203

Reputation: 2 838

0

C++17 (gcc), 180 bytes

#include<filesystem>
using namespace std::filesystem;auto f(){std::error_code e;path r;size_t m=-1,s;for(auto&p:directory_iterator(".")){s=file_size(p,e);if(s<m)m=s,r=p;}return r;}

Try it online!

Requires a recent standard library that implements std::filesystem.

G. Sliepen

Posted 2017-01-27T21:16:26.203

Reputation: 580