file1_path == file2_path surely tells that paths refer to the same file. However, even if file1_path != file2_path they still may refer to the same file.
file1_exists = std::filesystem::exists(file1_path); introduces a TOC-TOU race condition. The file may exist at the time of test, yet disappear by the time of use. See the next bullet.
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 declared for each usage. It should be instantiated once, and since you mentioned it could be called on multiple threads, it should be mutexed onto one at a time. Finally, it's not a good idea to have ...
Function equal to built-in
dir_array = 
for x in os.listdir(Dir):
This is exactly the same as os.listdir, so just use it instead of the whole function.
for x in range(len(dir_array)):
file_size = float(get_dir_size(Dir + "\\" + dir_array[x])) / ...
A lot of your commentary on this code revolves around whether bash is a good choice for this project. I would say, yes, it is a good choice. You have shell commands, and you want to make a bit of a wrapper around them. That's a perfect use case for shell, even with so many more recent choices available.
A related concern that you raised is
At first glance, here are the few things I saw that need to be fixed:
Your functions seem pretty long, and this possibly leads to violation of single responsibility principle. Make sure each of them does only a single job.
There are many magic numbers (such as using 0:3, 0:4 while slicing arrays). Same applies to your strings too. As someone who reads your ...
Python 3 classes
You should omit (object) as the base class for classes in Python 3.
changes is a global that's mutated by FolderSyncer, so immediately this is neither re-entrant nor thread-safe. Maybe move the changes list to a member of FolderSyncer.
Your changes has a few other issues:
The inner lists should be tuples, ...
I have a writeOnFile() method with too many fwrite(). ...
A way to reduce fwrite() calls is to simply write all text to a large char buffer and then write that once per for (int i = 0; i < global_index; i++) loop.
Use the return vale of snprintf() to speed calculation of next offset. Use *printf() features for padding.
for (int i = 0; i < ...
I don't think that this:
should be necessary. I would expect that if you simply join, it would do what you want - block until the observer is done.
Even if you retained the above structure, you're ...
I think you are trying to reinvent the wheel.
This task can be easily achieved with Pandas.
Using Pandas should come with a few benefits:
it will make your code more precise,
it will reduce its length, and
it will increase the readability. Which will make the reviewers give more attention to your code.
After installing Pandas you can use the pandas....
If not a fan of using a for loop to echo each value in a list to 'return' a list. Is there a cleaner way to do this?
The printf command will reuse the format string to consume all the input:
printf "%s\n" $mounts
I'm not a fan of names like $argv rather than $uuid as they make the code harder to understand. Is there a clean way to specify ...
Your design lacks robustness. I.e. it relies on a specific parent-child relation described with object references but it does not enforce that the relation is sound in the data structure. You allow insertion of parentless entries and entries with different parent to a directory.
Representation of reality
Since this is a representation of a ...
You use pathlib.Path, which is great, but it can do a lot more:
Operations like os.path.splitext should be modernized using the suffix attribute of Path objects; for a full list of those designated replacements, see the documentation.
os.scandir can in this case be replaced by Path.rglob. This is where the recursion you mentioned comes into play. But that's ...
A few changes I would make:
Follow PEP 8.
Use the modern, high-level pathlib instead of a combination of the os module, glob, and shutil.
Be careful when using a bare except:, or except Exception:, see https://stackoverflow.com/q/54948548.
docs_dir = pathlib.Path('')
target_dir = pathlib.Path('')
for file in docs_dir.glob('*-*'): # Each ...
Here is my version based on two personal preferences: I hate scroll bars and I hate repititions. Hence I prefer everything typed once and also I like my code being fully visible in the default code area on Stack Overflow.
for this reason I removed that double spacing which just hurts my eyes
also I removed the try catch which is a cargo cult code that makes ...
Use References in place of CreateObject
If you include the reference to the Microsoft Scripting Runtime you can reduce the dim and set of objFSO to
Dim fso As New Scripting.FileSystemObject
to increase readability. Note that i have removed the obj prefix as it is no longer dimmed as an object. Similarly, this can be done with the file as
My first feedback about IFileValidator interface would be to have an Exists() method, just like how you're having one in IDirectoryValidator interface. Plus the Validator interfaces are doing much more than validation I feel. For example, it is also trying to get a list of subdirectories and files. It is good if Validators only handle the job of validations ...
Well, the first thing I can see is it's good you have been exposed to the concept of OOP, but you're needing a bit more understanding, which will come with experience.
Primarily, OOP is really around objects and their data or the actions which they do - for instance Dog("Spot").bark() as an action or Dog("Spot").name as a property/value.
I mention that ...
the fastest way is to keep a counter of the number of entries allocated. then on the first call to realloc() just allocate for a single entry. Only call realloc() when all the current allocation is used. each time `realloc() is called, double the allocation count. I.E. 1, 2, 4, 8, 16, 32, etc.
Be sure to always assign the result of realloc() to a temp ...
Calling realloc in every iteration makes the code really slow. Algorithmically it is in \$\mathcal O(n^2)\$ since realloc already has complexity \$\mathcal O(n)\$. Plus, you are calling it interleaved with malloc for the name of the directory entries.
The performance of your program depends very much on the specific memory allocator. It might be very fast or ...
I think you understand the tradeoffs: you can either use __file__ everywhere or trust the stack to rewind to the caller's frame of reference. The former looks redundant, but the latter makes your function kinda weird and may behave oddly if the user isn't aware of what's going on. For example, if they decorated your function, then they might get the file ...
As far as I can tell, you're returning error only in case of read_dir failure. Not sure if anyone ever really needs it, but you could change upmost Some() to Ok(), remove .ok() and fix the signature so that my version works just like yours. Note: the code below wasn't tested. I didn't like nested structure of your function, so I came up with this:
As @OnurArı suggested, your naming needs work. In particular, this:
is probably worse than having no function at all, so it's good that you attempted to split it up.
Some nuance to the other answer: yes, mutation_adder should be add_mutation (imperative-tense verb) as a function. Where you would see MutationAdder (noun) is if it'...
lastAccessed and lastUpdated are not set beside in the entry constructor.
a file's size is usually affected by its content.
addEntry and deleteEntry should affect the parent of entry that was added/removed.
Validations and error handling. For example, having 2 different files with the same name in the same directory.
create Subclasses / interfaces
if you think there is a difference in Behaviour then there is a need for a seperate class - if you think some classes have something in common, extract an interface!
so create a class Directory and a class File. Let both classes implement the Node Interface. (Note - in Java we don't use the hungarian notation )
inconsistency // ...
For the sake of your code and mine, I hope that the usernames cannot contain any colons since that is the delimiting character between usernames and passwords!
I have a bias toward regex because I have a fair handle on it and I enjoy the utility and brevity that it affords my scripts. I also don't (personally) enjoy all of the imploding and exploding going ...
First thing I notice is that this...
nxt = input('Welcome, press enter to continue \n')
if nxt == '':
...could just be:
input('Welcome, press enter to continue')
It doesn't seem like you're using nxt for anything else so there's no need to store a value for it, especially if you just want the user to hit enter.
Next, you never do f_n.close() ...
If I understood correctly, you would like to have a straight function that, given a directory to analyze, returns its size and the size of every sub-directory.
You want the function to return a dictionary like the following:
where the values are the size of the ...
Try using pathlib over os when you're dealing with file/glob operations. It has a lot cleaner interface, and is part of standard library in python 3.
Name constants in your code with the CAPITAL_SNAKE_CASE. It is recommended guideline from the PEP-8.
Split your code into individual functions doing a single task each.
Put the execution flow for your code ...
#pragma once is not standard C++ - use conventional #ifndef/#define include guards until/unless that gets standardised (by that time, Modules will be a better approach, anyway).
This looks strange:
void mark(std::string& targetDirectory, std::string& watermarkPath);
Why include <...
For automation, I think you can look for Task Scheduler in windows (as you mention *.bat, I imagine cron isn't an option.
And just add a job daily (or weekly, etc.) to run your script and forget about that.