Questions tagged [file-system]

For challenges relating to manipulating and traversing the file system. This may include reading directory trees, creating, moving and deleting files or directories, reading or changing file permissions, etc.

Filter by
Sorted by
Tagged with
6
votes
12answers
898 views

Recursively count lines of code, excluding empty lines and comments

Requirement: Write a program (in any language) that counts the number of lines of code in files matching *.sh in the directory tree starting from the directory that ...
3
votes
14answers
659 views

Rest of the path

Consider this file path: C:/Users/Martin/Desktop/BackupFiles/PC1/images/cars/new.png Your goal is to write a program that will return the file path starting from ...
11
votes
13answers
620 views

Checking a file contains only null bytes

Your goal is to write a program or function that takes in as input a string representing the path to a file, and outputs a truthy value if that file is not empty and contains no non-null bytes -- i.e.,...
19
votes
23answers
2k views

Insist on a new filename

At runtime, keep prompting for a line of input until the user input is not the name of an existing file or directory or other file system item, relative to the current working directory. Then return/...
-1
votes
9answers
191 views

Extract filename from path [duplicate]

Given a printable ASCII string representing a path to a file on a POSIX-compliant system, return just the filename, i.e. remove everything until and including the last slash (...
9
votes
2answers
424 views

Shell Glob Golfing

This task is to output the shortest path to a file, after glob expansion. What is shell globbing? In most shells, you can use the * character in a path to ...
-4
votes
4answers
223 views

tail: troll: file truncated

Background When you run tail -f file in bash, the file is outputted and then any subsequent appends. However, when you remove something that has already been ...
11
votes
14answers
997 views

Pad a file with zeros

Your task today will be to take an existing file and append zeros to it until it reaches a certain size. You must write a program or function which takes the name of a file in the current directory <...
-5
votes
1answer
152 views

Reverse the file [duplicate]

I remember this was exam question long long long time ago. There is a file say MyFile.txt, it can be any size and contains aphanumeric only your task is to revese the words example : "Go beyond the ...
-4
votes
14answers
224 views

Create a folder

Challenge Given an input x, create a directory (AKA folder) in the file system with the name x. Languages that are not able to ...
17
votes
9answers
2k views

Shorten an absolute path

Sometimes a long absolute path, in e.g. a command-line parameter to a linux tool, can be shortened, using current working directory as reference: ...
9
votes
10answers
588 views

Hello world that handles errors

Write a program or function with the following functionality: The program/function first attempts to write the string Hello, world! to the standard output stream. (...
9
votes
4answers
429 views

Quining, but with Windows files!

Write a quine, that when run, creates itself in the current directory, in a source file named itself. We will be using Windows in this, so the file name (and therefore quine) must have the following ...
19
votes
26answers
2k views

Find the smallest file

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 ...
19
votes
9answers
1k views

Be there or be square!

Everybody has heard of the phrase "be there or be square". So I thought it was time for a challenge about it. Input You will take a full absolute directory address as text as input via STDIN or ...
13
votes
17answers
2k views

Clone yourself!

You are to create a program that creates exact clones of itself infinitely until stopped. Whatever is in the original program must be in the clones. In other words, the clones and original program are ...
6
votes
3answers
289 views

Line ending conversion program

Write a program or function that alters the file at a user-specified filename via replacing all instances of UNIX line endings with Windows line endings and vice versa. Clarifications: For the ...
-2
votes
2answers
107 views

Numeric to Alphabetic Organization [closed]

I have a list of images grouped numerically (YI0.png, YI1.png...YI20479.png). I want them ...
17
votes
15answers
2k views

Write a program that outputs the number of times it has been run [duplicate]

In a programming language of your choice, write a full program that, when run, prints a positive integer N and then modifies its own source file such that the next time it is run it will print N+1. ...
0
votes
3answers
159 views

Output source file name [duplicate]

Write a program that prints the name of its source file. REPL environments are not allowed for this challenge. Your code must work in any file that your language's interpreter will accept. Your answer ...
11
votes
50answers
2k views

Create and write to a file

Challenge Create a new file and write the string Hello World to it. Restrictions Your challenge must write to a file on disk, in the file system. The file may ...
8
votes
8answers
646 views

Missing Integer Sequence Detection — Filesystem

The challenge is to detect missing integer sequences of files or directories. You have a directory filled with files/directories that are named as integers. The files/directories are generated from ...
9
votes
11answers
565 views

Write a program to display directory treehouse

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 ...
19
votes
14answers
558 views

Directory calculation

For this challenge, you will be given an absolute path, and a "new" path (which can be absolute or relative), and you need to return the final path. For example, if your current directory was ...
27
votes
9answers
977 views

Decode a Microsoft MS-DOS 5.0 FAT directory entry

The Microsoft FAT file system has a directory table to represent which "files" are in which "folders" on the disk. For the time, these entries crammed a lot of information into a small amount of bits. ...
26
votes
30answers
3k views

Write a program that reverses the name of its source file

In a single file, write a program that requires no input and produces no output. When run it should reverse the name of the file it is contained in, regardless of what the name is, without altering ...
16
votes
10answers
2k views

Read n random lines from a potentially huge file

This challenge is about reading random lines from a potentially huge file without reading the whole file into memory. Input An integer n and the name of a text ...
7
votes
1answer
223 views

Make a directory tree

Imagine for a second that you can compose a tree out of dots. ...
20
votes
1answer
537 views

The puppy command

The puppy utility takes a filename as input, and does exactly what you would expect a puppy to do: it shreds it! How to shred Rip out the pages with your teeth ...
13
votes
4answers
409 views

Interpret the Pig series

Given an input of a Pig, SickPig, DeadPig, QuinePig, or DeafPig program, choose one of those "languages" randomly and interpret the input as that "language." First, randomly choose between one of the ...
3
votes
1answer
233 views

golffs - Implement a FUSE filesystem [closed]

Implement a FUSE filesystem in minimum bytes. Your program must do three things: Mounting the virtual filesystem to a directory Handling requests to enumerate files in that directory (showing one ...
-5
votes
5answers
661 views

Standard loopholes only [closed]

So, you're browsing Programming Puzzles & Code Golf, and you see a new challenge. The author (gasp) forgot to say "No standard Loopholes". You decide to take advantage of this situation, and you ...
9
votes
1answer
396 views

Hello human, I want to recover my little cat pics

NB : Everything presented in the situation is totally fake and had just been put here to make the challenge a little more fun ;) ... Or maybe not ;) === === BEGINNING TRANSMISSION === === Hello, I ...
10
votes
5answers
376 views

Implement the dog bash utility

dog is a command-line utility that takes in an arbitrary number of arguments, the first of which is the text to be written and the others are arbitrarily many files....
65
votes
22answers
11k views

The kitten command

A kitten is much like a cat. Some of the main differences are cuteness, lack of intelligence, and size. Similarly, the cat command is different from the ...
3
votes
4answers
392 views

Words of centuries

I'd like to get a list of words that are strongly connected with a particular time epoch, for example, 19th century, 20th century and 21st century. I suspect that nobody used a word like "smartphone" ...
-2
votes
2answers
107 views

Print the content of /etc/passwd with constant creation limit [closed]

Rules/Objectives: The program must be executed using ./program-name without shell parameter/arguments. the program-name may not ...
12
votes
4answers
605 views

H Tree Directories

Programmers are often obsessed with drawing fractals. I think we need a new computer based medium. The H tree is a fairly simple type of fractal made of horizontal and vertical lines. Here it is at ...
18
votes
9answers
3k views

A Skittish Program

Objective You are to write a program that receives an integer n as input (from the command line), and embeds itself (the program) ...
61
votes
15answers
11k views

I HATE spaces in file names

It is simple. I cannot stand when people use spaces when naming files. It sometimes wrecks console commands and makes the output of ls ugly. The challenge is to write a program (only ascii characters)...
2
votes
14answers
2k views

Traverse a directory tree and output a list of all files

Write the shortest code that traverses a directory tree and outputs a flat list of all files. It should traverse the whole directory tree The order in which it enters sub-directories doesn't matter ...
22
votes
30answers
4k views

A program that deletes itself

If a compiled language is used, the program must delete the compiled executable (but need not delete the source file). If an interpreted language is used, the program must delete the source file. My ...
11
votes
7answers
498 views

Code Golf: Directory Tree -> Tree

Contest (!): In the language of your choice, write a program that will traverse the directory tree of a given directory and output a tree (i.e., an array of arrays) corresponding to it. Assume the ...
17
votes
1answer
3k views

Hide evil code - print files containing a given string anywhere in a directory tree [closed]

The point of this puzzle is to learn how a malicious code can be hidden and discovered in a program. A person is asking the question: Plz give me some code that how can I search a file may be in ...
7
votes
5answers
1k views

“Useful” self-modifying script for financial firm [closed]

True Story: Several years ago while interviewing at an investment advisory firm that managed over a billion dollars in client funds, I was asked a collection of reasonable and bizarre questions by a ...
12
votes
6answers
3k views

Delete those pesky “.DS_Store” files

If you use OS X then you might be familiar with the infamous hidden ".DS_Store" files that are produced as a result of using Finder. The challenge is to write code that will go through the entire ...
8
votes
3answers
718 views

Advanced Code Golf - Disk Operations, and File Allocation

Good Afternoon Golfgeneers. This is reasonably long and detailed question. Given what it was asking, it needed to be. If you have any questions, please ask them. If there is anything that isn't clear,...