Skip to main content
48 votes

A file class for Python

I'm about to say a lot of fairly unkind-sounding things. I'll say upfront, though, that this is generally good, simple, well-documented code. Unfortunately, it makes a pretty serious mistake that I ...
ymbirtt's user avatar
  • 840
18 votes
Accepted

Path shortener for GUI application

Python is 'batteries included', this means offloading code to the core library is a good thing, and often possible. In this case, if you're running Python 3.4+ you could make use of ...
Peilonrayz's user avatar
  • 43.4k
18 votes

Python tool to organize downloaded media files

I'm sure Peter is a nice guy, but you shouldn't write programs only for him. Use a parametric home directory. Some of your extensions support either case and some ...
Reinderien's user avatar
  • 63.1k
14 votes

A file class for Python

Private members You should mark file_path as not part of the public API for the class. You accomplish this with a leading underscore in the member name. eg) ...
AJNeufeld's user avatar
  • 33.9k
13 votes
Accepted

Generate a nested structure based on a list of file paths

You can split each path at / using split and then use reduce() to build that object. <...
Nenad Vracar's user avatar
13 votes

A file class for Python

One more warning bell here. You should not perform any shell invocation unless absolutely necessary, and that comes with pitfalls and security considerations that have to be fully understood. You ...
Kate's user avatar
  • 7,338
11 votes
Accepted

Bash script that lowercases files

In my testing, constructing one Perl script and running it repeatedly is much faster (0.5s versus 3.6s) then running a new Perl instance for each replacement: ...
choroba's user avatar
  • 1,393
11 votes
Accepted

A minimal CLI password storage and retrieval manager

I would pinpoint the major problems in the code which I would address first: do not manually handle provided command-line arguments - there is a great built-in module for it - ...
alecxe's user avatar
  • 17.3k
11 votes
Accepted

Go function to test whether a file exists

Instead of checking with an if statement if errStat is null and then returning false: ...
Eliahu Aaron's user avatar
11 votes
Accepted

A utility to swap two files

file1_path == file2_path surely tells that paths refer to the same file. However, even if file1_path != file2_path they still ...
vnp's user avatar
  • 57k
11 votes
Accepted

Header-only log-structured database

nit, typo: lenght ... lenght Also, "it is rebuilT from the data", and "reported as not writed" --> "written". motivation App developers who need logging features would ...
J_H's user avatar
  • 32.4k
10 votes

Get directory permissions for all directories in tree

This is not efficient pathString += String is immutable so it builds a new string every time Use StringBuilder
paparazzo's user avatar
  • 6,026
10 votes

Removing multiple slashes from path

Here are some suggestions for how you might improve your code. Use the appropriate #includes This program fragment requires headers, which should be included: <...
Edward's user avatar
  • 66.5k
10 votes

Backup with Hanoi Strategy

Do not silently ignore invalid arguments Your script allows to specify the source directory (and other locations). Here is the relevant part in function parseArgs()...
Martin R's user avatar
  • 23.3k
10 votes
Accepted

Random temp folder implementation for unit testing

You could easily wind up with collisions on the folder name if the method is called multiple times in very quick succession because of the new Random() being ...
Jesse C. Slicer's user avatar
10 votes

A file class for Python

At the moment, your class only fully works on Windows. On Mac OS and Linux all methods that call a command line tool with os.system will fail. You should make this ...
Graipher's user avatar
  • 41k
10 votes
Accepted

Portable old-school filesystem tool

EXIT_SUCCESS and EXIT_FAILURE The language spec promises that EXIT_SUCCESS and ...
John Bollinger's user avatar
9 votes

Removing multiple slashes from path

Your specification has holes in it. What will be if user passes NULL? Undefined behavior? Return? What if the path is already valid? Copy the string? Return ...
Incomputable's user avatar
  • 9,504
9 votes
Accepted

Recursively list files within a directory

Your function could be a generator (which were introduced in Python 2.2). It should also expose the pattern for the filter as a parameter: ...
Graipher's user avatar
  • 41k
9 votes
Accepted

Retrieve filetype:pdf from library

Similarly to a feature in most UNIX shells, Python has a globbing module, called glob. It even supports the extended globbing (using ...
Graipher's user avatar
  • 41k
9 votes

Find all files that match a filename pattern in a folder tree

As you tagged this Python 3.x, I'd suggest using pathlib.Path.rglob() and collections.defaultdict. Also, check out f-strings. <...
RootTwo's user avatar
  • 10k
9 votes

Python tool to organize downloaded media files

PEP-8 This already looks very readable. You use snake_case as per PEP-8 for variables and functions. However, the global constants should be in ...
Richard Neumann's user avatar
9 votes

Efficient file-copying utility using threads

Missing and incorrect error handling The most important problem with your code is that you either don't handle errors, or in some other cases handle them incorrectly. Already at the start of ...
G. Sliepen's user avatar
8 votes

Delete folder if it exists in PowerShell

It is better to use pipeline syntax. If there are no files, then nothing will happen: Get-ChildItem $folder -Recurse | Remove-Item
Max's user avatar
  • 81
8 votes

Simple backup script in Python

If the file size is 0, it ignores that file (when it returns 0 from the size function and uses that to determine if the file is newer). I noticed this when testing it and I created an empty file and ...
aljgom's user avatar
  • 181
8 votes

Initialization File Parser

The HasKey(string,string) can be simplified like so ...
Heslacher's user avatar
  • 50.4k
8 votes

Making a directory structure for a web project

I think it would be nice, if you could define the directory structure once and then let the program create it. Something like this: ...
Graipher's user avatar
  • 41k
8 votes
Accepted

Speech Recognition Part 3: Training the Neural Network

First things first: you can get far better results by fine-tuning the arguments. Yes, it goes over 52% at times and I'm sure it can go even higher. Let's take a look at what colours are caused by ...
Mast's user avatar
  • 13.4k
8 votes
Accepted

Extracting parts of filenames from an array

As said before, use map instead of a foreach loop and change the regex delimiter. If you put the array in double quote when print, a space is inserted between each element of the array in fact it is ...
Toto's user avatar
  • 559
8 votes

Disassembler for intel 8080

C++ is not Java. While there is a valid use-case for classes treated as namespaces with a type-name, that's only for traits-classes used with templates, and not for general consumption. I don't know ...
Deduplicator's user avatar
  • 19.3k

Only top scored, non community-wiki answers of a minimum length are eligible