Das DOS to the rescue

Lets say you’ve got a folder with a bunch of files and subfolders…each subfolder in turn contains a bunch more files of which you are only interested in one with a specific name. You could perform a search in the root folder and quickly find all the files with that name. Copying them from that search window is easy enough, but lets say you want to keep the folder structure in tact. Lets say you want the same bunch of folders and subfolders, but only containing the specific files you’re looking for. If you’re running Windows, Robocopy will be your friend.
[problem]
you have the following (a structure of folders, subfolders and files. You want to copy the folder structure, but just along with one specific file that may or may not be within each of the folders/subfolders):

root
 subfolder1
  index.html
  navigation.inc
  about.html
  history.html
  contact.html
 subfolder2
  index.html
  navigation.inc
  quotes.html
  menu.html
  directions.html
main.html
overview.html
navigation.inc
...

you want this (the same folder structure as above, but just the navigation.inc file in each folder/subfolder if it exists):

root
 subfolder1
  navigation.inc
 subfolder2
  navigation.inc
navigation.inc

[step 1] Open a command prompt.

[step 2] Use the Robocopy command as follows (command reference – check it):

C:>Robocopy C:root *navigation* C:destination /E

The /E will create subdirectories even if they don’t contain a targeted file and as shown, filenames can be targeted using a wildcard mask.

Boom, Done!

Oh, and to recursively rename all these files in all these subfolders…DOS comes to the rescue again

for /r %x in (*.inc) do ren “%x” *.html


Posted

in

by