windowsshellforeachcommand-linecommand-line-interface

How do I copy a specific file to have it replace all files of only a specific file type in all subfolders of a directory that match a wildcard in PATH


So, I'm currently working on a mod for a game, and I might end up having to do this for other mods in the future, so I'd like to know if there is a way to do it with the FOR/DO command in Windows' Command Prompt. As it stands, I'm trying to modify a map to make it not show any details. The map is split up into small squares in a grid pattern, named "map tiles". One of these map tiles is for a part of the map the player can't access. Kind of akin to empty space, I suppose. This design is nice, and I have to replace the files with something. I'll include a PNG conversion [from DDS] of said tile below.

map_tile_z

I will visualize the folder & file structure below. Hopefully it helps. Either way, what I'm trying to do is this: Have a command go through each folder ("MENU_MapTile_*-tpf-dcx") and copy "map_tile_z.dds" into that folder, having its copy adopt the name of the DDS file currently residing in said folder, overwriting the file that currently resides there. The DDS file currently residing in its respective directory always has the exact same name as the folder, but it ends with its file extension (".dds") and it drops its parent directory's suffix "-tpf-dcx".

There are 28,439 of these folders and 28,439 DDS files, one file in each folder, so it's my hope that I can automate this process somehow; possibly with the FOR/DO command Windows Command Prompt has. I'm not quite sure if there is a better command to use or a more practical way to go about this, so if you have any alternative suggestions for methods on how to accomplish this, I'm all ears. I'm new to using this command-line utility, so please bear with me and my basic questions.

• 71_maptile.tpfbdt

• maptile_file // Folder, containing "map_tile_z.dds", that which I want to replace all other map tiles with //

• map_tile_z.dds --// File inside of the folder "maptile_file" //

• 71_maptile-tpfbdt ----// Folder, created from decompiling "71_maptile.tpfbdt" //

• MENU_MapTile_M00_L0_00_00_00000000.tpf.dcx

• MENU_MapTile_M00_L0_00_00_00000000-tpf-dcx --// Folder, created from decompiling "MENU_MapTile_M00_L0_00_00_00004000.tpf.dcx" //

         • MENU_MapTile_M00_L0_00_00_00000000.dds --// File inside of the folder "MENU_MapTile_M00_L0_00_00_00004000-tpf-dcx" //

• MENU_MapTile_M00_L0_00_00_00004000.tpf.dcx

• MENU_MapTile_M00_L0_00_00_00004000-tpf-dcx --// Folder, created from decompiling "MENU_MapTile_M00_L0_00_00_00004000.tpf.dcx" //

         • MENU_MapTile_M00_L0_00_00_0000000.dds --// File inside of the folder "MENU_MapTile_M00_L0_00_00_00004000-tpf-dcx" //

etc...

If there is anymore information I can provide that would be relevant to my question, please don't hesitate to mention it. Thank you in advance, for taking the time to read and help.


Solution

  • It honestly got pretty late last night, so I ended up doing it a less efficient way. I did the following to accomplish my goal:

      1. In the root directory, I ran dir /s /b /o:n | findstr /vi ".xml" > dir.txt
    
      2. I then opened this up in Notepad++ and removed the first set of entries, the folders ("MENU_MapTile*-tpf-dcx"). This left me with a list of all of the .DDS files, separated by line breaks, with the absolute path to each of them preceding them in the line
    
      (e.g. "D:\Path\To\root\MENU_MapTile_M00_L0_00_00_00000000-tpf-
      dcx\MENU_MapTile_M00_L0_00_00_00000000.dds")
    
      3. I opened Find (`Ctrl+F'), went to the Replace tab and
          • for "Find what:" I input D:'
          • for "Replace with:" I input 'copy /Y "D:\Path\To\maptile_z\maptile_z.dds" "D:'
    
      4. I then changed the extension to make the `.txt` file a `.bat` file and ran it, which copied `maptile_z.dds` into each of the directories, renaming it to the name of the `.DDS` file that already resided in the each folder, overwriting them with `maptile_z.dds`.
    

    Thankfully, this did the trick and I'm satisfied with this particular solution to the problem I was facing.