Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently need to swap one file with another, without overwriting the original.

Let's say there are two files, foo_new.dll and foo.dll. I usually rename them the follwing way:

  1. foo.dll -> foo_old.dll,
  2. foo_new.dll -> foo.dll,
  3. [do something with replaced file],
  4. foo.dll -> foo_new.dll,
  5. foo_old.dll -> foo.dll.

This is ok for a single file to swap but it becomes tedious when swapping multiple files at once.

Is there a Windows (7 and preferrably XP) utility or a technique that simplifies this task and works well when swapping multiple files?

I'd prefer to be able to use it from within FreeCommander but Windows Explorer would be ok, too.

share|improve this question

If you change your file name convention, then you can easily manage swapping multiple files via RENAME with wildcards.

Instead of calling your files foo_new.dll, call them After the initial swap, the original foo.dll will be called foo.dll.old.

Then you can use:

rem First swap in the new files

  rem The following command appends .old to all files with .dll extension (foo.dll -> foo.dll.old)
  ren *.dll *?.old

  rem The following command removes all .new extensions ( -> foo.dll)
  ren *.new *.

rem Now you can work with the new replacements

rem Finally swap out the new files and restore the old ones

  rem Add .new to the dll files (foo.dll ->
  ren *.dll *?.new

  rem Remove .old extensions (foo.dll.old -> foo.dll)
  ren *.old *.

See How does the Windows RENAME command interpret wildcards? for a complete explanation of how RENAME handles wildcards.

One limitation of the above is it assumes you have a replacement for every .dll file in your directory.

A simple extension using the FOR command can be used to swap a subset of the .dll files (only those for which * is defined). It is probably easiest to put the commands in a pair of batch scripts.

Use the following swapInNew.bat batch file to swap in the new files:

@echo off
for %%F in (*.new) do (
  move "%%~nF" "~nF.old"
  move "%%F" "%%~nF"

Now you can work with the replacement files as needed

Finally, Use the following restoreOld.bat batch file to restore the old files:

@echo off
for %%F in (*.old) do (
  move "%%~nF" ""
  move "%%F" "%%~nF"
share|improve this answer

For (1)

>for /f "delims=" %f in ('dir *.cmd /a-d /on /b') do @ren %f %~nf_old%~xf

For (2)

>for /f "delims=" %f in ('dir *_new.cmd /a-d /on /b') do @(@set nf=%~nf & @ren %f %nf:~0,-5%%~xf)

For (3)

rem Anything You Can Do!

For (4)

>for /f "delims=" %f in ('dir *.cmd /a-d /on /b') do @ren %f %~nf_new%~xf

For (5)

>for /f "delims=" %f in ('dir *_old.cmd /a-d /on /b') do @(@set nf=%~nf & @ren %f %nf:~0,-5%%~xf)

Wish there is specific need to design specific script. Any idea for improvement are welcome. :)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .