2

So if I have C:\drivers\* with * indicating many sub-folders, I want to find out where my inf files are located, and then copy ALL files that are located in the same directory where my inf files are located and all sub-directories.

It has been easy to create a script that will copy all .inf files found to my directory:

FOR /R C:\drivers\ %%a in (*.inf *.cat *.sys) do xcopy /c /h /y %%a C:\test

But copying the other files that are located in the same directory and all sub-directories has been difficult.

Such as, if the inf file is located under C:\drivers\sbdrv\hseries\usb30\amdhub\w7 and the sys file is located in the sub-folder of x86, I need the sys file to be kept in the same sub-folder but under the destination of C:\test\x86.

Any ideas?

EDIT: Maybe this will make it easier. As soon as it finds one .inf file in a folder, it should copy the entire folder over to test as well as all sub-folders and move on to the next one. So if it sees the first .inf file located C:\drivers\sb3045\sb407.inf it should copy all files and folders under sb3045 without copying the folder sb3045 itself, and then move on to folder C:\drivers\sb4055\drivers\oem\intel\id6077.inf and copy all files and folders under the intel folder without copying the intel folder itself.

EDIT2: It looks like this will work, but it is slow as it finds every .inf and is copying over any old files if there is more than one .inf file per folder

@ECHO ON

SETLOCAL ENABLEDELAYEDEXPANSION

CD\

CD drivers

FOR /f "tokens=* delims=" %%B IN ('DIR /b /s /o:gen .inf') DO ( XCOPY "%%~dpB.*" "C:\test\" /e /c /h /y

If anyone has a cleaner or quicker idea, let me know please. Until then, I'll have to work with this one.

2
  • you have problem with files with the same names ? Commented May 15, 2013 at 17:42
  • @npocmaka no, my problem is that after extracting drivers from HP or dell, I need a quick way to update my driver repository from within windows 7 pro or by pointing it to one of my servers. The problem is that I need file structure intact only after it finds where the .inf file is located to do this. I know the above script will not work, and I believe it needs another for loop (if not 2) to do what I am looking for, and was hoping for help from the community on ideas. Commented May 16, 2013 at 11:22

2 Answers 2

0

try this:

 FOR /R C:\drivers\ %%a in (*.inf *.cat *.sys) do xcopy /c /h /y "%%~dpa*" C:\test
Sign up to request clarification or add additional context in comments.

5 Comments

this does work exactly as I asked, but I guess I was still not clear enough to define what I needed. What I still need is if the file was in a sub-folder, then I need the pathing the same as it was compared to the inf file.
And it's caught in an infinite loop on a single folder.
Hmm, I testet for infinite loop now and found not, so please show more from your folder structure.
This is what is looks like just doing a search for .inf .cat & .sys files with my original script output to a text file: [link] (docs.google.com/a/ccsuvt.org/document/d/…).
It got stuck on the second folder directly under C:\drivers and looped with "%%~dpa*" added in. It did go through the first folder perfectly fine however.
0
for /R C:\WINDOWS\inf %%a in (*.inf*) do (
xcopy /qv /T  %%a .\test\
xcopy /qv  %%a .\test\
)
pause

this code worked for me.

1 Comment

Generally avoid code-only answers. Consider adding a description that helps to explain your code. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.