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 ...
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 ...
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 ...
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)
...
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.
<...
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 ...
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:
...
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 - ...
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:
...
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 ...
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 ...
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
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:
<...
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()...
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 ...
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 ...
10
votes
Accepted
Portable old-school filesystem tool
EXIT_SUCCESS and EXIT_FAILURE
The language spec promises that EXIT_SUCCESS and ...
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 ...
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:
...
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 ...
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.
<...
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 ...
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 ...
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
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 ...
8
votes
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:
...
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♦
- 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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
file-system × 733python × 234
beginner × 96
performance × 81
python-3.x × 76
c# × 72
c × 58
c++ × 56
java × 55
linux × 44
php × 41
file × 40
bash × 39
windows × 34
recursion × 30
object-oriented × 29
javascript × 22
console × 21
python-2.x × 20
powershell × 20
vba × 18
node.js × 18
ruby × 17
error-handling × 17
strings × 16