DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: DONE: One Click File Extension Changer  (Read 9,673 times)

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 24
DONE: One Click File Extension Changer
« on: September 12, 2016, 11:23 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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: One Click File Extension Changer
« Reply #1 on: September 13, 2016, 04:33 AM »
Here's one way to do it via AutoHotkey.  It should be pretty easy to follow so modify it as necessary.

Code: ( autohotkey)
^`::
{
    ; Get the highlighted selection onto the clipboard and crack its path.
    Send, ^c
    myFile := Clipboard
    SplitPath, myFile, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
    
    ; Determine current and new extensions.
    If ( OutExtension = "epub" )
    {
        myExtension := "zip"
    }
    Else If ( OutExtension = "zip" )
    {
        myExtension := "epub"
    }

    ; Check that the destination file doesn't already exist.
    If ! FileExist( OutDir . "\" . OutNameNoExt . "." . myExtension )
    {
        ; Destination file does not exist so rename existing file with new extension.
        FileMove, % myFile, % OutDir . "\" . OutNameNoExt . "." . myExtension
    }
    Else
    {
        ; Destination file exists.  Warn user and do nothing.
        MsgBox, Destination file already exists.  Aborting...
    }
}
Return
« Last Edit: September 14, 2016, 01:47 AM by skwire »

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 24
Re: DONE: One Click File Extension Changer
« Reply #2 on: September 14, 2016, 12:05 AM »
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

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: One Click File Extension Changer
« Reply #3 on: September 14, 2016, 01:48 AM »
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: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: DONE: One Click File Extension Changer
« Reply #4 on: September 14, 2016, 06:19 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?
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

pulphero

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 24
Re: DONE: One Click File Extension Changer
« Reply #5 on: September 14, 2016, 12:02 PM »
Sorry for not seeing that myself. It works like a charm. Much appreciated!

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: One Click File Extension Changer
« Reply #6 on: September 14, 2016, 11:55 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.

Original address: https://www.donationcoder.com/forum/index.php?topic=43008.0