Since my FileSync Project is still a long way to being where I want it to be and is in a state that makes it annoying to use, I decided to throw together a script that essentially emulates the primary functions of it for what I need. I find it a bit annoying that I’ve never been able to find another good project that does exactly what I want for quick syncing of files over networks :-\. I used to think rsync would be a good solution for it but it’s very... quirky and unstable in certain ways. Not as flexible as I would like. Alas.
Anywho, this PHP script takes 2 file lists and gives you back their differences in a directory tree view. Each file has a data string after it used to tell if the files are different. The data string can be anything you want, but will usually probably be a timestamp or data checksum. The tree view lets you hide files/directories depending on whether each item is only on one side, different, or the same. An example is as follows (List1, List2):
Dir1.txt files | Data String (Timestamps) |
Same.txt | 9999-99-99 99:99:99 |
Diff.txt | 9999-99-99 99:99:99 |
LeftOnly.txt | 9999-99-99 99:99:99 |
PartialDir/Same.txt | 9999-99-99 99:99:99 |
PartialDir/Diff.txt | 9999-99-99 99:99:99 |
PartialDir/LeftOnly.txt | 9999-99-99 99:99:99 |
SameDir/Same.txt | 9999-99-99 99:99:99 |
LeftOnlyDir/Left.txt | 9999-99-99 99:99:99 |
LeftOnlyDir/Left2.txt | 9999-99-99 99:99:99 |
DiffDir/Diff.txt | 9999-99-99 99:99:99 |
|
Dir2.txt files | Data String (Timestamps) |
Same.txt | 9999-99-99 99:99:99 |
Diff.txt | 1111-11-11 11:11:11 |
RightOnly.txt | 9999-99-99 99:99:99 |
PartialDir/Same.txt | 9999-99-99 99:99:99 |
PartialDir/Diff.txt | 1111-11-11 11:11:11 |
PartialDir/RightOnly.txt | 9999-99-99 99:99:99 |
SameDir/Same.txt | 9999-99-99 99:99:99 |
RightOnlyDir/Right.txt | 9999-99-99 99:99:99 |
| |
DiffDir/Diff.txt | 1111-11-11 11:11:11 |
|
Example Output:
Legend:
- Differences:
- No differences detected
- File is different, or directory contains differences
- File is only found on left side, when this happens to a directory, it is only counted as 1 difference
- File is only found on right side, when this happens to a directory, it is only counted as 1 difference
- Type:
- This is a directory with sub items. After the directory name, it lists as info the number of differences over the total number of sub items
- This is a file. If both sides contain the file but are different, it lists as info the different strings
- Info about the file/directory listed in between parenthesis.
Left Side: ./Dir1.txt
Right Side: ./Dir2.txt
Total Differences: 9
Total Items: 13
- DiffDir (1/1)
- Diff.txt (9999-99-99 99:99:99 :: 1111-11-11 11:11:11)
- LeftOnlyDir (1/2)
- PartialDir (3/4)
- Diff.txt (9999-99-99 99:99:99 :: 1111-11-11 11:11:11)
- LeftOnly.txt
- RightOnly.txt
- Same.txt
- RightOnlyDir (1/1)
- SameDir (0/1)
- Diff.txt (9999-99-99 99:99:99 :: 1111-11-11 11:11:11)
- LeftOnly.txt
- RightOnly.txt
- Same.txt
Some example bash commands used to create file lists:
- Output all files and their timestamps to “Dir1.txt”: find -type f -printf '%P\t%T+\n' > Dir1.txt
- Output all files and their md5sums to “Dir1.txt”: find -type f -print0 | xargs -0 md5sum | perl -pe 's/^(.*?) (.*)$/$2\t$1/g' > Dir1.txt