Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 01:59:41 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: One Click File Extension Changer  (Read 751 times)

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
DONE: One Click File Extension Changer
« on: September 12, 2016, 06:23:55 PM »
In my work, I often change file extensions from one to the other, and then back again, and then back again, and so on.

I'd love to have a little AHK script that would do this:

If I select a file with an .epub extension in Explorer and press Ctrl+`, the file extension will change to .zip.

If I select a file with a .zip extension in Explorer and press Ctrl+`, the file extension will change to .epub.

I put in epub/zip and the hotkey Ctrl+` as examples. I figure a user would be able to adjust those things as needed.

Thanks!

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #1 on: September 12, 2016, 11:33:44 PM »
Here's one way to do it via AutoHotkey.  It should be pretty easy to follow so modify it as necessary.

Code: Autohotkey [Select]
  1. ^`::
  2. {
  3.     ; Get the highlighted selection onto the clipboard and crack its path.
  4.     Send, ^c
  5.     myFile := Clipboard
  6.     SplitPath, myFile, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  7.    
  8.     ; Determine current and new extensions.
  9.     If ( OutExtension = "epub" )
  10.     {
  11.         myExtension := "zip"
  12.     }
  13.     Else If ( OutExtension = "zip" )
  14.     {
  15.         myExtension := "epub"
  16.     }
  17.  
  18.     ; Check that the destination file doesn't already exist.
  19.     If ! FileExist( OutDir . "\" . OutNameNoExt . "." . myExtension )
  20.     {
  21.         ; Destination file does not exist so rename existing file with new extension.
  22.         FileMove, % myFile, % OutDir . "\" . OutNameNoExt . "." . myExtension
  23.     }
  24.     Else
  25.     {
  26.         ; Destination file exists.  Warn user and do nothing.
  27.         MsgBox, Destination file already exists.  Aborting...
  28.     }
  29. }
  30. Return
« Last Edit: September 13, 2016, 08:47:29 PM by skwire »

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #2 on: September 13, 2016, 07:05:38 PM »
Thanks, but no joy. I saved the code as "ExtSwitch.ahk", double-clicked that file, selected an .epub file, and pressed Ctrl + ` (the hotkey). Nothing happened; no error message, either.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #3 on: September 13, 2016, 08:48:38 PM »
Thanks, but no joy. I saved the code as "ExtSwitch.ahk", double-clicked that file, selected an .epub file, and pressed Ctrl + ` (the hotkey). Nothing happened; no error message, either.

I think I looked at your hotkey wrong and substituted an apostrophe for the backtick you had.  Please recopy the code above and try it again.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,783
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #4 on: September 14, 2016, 01:19:26 AM »
Just tried it and it seems to work just fine.
It might take your Explorer a few seconds to refresh the list of files though, maybe a Ctrl-R/F5 press (refresh) might fix that?

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #5 on: September 14, 2016, 07:02:59 AM »
Sorry for not seeing that myself. It works like a charm. Much appreciated!

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,668
    • View Profile
    • Donate to Member
Re: DONE: One Click File Extension Changer
« Reply #6 on: September 14, 2016, 06:55:56 PM »
Sorry for not seeing that myself. It works like a charm. Much appreciated!

Good to hear.  I'll move this to the Finished section.