topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Tuesday March 19, 2024, 5:36 am
  • Proudly celebrating 15+ 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: Coding Snack: Switch Filenames  (Read 18103 times)

Coeluh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 273
  • Family Guy ^^
    • View Profile
    • Jeroen Coelen
    • Donate to Member
Coding Snack: Switch Filenames
« on: June 06, 2009, 06:11 AM »
Let's say, i've got 2 files: filea.jpg and fileb.jpg

But I want filea.jpg to be fileb.jpg and fileb.jpg to be filea.jpg. Normally the filenames I want to switch are longer, so it takes longer to switch them, because I have to copy/paste twice and stuff. I want a simple tool where I can drop 2 items and they will switch filenames.

Thanks a lot in advance! :)
« Last Edit: June 29, 2009, 08:56 AM by mouser »

NoWhereMan

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 23
    • View Profile
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #1 on: June 06, 2009, 07:02 AM »
Here is a quick batch file which does what you are asking for

@echo off

if %1.==. goto USAGE
if %1.==. goto USAGE


if not exist %1 goto NOTEXISTS
if not exist %2 goto NOTEXISTS

REM move first to temp name
set tempfile=%1.%RANDOM%

move %1 %tempfile% > NUL
move %2 %1 > NUL
move %tempfile% %2 > NUL

goto EXIT

:USAGE
echo USAGE: swap file1 file2
goto EXIT

:NOTEXISTS
echo ERROR: Can't find the file(s) you specified

:EXIT
echo.


Obviously since it's a batch file it would flash in a command prompt window, but you can hide it by creating a shortcut and setting the program status to minimized. You can then drop either the shortcut or the batch file to your sendto folder, at your convenience :)

Just copy/paste the code to a text file (notepad) and save it as swap.bat or swap.cmd and you're set

bye

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #2 on: June 06, 2009, 06:43 PM »
Give Switcheroo a try and see if it's what you had in mind.

2009-06-07_114401.png

Download: http://skwire.dcmemb...heroo/Switcheroo.zip
« Last Edit: July 07, 2009, 06:18 AM by skwire »

Coeluh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 273
  • Family Guy ^^
    • View Profile
    • Jeroen Coelen
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #3 on: June 07, 2009, 03:27 AM »
Give Switcheroo a try and see if it's what you had in mind.
 (see attachment in previous post) (see attachment in previous post)
Download: http://skwire.dcmemb...heroo/Switcheroo.zip
Switcheroo is cool. But: Maybe the files are not in the same folder, and not by that not selectable at the same time. One by one dropping would be cool.

It does the same job as the batch file, but the interface is nice. :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #4 on: June 07, 2009, 08:29 AM »
Maybe the files are not in the same folder, and not by that not selectable at the same time. One by one dropping would be cool.

Try build 6.  You now have two drop methods available:
  • You can drag-n-drop one file on to each of the edit fields
  • You can drag-n-drop two files anywhere on the form.

Download: http://skwire.dcmemb...heroo/Switcheroo.zip
« Last Edit: June 07, 2009, 08:40 AM by skwire »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,896
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #5 on: June 07, 2009, 09:01 AM »
Skwire is on fire lately!!

Coeluh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 273
  • Family Guy ^^
    • View Profile
    • Jeroen Coelen
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #6 on: June 07, 2009, 11:01 AM »
Skwire is on fire lately!!
He shoud change is name to skfire ;)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: IDEA: Switch Filenames
« Reply #7 on: June 07, 2009, 11:51 AM »
Code doesn't write itself, eh?   :D  Thanks for your kind compliments.  As I've mentioned before, I really enjoy making quick apps such as this one.

TaoPhoenix

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 4,642
    • View Profile
    • Donate to Member
Re: Coding Snack: Switch Filenames
« Reply #8 on: December 24, 2011, 01:51 AM »

(Someone tell me if they hate thread bumps!)

I just stumbled onto this, and found a great use case for it.

(Gangster's voice)
So ya' got's this file, see? And it's called Project Update December 2011 with annotations.pdf, which is a scan file. But then you add something else, and scan it again. I don't throw out partial work, I save it as drafts. But now it's no longer good! So I'm stuck scanning the new copy. But computers won't let you copy a new file with the same filename!
(End Gangster)

So this is neat so that when you rescan it, and it comes out Scan265432, you Switcheroo it, your fresh new scan gets the right file name, then you can rename the junk one Project-Junk etc.