File manager

Create a file manager in C in just 170 lines of code

I’ll show you how to write a file manager in C in just 170 simple lines of code.

It’s all about low-code and high performance. Why use languages ​​that still work with interpreters, byte-code engines, and similar contraptions, when you can circle around them?

How am I going to do this?

I will do this using Vely.

Vely is a framework for C programmers. It is based on an API concept and instruction queries. More on that towards the end of this post.

What does the app look like?

The user can upload files to the server, see them in a list with links to view or download them, and finally each file can be deleted.

Here’s what the end result looks like (you can add CSS or style it as you see fit, it’s plain HTML):

Vely File Manager main page

Display of the list of downloaded files:

Vely File Manager File List

Deleting a file starts by asking for confirmation:

Vely File Manager deletion request

then delete:

Preconditions

You will need to install Vely of course, but no worries, you can use standard Linux packages like apt, dnf, zypper or pacman. So if you don’t like it, uninstall it and poof, go!

You will also need to install Apache and PostgreSQL – you may already have these as they are common. It is more or less that.

Where is the code?

Step-by-step instructions are at

https://vely.dev/example_file_manager.html.

The example itself is part of the Vely installation, so once you install it, other than copying and pasting command lines, you don’t need to write any code.

The sample is easy to try out and functional enough for the real world to show Vely in action. Give it a shot!

And now a little about Vely. As I said, Vely allows you to use Statement APIs to process HTTP requests. This is true for web and command line applications.

Declaration API

A statement API is a declarative statement that does something useful, like query a database, write a file, parse a JSON file, run a program.

It does this by generating C code. It’s not like a macro though. A lot more goes into a compile-time declaring API so the developer experience is much better.

Here is a sample code:

Look and feel of the Vely source code

Requests

Vely works by processing HTTP requests (GET and POST), at all levels, for web and command line applications.

An HTTP request is given by a URL. The URL path has the application name and the only required parameter (“req”) has the name of the .vely file that handles it. Quite simple and it helps to understand at a glance the queries the app is serving.

Cover photo by Annie Spratt on Unsplash


Here too

LOADING
. . . comments & After!