-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script that compares all the files named the same within a given path (…
- Loading branch information
1 parent
4c95675
commit 114de6f
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
README.md | ||
CMakeLists.txt | ||
DectDimensions.xml | ||
materials.xml | ||
#__CLD_ill_named_files__ | ||
additional_materials.xml | ||
BeamInstrumentation_o3_v01_overlap.xml | ||
BeamInstrumentation_o3_v02_fitShield.xml | ||
Beampipe_o4_v03_noNotch_Ta_cone.xml | ||
Beampipe_o4_v04_noNotch_W_n02_smallBP.xml | ||
Beampipe_o4_v04_noNotch_W_n02.xml | ||
Beampipe_o4_v05.xml | ||
ECalBarrel_o2_v01_03.xml | ||
ECalEndcap_o2_v01_03.xml | ||
elements.xml | ||
FCCee_DectDimensions.xml | ||
FCCee_o2_v02.xml | ||
HCalBarrel_o1_v01_01.xml | ||
HCalEndcap_o1_v01_01.xml | ||
HOMAbsorber_v00.xml | ||
InnerTracker_o2_v06_02.xml | ||
LumiCal_o3_v02_02.xml | ||
LumiCal_o3_v02_03.xml | ||
OuterTracker_o2_v06_02.xml | ||
Solenoid_o1_v01_02.xml | ||
Vertex_o4_v05_smallBP.xml | ||
Vertex_o4_v05.xml | ||
YokeBarrel_o1_v01_02.xml | ||
YokeEndcap_o1_v01_02.xml | ||
#__ALLEGRO_ill_named_files__ | ||
ECalBarrel_thetamodulemerged.xml | ||
ECalBarrel_thetamodulemerged_calibration.xml | ||
ECalBarrel_thetamodulemerged_upstream.xml | ||
#__FCCee_ill_named_files__ | ||
FCCee_DectEmptyMaster.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# This script compares all the files named the same within a given path (as argument) | ||
# If files with the same name have different contents, it prints the paths of those files | ||
# If the files are identical, nothing is printed | ||
# Files listed in an ignore file are excluded | ||
|
||
# Usage: ./script.sh <search_dir> <ignore_file> | ||
|
||
search_dir="$1" | ||
ignore_file="$2" | ||
|
||
# Read filenames to ignore from the ignore file | ||
files_to_ignore=$(<"$ignore_file") | ||
|
||
# Create an associative array to store file paths with the same names | ||
declare -A file_names | ||
|
||
# Initialize status code variable | ||
status_code=0 | ||
|
||
# Iterate through files in the directory | ||
while IFS= read -r -d '' file; do | ||
# Get the base name of the file (without the path) | ||
file_name=$(basename "$file") | ||
|
||
# Ignore files listed in the ignore file | ||
if grep -qx "$file_name" <<< "$files_to_ignore"; then | ||
continue | ||
fi | ||
|
||
# Check if there is already a file with the same name | ||
if [[ -n "${file_names[$file_name]}" ]]; then | ||
# Compare the contents of the files | ||
if ! cmp -s "$file" "${file_names[$file_name]}"; then | ||
# Print the paths of the files if they differ | ||
echo "Error. Files with the same name but different contents:" | ||
echo "$file" | ||
echo "${file_names[$file_name]}" | ||
echo | ||
status_code=1 | ||
fi | ||
else | ||
# Store the file path in the array | ||
file_names["$file_name"]="$file" | ||
fi | ||
done < <(find "$search_dir" -not -path '*/.*' -type f -print0) | ||
|
||
exit $status_code |