tsteward Well-Known Member Licensed User Longtime User May 3, 2025 #1 I have downloaded digital files from my opencart server and they all have random extensions. I need to be able to Chooser a directory. Lists all files in that directory. Renames each file by removing anything after .pdf (keeping the .pdf extension only). Can anyone help with this. I had a go and it sounds simple but I failed Hoping someone would be kind enough to knock up a quickie for me PLEASE!
I have downloaded digital files from my opencart server and they all have random extensions. I need to be able to Chooser a directory. Lists all files in that directory. Renames each file by removing anything after .pdf (keeping the .pdf extension only). Can anyone help with this. I had a go and it sounds simple but I failed Hoping someone would be kind enough to knock up a quickie for me PLEASE!
Sandman Expert Licensed User Longtime User May 3, 2025 #2 In case this was a one-off, and you have access to Linux: To delete everything after "pdf" in a file name in Linux, you can use the rename command with a regular expression. For example, the command... Bash: rename 's/(.*\.pdf).*/$1/' *.pdf ...will rename all PDF files by keeping only the part before any additional characters after "pdf". Upvote 0
In case this was a one-off, and you have access to Linux: To delete everything after "pdf" in a file name in Linux, you can use the rename command with a regular expression. For example, the command... Bash: rename 's/(.*\.pdf).*/$1/' *.pdf ...will rename all PDF files by keeping only the part before any additional characters after "pdf".
tsteward Well-Known Member Licensed User Longtime User May 3, 2025 #3 Sandman said: In case this was a one-off, and you have access to Linux: To delete everything after "pdf" in a file name in Linux, you can use the rename command with a regular expression. For example, the command... Bash: rename 's/(.*\.pdf).*/$1/' *.pdf ...will rename all PDF files by keeping only the part before any additional characters after "pdf". Click to expand... That's cool, but in windows? Upvote 0
Sandman said: In case this was a one-off, and you have access to Linux: To delete everything after "pdf" in a file name in Linux, you can use the rename command with a regular expression. For example, the command... Bash: rename 's/(.*\.pdf).*/$1/' *.pdf ...will rename all PDF files by keeping only the part before any additional characters after "pdf". Click to expand... That's cool, but in windows?
Sandman Expert Licensed User Longtime User May 3, 2025 #4 No idea. Perhaps just ask ChatGPT? In Windows, how to delete everything after pdf in file name? Upvote 0
tsteward Well-Known Member Licensed User Longtime User May 3, 2025 #5 powershell Get-ChildItem -File | Where-Object Name -match '\.pdf\.' | ForEach-Object { $newName = ($_.Name -replace '^(.+?\.pdf)\..*$', '$1') Rename-Item $_.FullName -NewName $newname } Click to expand... Upvote 0
powershell Get-ChildItem -File | Where-Object Name -match '\.pdf\.' | ForEach-Object { $newName = ($_.Name -replace '^(.+?\.pdf)\..*$', '$1') Rename-Item $_.FullName -NewName $newname } Click to expand...