none
Using cmd: Copying a file into all file folders in a drive RRS feed

  • Question

  • Hi,

    Using cmd, I need to copy an excel template into all folders (and not their subfolders) within one drive. Have managed to copy to specific folders by specifying their names but need to do it to approx. 500 folders, would be great not to have to type 500 names ... Could someone help me with the syntax please?

    Many Thanks

    Wednesday, July 1, 2015 3:17 PM

Answers

  • if the directory names have spaces in them then you'll need to set your delimiter to nothing and use quotes or it will mess up.  Here's an example without creating the interim cmd file

    for /f "delims=" %a in ('dir /b /ad') do copy "drive:\path\to\ExcelFile.xlsx" "%a"


    Wednesday, July 1, 2015 5:42 PM

All replies

  • Hi, 

    try this:

    for /f %d in ('dir /a:d /b') do @echo copy myExcelFile.xlsx %d >> CopyAll.cmd

    Obviously you need to replcace myExcelFile.xlsx with the actual name of your file.

    At the end you'll have a batch file (CopyAll.cmd) where each line copies the file to a folder.

    If you omit "@echo" and ">> CopyAll.cmd" the command will execute immediately but you lose a bit of control and also CopyAll.cmd can be edited before running it.


    This post is provided AS IS with no warranties or guarantees, and confers no rights.
    ~~~
    Questo post non fornisce garanzie e non conferisce diritti

    • Proposed as answer by jholden90 Wednesday, July 1, 2015 4:18 PM
    Wednesday, July 1, 2015 3:24 PM
  • Will copy the file to all folders in current folder.

    dir |?{$_.PsIsContainer} | %{Copy-Item c:\template.xltx $_}


    \_(ツ)_/

    Wednesday, July 1, 2015 3:45 PM
  • if the directory names have spaces in them then you'll need to set your delimiter to nothing and use quotes or it will mess up.  Here's an example without creating the interim cmd file

    for /f "delims=" %a in ('dir /b /ad') do copy "drive:\path\to\ExcelFile.xlsx" "%a"


    Wednesday, July 1, 2015 5:42 PM