Closed zdavatz closed 1 year ago
updated version, do not forget to do Set-ExecutionPolicy RemoteSigned
$directory = 'S:\GDT-E-PAT-Vitabyte'
$originalFileName = 'epat.gdt'
# Check if the file exists in the directory
$files = Get-ChildItem -Path $directory -Filter $originalFileName
if ($files.Count -gt 0) {
$timestamp = Get-Date -Format 'yyyyMMddHHmmss'
$counter = 1
foreach ($file in $files) {
$extension = $file.Extension
$newName = "$timestamp" + "_epat_$counter" + $extension
$newPath = Join-Path -Path $directory -ChildPath $newName
Rename-Item -Path $file.FullName -NewName $newPath
$counter++
}
Write-Host "Files renamed successfully."
} else {
Write-Host "No files named '$originalFileName' found in the directory."
}
$gdtDirectory = 'S:\GDT-E-PAT-Vitabyte'
$outputDirectory = 'C:\Users\medi-lan\gdt2dicom\dicom\medilan_MWL'
$gdt2dicomExe = 'C:\Users\medi-lan\gdt2dicom\gdt2dicom.exe'
# Create the output directory if it doesn't exist
if (-not (Test-Path -Path $outputDirectory)) {
New-Item -ItemType Directory -Path $outputDirectory | Out-Null
}
# Get all GDT files in the input directory
$gdtFiles = Get-ChildItem -Path $gdtDirectory -Filter '*.gdt'
foreach ($gdtFile in $gdtFiles) {
$outputFile = Join-Path -Path $outputDirectory -ChildPath ($gdtFile.Name -replace '\.gdt$', '.wl')
& $gdt2dicomExe --gdt-file $gdtFile.FullName --output $outputFile
}
Get-ChildItem -Path $outputDirectory -Filter "*.wl" | ForEach-Object {
& "dcmodify" -i "(0040,0100)[0].(0008,0060)=ECG" "$($_.FullName)"
& "dcmodify" -i "0032,1060=holter" "$($_.FullName)"
}
# Get all .gdt files in the specified directory
$files = Get-ChildItem -Path $directory -Filter *.gdt
# Remove each file
foreach ($file in $files) {
Remove-Item $file.FullName -Force
}
Write-Host "All .gdt files in $directory have been removed."
# Get all .bak files in the specified directory
$files = Get-ChildItem -Path $outputDirectory -Filter *.bak
# Remove each file
foreach ($file in $files) {
Remove-Item $file.FullName -Force
}
Write-Host "All .bak files in $outputDirectory have been removed.
Bash version:
#!/bin/bash
# Directory paths
directory="/mnt/S/GDT-E-PAT-Vitabyte"
gdtDirectory="/mnt/S/GDT-E-PAT-Vitabyte"
outputDirectory="/home/medi-lan/gdt2dicom/dicom/medilan_MWL"
gdt2dicomExe="/home/medi-lan/gdt2dicom/gdt2dicom"
# Original filename
originalFileName="epat.gdt"
# Check if the file exists in the directory
files=("$directory/$originalFileName")
if [ -e "${files[0]}" ]; then
timestamp=$(date +"%Y%m%d%H%M%S")
counter=1
for file in "${files[@]}"; do
extension="${file##*.}"
newName="${timestamp}_epat_${counter}.${extension}"
newPath="$directory/$newName"
mv "$file" "$newPath"
((counter++))
done
echo "Files renamed successfully."
else
echo "No files named '$originalFileName' found in the directory."
fi
# Create the output directory if it doesn't exist
if [ ! -d "$outputDirectory" ]; then
mkdir -p "$outputDirectory"
fi
# Get all GDT files in the input directory
gdtFiles=("$gdtDirectory"/*.gdt)
for gdtFile in "${gdtFiles[@]}"; do
outputFile="$outputDirectory/$(basename "${gdtFile%.*}.wl")"
"$gdt2dicomExe" --gdt-file "$gdtFile" --output "$outputFile"
done
# Modify the created .wl files
for file in "$outputDirectory"/*.wl; do
dcmodify -i "(0040,0100)[0].(0008,0060)=ECG" "$file"
dcmodify -i "0032,1060=holter" "$file"
done