Remove file type in name?

I recently realized that my databases are full of files with the type appended: .txt, .pdf, etc., etc.

I understand that I can turn off the file type as part of the initial import process, but is there a way to remove the file type designation from all my files in a database, except one at a time?


Preferences > Import - Titles; check the option “Filename without extension”.

As a practical matter, it doesn’t make any difference, as DEVONthink will remember the file type whether it’s displayed as a suffix in the Name, or not. So a document exported to the Finder will display the correct suffix, whether or not it was displayed in the document Name. And in a Name search, you can make the query string any part of the Name, excluding the suffix if you wish.

I’ve got the Preferences set not to display the file type suffix. But I’ve got a column in my view window (Three Panes) that displays the Kind. Note: You can add desired columns using View > Columns > and choose (adding one at a time) additional columns, perhaps Size, Word Count or Comments. I often find that useful – each column can be used to sort the documents. So if I sort by Kind, image-only PDFs are listed as PDF and searchable PDFs are listed as PDF+Text; in DT Pro Office, that lets me identify PDFs than I may wish to concert to searchable PDFs by running OCR (Data > Convert > to searchable PDF). Note: There’s a script in DEVONacademy script examples that will perform the conversion to searchable PDF without changing the group location of the original – handy if you have “pulled together” a selection list of documents from different groups.

There’s a script (DEVONacademy Web pages) to add the correct suffix to Names. I didn’t see a script to remove suffixs, but I suppose that could be done.

Here’s one.

The variable “ext_list” contains a list of suffixes/extensions to remove. My list is {".txt", “.rtfd”, “.rtf”, “.pdf”, “.webarchive”, “.html”, “.png”, “.jpg”, “.gif”}; adjust to suit. Select one or more documents and run the script. Any titles ending with one of these extensions will have the extension removed.

Example: “foo bar.txt” --> “foo bar”.

NB: The script doesn’t actually verify that the string being removed is at the end of the title (but it works for me :slight_smile: )

-- Remove any of the extensions in 'ext_list' from all selected document titles.

-- This script is based on:
--     Replace Text in Names
--     Created by Christian Grunenberg Sat May 15 2004.
--     Copyright (c) 2004-2008. All rights reserved.
--     Based on (c) 2001 Apple, Inc.

set ext_list to {".txt", ".rtfd", ".rtf", ".pdf", ".webarchive", ".html", ".png", ".jpg", ".gif"}

set replacement_string to ""
tell application "DEVONthink Pro"
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."
		repeat with search_string in ext_list
			set od to AppleScript's text item delimiters
			repeat with this_item in this_selection
				set current_name to name of this_item
				if current_name contains search_string then
					set AppleScript's text item delimiters to search_string
					set text_item_list to every text item of current_name
					set AppleScript's text item delimiters to replacement_string
					set new_item_name to text_item_list as string
					set the name of this_item to new_item_name
				end if
			end repeat
			set AppleScript's text item delimiters to od
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Works a charm, Dave. Thanks for this.

Just wanted to chime in and say that this little script still worked great for me. I forgot to turn off the preference to use the file extension when importing files, and wound up with thousands of names with .pdf and .html in them. I grabbed this script, selected everything in my database, ran it, and it removed the extension from all my files.