11

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. std::filesystem::...


8

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 ...


7

Function equal to built-in def get_subdirs(Dir): dir_array = [] for x in os.listdir(Dir): dir_array.append(x) return dir_array This is exactly the same as os.listdir, so just use it instead of the whole function. Iterate simpler for x in range(len(dir_array)): file_size = float(get_dir_size(Dir + "\\" + dir_array[x])) / ...


5

Language choice 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 ...


5

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 ...


4

Python 3 classes You should omit (object) as the base class for classes in Python 3. Re-entrance 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. Anonymous tuples Your changes has a few other issues: The inner lists should be tuples, ...


4

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 < ...


3

Wait loops I don't think that this: try: while True: time.sleep(SLEEP_TIME) except: self.observer.stop() print("Observer Stopped") 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 ...


3

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....


3

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[1] rather than $uuid as they make the code harder to understand. Is there a clean way to specify ...


3

Robustness 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 ...


3

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 ...


3

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. import pathlib docs_dir = pathlib.Path('') target_dir = pathlib.Path('') for file in docs_dir.glob('*-*'): # Each ...


3

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 ...


2

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 Dim ...


2

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 ...


2

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 ...


2

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 ...


2

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 ...


2

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 ...


2

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: use std::...


2

Function naming As @OnurArı suggested, your naming needs work. In particular, this: def fun(): 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'...


2

Missing Implementation 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. Interfaces Use ...


2

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 // ...


2

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 ...


2

First thing I notice is that this... nxt = input('Welcome, press enter to continue \n') if nxt == '': break ...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() ...


2

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: { 'dir': int, 'dir/subdir1': int, 'dir/subdir1/subsubdir1': int, 'dir/subdir2': int, ... } where the values are the size of the ...


2

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 ...


2

#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: #include <iostream> class Watermarker { public: void mark(std::string& targetDirectory, std::string& watermarkPath); }; Why include <...


1

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.


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