中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-11-24 05:33
47,820 topics / 349,938 posts / today 0 new / 48,298 members
DOS批处理 & 脚本技术(批处理室) » 【Solved】Copy only the folder without including its contents
Printable Version  4,379 / 19
Floor16 balinger Posted 2009-04-07 02:30
中级用户 Posts 115 Credits 356
Reply to HAT moderator.

XCOPY is specifically for copying files with directory structures. If the user's system has XCOPY, and considering the level of the code in building post 9, they should directly use XCOPY.

Actually, one is dissatisfaction with the user's way of asking questions, especially the sentence "In fact, I just posted in other forums before!", which seems to imply that this forum must compete with other forums. Second, I want to remind the user that XCOPY pointed out by yishanju in post 5 is actually the best.

Based on my understanding of this forum, I believe many people are clear that although the code in post 9 is competent, for the user's problem, it is overcomplicating a simple issue.
Floor17 26933062 Posted 2009-04-07 05:01
银牌会员 Posts 879 Credits 2,268
Regarding the code on floor 9, I think the suggestion from floor 13 is very good, but I really don't know how to achieve it directly with xcopy. The owner's requirement is to keep all directories and subdirectories in the current directory of the batch and the jpg and gif files.

Please kindly give advice on how to use xcopy to copy only files with specified extensions.

I once tried to use xcopy /t /e to build the directory tree, but found that when the target directory is also in the current directory of the batch, an error "Periodic copy cannot be executed" is prompted.

Brother zpz0012005 once gave a code of xcopy, but when the "target directory" is in "the specific path of a certain folder", an error "Periodic copy cannot be executed" is prompted


[ Last edited by 26933062 on 2009-4-7 at 05:32 ]
Floor18 balinger Posted 2009-04-07 11:33
中级用户 Posts 115 Credits 356
@echo off
set src=Source directory path
set dst=Target directory
for %%a in (jpg gif) do xcopy /s/e/c "%src%\*.%%a" "%dst%\"

My understanding is that if this batch file is not in the source directory, the generated target directory will be in the same directory as the batch file. Otherwise, there is no need to specify the specific path of the source directory, just use. instead of %src%.

If this batch file is in the source directory, it will prompt the error "Periodic copy cannot be executed". Because the source directory being copied contains the target directory. In fact, it can be changed. Move the target directory to the parent directory, side by side with the source directory:
@echo off
set dst=Target directory name
for %%a in (jpg gif) do xcopy /s/e/c ".\*.%%a" "..\%dst%\"

Similarly, if the batch file is not in the source directory and you want the generated target directory to be with the source directory:
@echo off
set src=Source directory path
set dst=Target directory
for %%a in (jpg gif) do xcopy /s/e/c "%src%\*.%%a" "%src%\..\%dst%\"

Of course, if the source directory is the root directory, using.. will not work. In fact, the code on floor 9 is not suitable for execution in the root directory now, but he can modify it and add a \.

It must be that the generated target directory is under the source directory, the code on floor 9 can, but xcopy cannot. But I think it is not necessary. Copying itself is from one place to another, without changing the object being copied. The fact that xcopy does not allow the target directory to be in the source directory is not without reason.

The landlord did not require the target directory to be under the source directory, nor did he require the batch file to be in the source directory, and the object being copied is not the root directory. In my humble opinion, just two xcopy are enough, and use for when there are more file types.

xcopy /s/e/c "c:\123\*.jpg" "d:\456\"
xcopy /s/e/c "c:\123\*.gif" "d:\456\"
Floor19 ligui0001 Posted 2009-04-09 04:13
初级用户 Posts 41 Credits 58
Floor20 a22124497 Posted 2009-04-10 00:10
新手上路 Posts 10 Credits 14
Just use the DIR to get the file folder, and then create the file, isn't that enough?
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023