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 06, 2016, 10:11:17 AM
  • 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: seeking something to replace and rename files by drag 'n' drop  (Read 3068 times)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Donate to Member
i'm forever replacing files that are referenced within other programs (eg. swf files referencing jpg's for a gallery slideshow).

for these kinds of things to work i have to maintain the filenames, i.e. the new file and the old file that is replaced have to share the same file name.

i find it an incredibly tedious process having to manually type each file name for each new file.

as the old file that is going to be thrown away has the correct name i'd like an 'automatic' way of taking the old file's name and giving it to the new file's name.

something like a drag and drop process would be great, something like this:

1. i drop the new file with 'randomname.jpg' onto the old file with 'specificname.jpg'

2. the old file is then automatically deleted.

3. the new file has it's name automatically changed to what the old file's name was (so randomname.jpg becomes specificname.jpg).

if there is something out there that does something similar to this then please speak up.

the main point is that i need it to be something simple - i need to pick single files out of a folder that may contain several so the drag 'n' drop process will be the quickest way of doing it. well, anything quicker than typing filenames out by hand would be good.

love you all, nudone.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #1 on: June 27, 2007, 05:16:36 AM »
I think it's not possible to do drag-drop on to the other file, because that is already a behaviour that is specified in windows: it starts that other file, with the dropped file as argument.
But it shouldn't be hard to make a gui, where you'd drop first one file, then the other one, and it'd do what you want.

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #2 on: June 27, 2007, 05:44:15 AM »
yes, i see what you mean, jgpaiva.

a gui would be just right though.

how about something like this...

a small window - two panels - left and right.

left panel - you drop the old file.

right panel - you drop the new file.

after the second drop (i.e. both files have been dropped) the auto process takes place - old file name copied to new file, then old file deleted and new copied to old files location.


extending it further perhaps several files could be dropped at a time on each panel - the files remain in the order they were dropped and when you have an equal number of files in each left and right panel then the auto process takes place - or better, you click a button to start the process. important - if only one file is dropped on each panel then the process happens automatically without having to press a button.

are you going to be my knight in shining armour again, jgpaiva?

ak_

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 223
    • View Profile
    • wopah
    • Read more about this member.
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #3 on: June 27, 2007, 06:11:50 AM »
If by "new file" you mean "file with a more recent modification/creation date", i guess a AHK script could be easily done : you drag and drop the two files on the script GUI and the script takes the oldest file's name, erases it, rename the recent file, and that's it.

Of course if you can't rely on files' dates, it won't work.

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #4 on: June 27, 2007, 06:26:55 AM »
that's a clever idea - it would work most of the time.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #5 on: June 27, 2007, 06:57:12 AM »
Well.. Here you go!

code inside
;
;By jgpaiva
;date: June 2007
;Function:

Gui,  show, x100 y100 w200 h50 , Old File
Gui,2:show, x400 y100 w200 h50 , New File
Gui,  add,text,Vtext1, -No File-
Gui,2:add,text,Vtext2, -No File-
Gui,  +resize
Gui,2:+resize
file1 :=
file2 :=
return

guidropfiles:
  if A_EventInfo <> 1
    return

  file1 := A_GuiEvent
  GuiControl,1:text, text1, %file1%
  GuiControl,1:move, text1, W300
  if file2 =
    return

  msgbox,Now moving

  filerecycle,%file1%
  filemove,%file2%,%file1%,0
  file1 :=
  file2 :=
  GuiControl,1:text, text1, -No File-
  GuiControl,2:text, text2, -No File-
  msgbox,done
return

2guidropfiles:
  if A_EventInfo <> 1
    return

  file2 := A_GuiEvent
  GuiControl,2:text, text2, %file2%
  GuiControl,2:move, text2, W300
  if file1 =
    return

  msgbox,Now moving

  filerecycle,%file1%
  filemove,%file2%,%file1%,0
  file1 :=
  file2 :=
  GuiControl,1:text, text1, -No File-
  GuiControl,2:text, text2, -No File-
  msgbox,Done
  return

GuiClose:
2GuiClose:
  exitapp
  
f2::reload


As usual, just copy to a text file, name it as "whatever.ahk" and run it :)

A few important details:
- There are a few msgboxes that can you probably won't like, because they break the workflow. If so, just delete the lines with "msgbox".
- The order isn't relevant, as long as you drop the files on the correct GUIs.
- If you decide to keep the boxes, you can cancel the move operation by selecting "exit" from the tray menu before pressing ok on the first box.

THIS IS IMPORTANT: if you remove the message boxes, there's no way to cancel the operation. Still, the old file will be moved to the recycle bin.

[edit] Here's the source in a .ahk file:  and the compiled version:  [/edit]
« Last Edit: June 27, 2007, 04:38:09 PM by jgpaiva »

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,117
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #6 on: June 27, 2007, 08:15:09 AM »
fantastic work, jgpaiva.

as i use the revolutionary and always astounding, dialogmove, i don't mind the message boxes appearing  ;) but i may remove them in a minute.

i have named the script "bodysnatcher" as a tribute to the movie "invasion of the bodysnatchers" as this pretty much describes the process that happens to the files.

cody will send you something in a minute.

many many thanks.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: seeking something to replace and rename files by drag 'n' drop
« Reply #7 on: June 27, 2007, 09:00:20 AM »
as i use the revolutionary and always astounding, dialogmove, i don't mind the message boxes appearing  ;) but i may remove them in a minute.
;D ;D

i have named the script "bodysnatcher" as a tribute to the movie "invasion of the bodysnatchers" as this pretty much describes the process that happens to the files.
Now that's a catchy name :P
I love when people come up with names for the programs i make. Finding the right name is half the effort. At least for me ;)

cody will send you something in a minute.
many many thanks.
No... Thank you!!