Main »

Batch Files

Recursive batch file to copy all files with a common extension from ALL subfolders in a directory tree to a network drive

The key to this command is the combination of the FOR command and the /R switch to recurse through all folders to execute the copy command. This single line batch file was invaluable for picking out selected files from an extensive tree structure and backing them up to a single location.

--------------------------------------------
for /R z in (*.jpg) do copy "z" m:
--------------------------------------------

Initial code for command line, modified to a batch file and my specific application, came from the Daily Cup of Tech

  • FOR
  • /R - used with FOR to recurse through the current folder and all subfolders
  • %%z - variable for the filenames found in the folder
  • IN (*.jpg) - the search pattern
  • DO copy "%%z" m: - the dos command to copy each file to a network drive m:
or the command line stated generically: FOR %variable IN (set) DO command [command-parameters]

The difference between using this command in a batch file vs on the command line is the double "%%" in front of the variable names. Command line version requires only 1 "%"

I have learned that my creative condition and my spiritual condition are one and the same. Making art is an act of faith.

Julia Cameron

<< | Trail Index | >> HomeLinks

Index

Home

  Notes
  Investments
  Research
  Teaching 
  ReadingList
  ClassicQuotes
  Computer Applications

About

PmWiki

 PmWikiUserInfo
 Skin Admin  
 Basic Editing
 Documentation Index
 pmwiki.org

Lego

edit SideBar

http://devriesonline.net

Page last modified on July 26, 2007, at 10:09 AM - Powered by PmWiki

^