Computer Hope
Microsoft => Microsoft DOS => Topic started by: johngotts on March 18, 2010, 07:04:47 PM
-
When using xcopy, how specific can you be with wildcards when trying to specify which directories to search in? If I have a directory containing subdirectories named "reports 2010, reports 2009, etc" and I want to search those for files to be copied, can I specify \reports*\ for example?
-
Good question.
Have you searched in this forum database? There are some 100 topics just about what you can do with XCOPY.
Here is just one of many that may provide the answer.
http://www.computerhope.com/forum/index.php?topic=76290.0
If you don't see anything close to what you want, come back here and get some more help.
-
Well, I searched as much as possible, it's kinda like looking for navy blue socks in the black sock drawer.
Anyhow, here's the scenario.
Folder 1 contains report folders by date (010208 Reports thru 013108 Reports) as an example.
010208 Reports contains folders from the particular town where the reports were generated (town1 thru x)
the town folders contains the actual (*.doc) reports to be copied.
I was trying to specify:
xcopy "c:\documents and settings\folder1\*reports\town1\*.doc" \newfolder /e/s/t such that all existing report folders are searched for town1 folders and the *.doc files from each town folder are copied to a new folder.
It doesn't seem to like the syntax /*reports/ and indicates no files can be found.
-
I suggest a test, one line at a time, until DIR finds something.
dir "c:\documents and settings\folder1\*reports\town1\*.doc"
dir "c:\documents and settings\folder1\*reports\town1"
dir "c:\documents and settings\folder1\*reports"
dir "c:\documents and settings\folder1"
dir "c:\documents and settings"
I think XCOPY should be able to copy anything that DIR can see.
If DIR cannot see anything with
"c:\documents and settings\folder1\*reports"
but can see
"c:\documents and settings\folder1"
then perhaps there is no match for the folder "*reports"
and you must alter your search parameter to fit reality
Alan
-
Xcopy is one of the more complex utilities and the results can be quite unpredictable.
xcopy "c:\documents and settings\folder1\*.doc" \newFolder /S /E /L
This should hunt down all .doc files in the c:\documents and settings\folder1 directory tree and list them.
Note: I used the /L switch as a whatif condition. This will give you a chance to see what will actually get copied. When you are satisified with the result, remove the /L switch. I also used the /S switch to check the subfolders and the /E switch for the empty folders. You may or may not need them. Check xcopy /? for all the gory details on the switches (there is a whole alphabet soup of them)
Good luck. 8)
-
Well, it appears there's a conflict when using searches that are non specific for the directories. If I specify a specific "report" directory to search in, ie. "0102 reports", I can copy all day long. Once I try to make it a search that is non-specific like "* reports", it won't search for the docs. I guess I'm busted here.
-
You are probably doing it wrong.
What SPECIFIC folder are you interested in ?
"Report 2010" as in your for post, or
"2010 Reports" as in your latest post
Does the folder name actually have exactly one embedded space ?
I suggest you CD to the parent folder and issue the commands
CLS
DIR "c:\documents and settings\folder1\* Reports"
If that finds the folder of interest, then try
xcopy "c:\documents and settings\folder1\* Reports\*.doc" \newFolder /S /E /L
If you still have problems, I suggest a screen dump of the CMD.EXE display,
showing both of the commands and the responses to the commands.
To get a screen dump, right click on the CMD screen and "Select All",
which changes the display to Black text on White Background,
then Left Click and the display is restored to White on Black,
and the contents are in your paste buffer.
Then reply, and click the "Insert Code" button (Looks like a '#') and paste.
That will ensure we can clearly see if there is a problem with too many spaces.
Note, "*xyz" can include "* xyz", but not the other way round
e.g.
C:\Documents and Settings\Dad>dir "\*ro* File*"
Volume in drive C is ACER
Volume Serial Number is EC16-8702
Directory of C:\
15/03/2010 17:17 <DIR> Program Files
0 File(s) 0 bytes
1 Dir(s) 9,291,087,872 bytes free
C:\Documents and Settings\Dad>dir "\*ro*File*"
Volume in drive C is ACER
Volume Serial Number is EC16-8702
Directory of C:\
15/03/2010 17:17 <DIR> Program Files
0 File(s) 0 bytes
1 Dir(s) 9,291,087,872 bytes free
C:\Documents and Settings\Dad>
Alan
-
Good info, guys!
But is there any way to make XCOPY allow wildcards for directories?
Obviously, the following command does not work:
C:\>xcopy folder* D:\I_WANT_THEM_HERE\
0 File(s) copied
In this scenario, I have a bounce of folders (folder1 folder2 folder3 folder_abc ...) and want all of them go be copied.
Tried reading the documentation ("/?") but no syntax option seems to point me in the right direction.
I could (of course) use a FOR loop, but isn't there any way using just the XCOPY.EXE ... ?
-
Unfortunately in DOS the shell itself does not expand wildcards, it just passes them to the command. This means if you want to do anything fancy with a wildcard you need to explicitly expand it with for..in.
https://www.computerhope.com/forhlp.htm#xp
Take note of the /R option which recursively walks a directory structure.
The following SO thread has an example of using for..in with xcopy:
https://stackoverflow.com/a/35753046 (https://stackoverflow.com/a/35753046)
In your case (slightly different than this example) you might want to use /R, if you want the variable in your xcopy command to contain only a directory name, not a path to a specific file.
Edit: CMD.EXE does parse wildcards, but does so differently for batch files and the command line -
https://stackoverflow.com/a/4095133