I'm trying to copy开发者_如何转开发 the contents of multiple folders within the same directory into one new file. All the files I want to copy have the extension .sql
.
When I try this - with one directory - it works:
directory>copy *.sql copy.sql
but when I try
directory>copy */*.sql copy.sql
I get
The syntax of the command is incorrect.
What am I doing wrong? I think I'm following the directions on this site correctly, but am I?
I'm not sure if this makes a difference, but I'm using Windows 7.
TIA!
What you are trying to do works on Unix (bash/sh), but unfortunately doesn't work on Windows CMD.
In Windows CMD do something like this:
del result.sql && FOR /F %G IN ('"dir *.sql /s /b"') DO type %G >> result.sql
It will delete result.sql
, and for each file named *.sql in current and subdirectories (dir *.sql /s /b
) append the content to result.sql (type filename >> result.sql
).
There is also a FORFILES command, but unsure what version of Windows it was introduced in.
del result.sql && FORFILES /S /M *.sql /C "cmd /c type @path" > result.sql
(Note the && is just a way of adding multiple commands per line and can be replaced with standard newline (\r\n).)
I don't think this would work. Standard Windows command shells won't do wildcard matching on path components, just the final part of the path argument. As well, you've got a forward slash in there, which is used for command arguments
C:\> dir win*
Volume in drive C is BSOD
Volume Serial Number is 4AFF-AE03
Directory of C:\
03/01/2011 07:58 AM <DIR> Windows
0 File(s) 0 bytes
1 Dir(s) 393,128,820,736 bytes free
as expected, but doing
C:\> dir win*\sys*
The filename, directory name, or volume label syntax is incorrect.
and
C:\> dir windows\sys*
Volume in drive C is BSOD
Volume Serial Number is 4AFF-AE03
Directory of C:\windows
13/07/2009 08:36 PM <DIR> system
10/06/2009 03:08 PM 219 system.ini
10/02/2011 07:55 AM <DIR> System32
09/02/2011 04:33 PM <DIR> SysWOW64
1 File(s) 219 bytes
3 Dir(s) 393,128,816,640 bytes free
well I'm assuming all your sql files are text files so could you do something like
type *.sql >> copy.sql
精彩评论