9
2
Given a directory (such as C:/
), given from stdin or read from a file, produce a directory tree, with each file/folder indented based on its depth.
Example
If I have a C:/
drive which only contains two folders foo
and bar
, and bar
is empty while foo
contains baz.txt
, then running with input C:/
produces:
C:/
bar/
foo/
baz.txt
while running with input C:/foo/
should produce
foo/
baz.txt
As this is codegolf, lowest byte count wins. The file extensions (such as baz.txt
) are optional.
Extra notes: hidden files can be ignored, directories must actually exist, it can be assumed that files do not contain unprintable characters or new lines but all other printable ASCII characters are fine (file names with spaces must be supported). Output can be written to file or stdout. The indentations can be made up of either a tab character or 4 spaces.
1Extra note: this question is poorly formatted, so a reformatting would be appreciated. – Mathime – 2016-07-16T20:38:42.567
Are languages that do not have access to files automatically disqualified? – Leaky Nun – 2016-07-16T20:48:19.253
What filenames have to be supported? Files with spaces in their names? With newlines? With unprintable characters? What about hidden files (beginning with
.
)? – Doorknob – 2016-07-16T20:49:12.527@DrGreenEggsandIronMan I believe the answer to your question is yes. – Leaky Nun – 2016-07-16T20:50:47.810
Edits have been made. – Mathime – 2016-07-16T20:52:27.280
Related. – Leaky Nun – 2016-07-16T20:52:31.977
@LeakyNun I'm aware of that question, but this is entirely different. – Mathime – 2016-07-16T20:53:13.067
@Mathime What is the difference? – Leaky Nun – 2016-07-16T20:53:38.670
1@LeakyNun Output of reference question is an array of arrays. This question requires a representation of the directory tree to be printed to stdout. – Mathime – 2016-07-16T20:56:37.683
What characters specifically may the files contain? Only letters, numbers, and spaces? Or can there be a file called
{{}{#)((*[']238..23[]]4.2]3["'''"
? – Doorknob – 2016-07-16T21:00:04.963directory entries sorted, unsorted or no preference? – Titus – 2016-07-16T21:00:59.437
@Doorknob any printable ascii characters – Mathime – 2016-07-16T21:05:46.257
@Titus if you mean alphabetically sorted, no preference. – Mathime – 2016-07-16T21:06:07.570
Must directories have trailing
\
? It is obvious that they are dirs because of the indentation. – Adám – 2016-07-18T12:45:04.620@Adám they are preferred but not mandatory. – Mathime – 2016-07-18T14:41:59.773
Must the first output line of
C:/foo/
befoo/
or isC:/foo/
acceptable? – Adám – 2016-07-18T16:10:05.6731Can the input be a string parameter to a function? – mbomb007 – 2016-07-18T16:32:40.310