3

I wonder if I could help to do the following:

Search the PC (all units) all autocad files (* .DWG) and word (* .doc) and copy them to a new route from my server; the first time it is run must be a FULL and then just changed the date of FULL files are copied.

I have tried to use the following:

mkdir \\server1\j$\bk_user\%computername%\FULL\%date:~6,4%-%date:~3,2%-%date:~0,2%\a_ofim\

FORFILES /P C:\ /S /M *.doc* /C "cmd /c COPY @file \\server1\j$\bk_user\%computername%\FULL\%date:~6,4%-%date:~3,2%-%date:~0,2%\a_ofima\"

FORFILES /P C:\ /S /M *.dwg /C "cmd /c COPY @file \\server1\j$\bk_user\%computername%\FULL\%date:~6,4%-%date:~3,2%-%date:~0,2%\a_ofim\"

The point is that I do not know how to:

  1. Search all hard drives, my current code only searches drive C: (I was thinking of placing a line with "if exist D: \ goto diskD" and so for each disc, but I'm not sure if there is another more efficiently

  2. That every time you find and copy the file, copy it maintaining its original folder structure, because then no one knows where it came from that file because the places all together.

I hope you can help me ..

3 Answers3

1

The best way I have found to transfer that kind of data while maintaining the folder structure is through Robocopy.

With Robocopy you can also use multi threading support to help speed up your transfers.

EXAMPLE: Robocopy C:\ *.dwg \\myserver\backup\users_C_Drive /MT:4

That will keep the folder structure. You can get fancy later and add in custom excludes for temp files and folders to be skipped.

0

How do I search all hard drives?

To enumerate all your local drives, use the following batch file (GetDrives.cmd):

@echo off
setlocal enabledelayedexpansion
for /f "skip=1" %%d in ('wmic logicaldisk get caption ^| findstr /r /v "^$"') do (
  set _drive=%%d
  echo !_drive!
  rem add search code here
  )
endlocal

Example output:

> GetDrives.cmd
C:
add search code here
D:
add search code here
E:
add search code here
F:
add search code here

To skip DVD/CD drives, use the following batch file (GetDrives.cmd):

@echo off
setlocal enabledelayedexpansion
for /f "skip=1 tokens=1,2" %%d in ('wmic logicaldisk get caption^, drivetype  ^| findstr /r /v "^$"') do (
  if not [%%e]==[5] (
    set _drive=%%d
    echo !_drive!
    echo add search code here
    )
  )
endlocal

Example output (Drive d: is my DVD drive):

> GetDrives.cmd
C:
add search code here
E:
add search code here
F:
add search code here

>

Further Reading

DavidPostill
  • 162,382
0

If you want to create an exact duplicate, use the following version (which is equivalent to adding /E and /PURGE:

robocopy c:\test d:\test /MIR

If all you want to do is copy the directories and subdirectories including empty ones, use

robocopy c:\test d:\test /E

It is the backslash on the E option that was getting you.

To learn more about Robocopy here is a handy search:

http://www.google.com?q=robocopy+syntax

From my post at Robocopy - Copy directory into another directory

SDsolar
  • 1,696