Update Multiple Files on a Windows Machine

I recently needed to update all SWF files on a website I was working on with a newer version. However, these files were in multiple folders and there were hundreds of them, therefore it was out of the question that I do this update manually. However, no matter how much I searched, I just couldn’t find the utility to do this. There seem to be thousands of search and replace tools out there but the vast majority are for searching for strings in text files.

Who other than…

Well I didn’t think it would come to this, but the people who came to my help were… Microsoft!
I managed to find some documentation for a command line replace tool on the microsoft resources site.

The syntax for this tool is quite simple:

replace [drive1:][path1] FileName [drive2:][path2] [/p] [/r] [/s] [/w] [/u]

Lets break that down:

  • replace is the initial command
  • drive1 specifies the drive containing the new file (such as C:)
  • path1 refers to a location such as \Program Files
  • Filename refers to the name of the file to be replaced
  • drive2 and path2 are like drive1 and path1 but point to the directory containing the files to be replaced

Samples

So how is this used then?
Imagine that we want to replace all instances of flash_index.swf in P:\public\ with the latest version, C:\update\flash_index.swf

The syntax would be:

replace C:\update\flash_index.swf P:\public\

Lets not forget that you can also add the /s flag at the end. This searches all subdirectories so would also update the relevant files in P:\public\site1\ and so on.

The syntax would be:

replace C:\update\flash_index.swf P:\public\ /s

There are a few other ways that replace can be used. These are documented on the Microsoft Site. This tool is great if you are running your website on Windows Servers and need to make global updates quickly and easily. Do make sure you test it first before doing anything drastic. Of course, you would be silly to be running your site on a Windows Server in the first place but that is besides the point!

Hope this helped somebody out there then!

Leave a Reply