GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Websafe renaming


#1

(See also: Various simple rename presets -> Make Safe Name)

Hi,

i am a webdeveloper and get often files from my clients to link on websites. The filename has often special characters , which are not websafe like: äöüßáàâ...

The following button uses a vbscript to convert the selected filenames to a websafe format (a-z0-9-_). I hope, you like it.

<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Secure Rename</label>
	<tip>Websafe rename of selected files</tip>
	<icon1>#format</icon1>
	<function type="normal">
		<instruction>@nodeselect </instruction>
		<instruction>RENAME TO &quot;*&quot; </instruction>
		<instruction />
		<instruction>@script vbscript </instruction>
		<instruction>Option Explicit </instruction>
		<instruction />
		<instruction>Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, strNewName) </instruction>
		<instruction />
		<instruction>Dim strAllowed</instruction>
		<instruction>Dim tmpFile</instruction>
		<instruction>Dim iLen</instruction>
		<instruction>Dim i</instruction>
		<instruction>Dim strChar</instruction>
		<instruction />
		<instruction>strAllowed = &quot;abcdefghijklmnopqrstuvwxyz0123456789.&quot;</instruction>
		<instruction>strNewName = Trim(LCase(strNewName))</instruction>
		<instruction />
		<instruction>strNewName = Replace(strNewName, &quot;ä&quot;, &quot;ae&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;á&quot;, &quot;a&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;à&quot;, &quot;a&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;â&quot;, &quot;a&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;é&quot;, &quot;e&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;è&quot;, &quot;e&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ê&quot;, &quot;e&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ö&quot;, &quot;oe&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ó&quot;, &quot;o&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ò&quot;, &quot;o&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ô&quot;, &quot;o&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;í&quot;, &quot;i&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ì&quot;, &quot;i&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;î&quot;, &quot;i&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ü&quot;, &quot;ue&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ú&quot;, &quot;u&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ù&quot;, &quot;u&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;û&quot;, &quot;u&quot;)</instruction>
		<instruction>strNewName = Replace(strNewName, &quot;ß&quot;, &quot;ss&quot;)</instruction>
		<instruction />
		<instruction />
		<instruction>iLen = len(strNewName)</instruction>
		<instruction />
		<instruction>for i = 1 to iLen</instruction>
		<instruction>    strChar = mid(strNewName, i, 1)</instruction>
		<instruction>    if instr(strAllowed, strChar) &gt; 0 then </instruction>
		<instruction>        tmpFile = tmpFile &amp; strChar          </instruction>
		<instruction>    elseif right(tmpFile, 1) &lt;&gt; &quot;_&quot; then</instruction>
		<instruction>        tmpFile = tmpFile &amp; &quot;_&quot;</instruction>
		<instruction>    end if</instruction>
		<instruction>next</instruction>
		<instruction />
		<instruction>if left(tmpFile, 1) = &quot;_&quot; then</instruction>
		<instruction>    tmpFile = right(tmpFile, len(tmpFile) - 1)</instruction>
		<instruction>end if</instruction>
		<instruction />
		<instruction>strNewName = Replace(tmpFile, &quot;_.&quot;, &quot;.&quot;)</instruction>
		<instruction>End Function</instruction>
	</function>
</button>

Feel free to change the script for your purpose.

Bertram Simon

agentur-simon.de


HELP: delete asian (unicode) characters from file or folder
Web rename script? (percent url ascii encoding)
#2

Hi Bertram, thank you for this useful button!

I have changed it for me to include also ",-()" (of course without quotes) into strAllowed since all web-servers support this whithout using URL-encoding. What do you think?


#3

Hi Peter,

I use this script for web- and cd-rom-safe renaming. if you use it only for web renaming, you can enhance it with more characters. feel free to post your version!

Greetings from germany

Bertram


#4

With the help of Jonathan Potter of Directory Opus support, who I want to thank for his help, I have a combination of websafe and titlecase renaming.
See attached file.

Leo Lesage
Websafe and titlecase.zip (2.55 KB)


#5

Allow me to pick up in this to discuss underscore -vs- hyphen.

Should this script transpose to hyphen only, for websafe file names if used on websites, for SEO-reasons? Because - as I understand it - underscore renders one word while hyphen renders a word separation.

See Google Webmaster Resources: https://support.google.com/webmasters/answer/76329?hl=en