Windows 10 batch file using wildcard in folder names RRS feed

  • Question

  • copy "e:\net_copy3\abook.mab" "e:\rthomeserver\caspi_slave_sf_?\"

    I regularly need to copy a file like "abook.mab" to multiple folders with names like "caspi_slave_sf_1" "caspi_slave_sf_2", etc.

     but not sure how to use a wildcard in a folder name for a windows batch file.

    Thanks to the experts


    Tuesday, September 27, 2016 6:11 PM


  • Easier in PowerShell. PowerShell v2 example:

    $sourceFilename = "C:\Temp\net_copy3\abook.mab"
    $targetDirectory = "C:\Temp\rthomeserver\caspi_slave_*"
    Get-ChildItem $targetDirectory | Where-Object { $_.PSIsContainer } | ForEach-Object {
      Copy-Item $sourceFilename $_ -WhatIf

    Of course, remove -WhatIf to actually do the copying.

    If you have PowerShell newer than version 2, you can remove the Where-Object part and add the -Directory parameter to Get-ChildItem instead.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, September 27, 2016 6:34 PM