Create a folder

-3

Challenge

Given an input x, create a directory (AKA folder) in the file system with the name x.

Languages that are not able to create file system directories are excluded from this challenge.

The directory may be created anywhere, as long as the location is writable to the user running the program. Assume that the program is run as a non-privileged user on a modern Linux (or Windows if needed) desktop system.

Clarifications

  • Assume that the current directory is $HOME/%USERPROFILE%.
  • Assume that no file or directory exists with the name given.
  • Assume that the filename will only contain the characters abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.
  • Assume that the filename will always be 8 characters long or shorter.

Rules

  • The directory must actually be created. You can't just say "I made it in /dev/null".
  • Standard loopholes apply.
  • This is .

dkudriavtsev

Posted 2017-06-01T02:15:20.920

Reputation: 5 781

4Apart from leaving zero room for golfing (in what languages would the straightforward approach not be the shortest?), your challenge is also unclear. Does the third paragraph mean we have to create it in our home folder? Can we assume we're already there? What if a directory or file of the same name already exists? – Dennis – 2017-06-01T02:21:50.957

4Also, you might consider waiting a few minutes for feedback before complaining about the lack of it. – Dennis – 2017-06-01T02:22:32.797

@Dennis Clarified. – dkudriavtsev – 2017-06-01T02:24:54.950

Which characters can appear in the filename? – Dennis – 2017-06-01T04:10:28.847

@Dennis a-zA-Z0-9 upto 8 chars – dkudriavtsev – 2017-06-01T04:11:13.460

4You should really start using the Sandbox, Mendeleev. – Shaggy – 2017-06-01T08:38:23.480

Answers

3

MATLAB/Octave, 6 bytes

@mkdir

Creates a function handle named ans to the built-in function mkdir which accepts the folder to be created as a string

ans('folder_to_create')
ans('/absolute/path/to/folder/to/create')

Suever

Posted 2017-06-01T02:15:20.920

Reputation: 10 257

Where do you get input? – dkudriavtsev – 2017-06-01T02:20:32.940

@Mendeleev It's passed to the function – Suever – 2017-06-01T02:20:47.523

all right, thanks for clarifying – dkudriavtsev – 2017-06-01T02:25:15.573

2

Ruby, 11 + 1 = 12 bytes

+1 for -n

Dir.mkdir$_

Try it online!

Pavel

Posted 2017-06-01T02:15:20.920

Reputation: 8 585

2

Julia 0.5, 5 bytes

mkdir

Try it online!

Dennis

Posted 2017-06-01T02:15:20.920

Reputation: 196 637

2

Java, 33 31 bytes

-2 bytes thanks to @Phoenix - removing curly braces around lambda.

s->new java.io.File(s).mkdir();

In the form of a Consumer<String> where s is the name of the folder to create.

Mas

Posted 2017-06-01T02:15:20.920

Reputation: 151

You don't need the curly brackets for a lambda like that, I think. – Pavel – 2017-06-01T17:09:10.050

@Phoenix You are correct. Thanks! – Mas – 2017-06-02T17:54:00.457

Your code now has a curly brace on the end that you seen to have missed. – Pavel – 2017-06-02T20:52:43.230

@Phoenix thanks again, I'm not very good at this ;P – Mas – 2017-06-03T15:15:22.977

1

Bash, 8 bytes

mkdir $1

Try it online!

Pavel

Posted 2017-06-01T02:15:20.920

Reputation: 8 585

1

Python, 18 bytes

import os
os.mkdir

ovs

Posted 2017-06-01T02:15:20.920

Reputation: 21 408

1

Batch, 6 bytes

@md %*

Try it online!

Neil

Posted 2017-06-01T02:15:20.920

Reputation: 95 035

3can't you remove the @? other answers output to stdout as well – Felipe Nardi Batista – 2017-06-01T10:50:15.150

1

Go, 46 bytes

import."os"
func f(n string){Mkdir(n,ModeDir)}

totallyhuman

Posted 2017-06-01T02:15:20.920

Reputation: 15 378

1

Wolfram Language (Mathematica), 14 bytes

Run["md "<>#]&

Try it online!


The trivial approach is longer. Surprise! (demonstrates that Mathematica is very verbose)

Works on Windows only, where md is the command to create a directory. See this answer or this answer.


Explanation:

Run["md "<>#]&   Anonymous function.

    "md "        String literal "md ". (with a trailing space to separate
                   the command and the parameter (directory name)
           #     The input.
         <>      `StringJoin` together.
Run[        ]    Runs as a command.

user202729

Posted 2017-06-01T02:15:20.920

Reputation: 14 620

0

Mathematica, 15 bytes

CreateDirectory

alephalpha

Posted 2017-06-01T02:15:20.920

Reputation: 23 988

0

C#, 35 bytes

System.IO.Directory.CreateDirectory

Does what it says on the tin.

TheLethalCoder

Posted 2017-06-01T02:15:20.920

Reputation: 6 930

0

Batch, 2 bytes

md

md means make directory. Here it is in action:

C:\tmp>set f=md

C:\tmp>%f% foo

C:\tmp>dir f*.*
 Volume in drive C is OS
 Volume Serial Number is 6CC3-3025

 Directory of C:\tmp

02-Feb-18  09:56    <DIR>          foo
               0 File(s)              0 bytes
               1 Dir(s)  378,122,883,072 bytes free

Adám

Posted 2017-06-01T02:15:20.920

Reputation: 37 779

0

APL (Dyalog Unicode), 6 bytes

Prefix function.

⎕MKDIR

Try it online!

Adám

Posted 2017-06-01T02:15:20.920

Reputation: 37 779

-2

tcl, don't know how to count

My count could be:

  • 13, if everything on file mkdir $x is accounted.

  • 12, if file mkdir $as how I have seen in some answers x is not taken into account

  • 11, because in tcl whenever you use the value of x , you type $x, so only file mkdir is taken into account

  • 10, if is file mkdir by removing the trailing space from previous.

Source:

file mkdir $x

demo — Please reserve it for question asker. Look at files tree at the left where there is only root and main.tcl . Click the Execute button, it will run a script command on the green area; In the top of the files tree there is a Refresh button symbolized by an icon, click it and see folder1 and folder2 appearing.

sergiol

Posted 2017-06-01T02:15:20.920

Reputation: 3 055