China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-21 09:04
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【Solved】Copy only the folder without including its contents View 3,053 Replies 19
Floor 16 Posted 2009-04-07 02:30 ·  中国 福建 福州 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
21-year member
UID 29114
Gender Male
Status Offline
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.
Floor 17 Posted 2009-04-07 05:01 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
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

@echo off
set src=The specific path of a certain folder
set dst=Target directory
for %%a in (jpg gif) do xcopy /s/e/c "%src%\*.%%a" "%dst%\"


[ Last edited by 26933062 on 2009-4-7 at 05:32 ]
致精致简!
Floor 18 Posted 2009-04-07 11:33 ·  中国 福建 福州 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
21-year member
UID 29114
Gender Male
Status Offline
@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\"
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
26933062 +5 2009-04-07 11:48
Floor 19 Posted 2009-04-09 04:13 ·  中国 江西 南昌 电信
初级用户
Credits 58
Posts 41
Joined 2009-04-03 00:04
17-year member
UID 141951
Gender Male
Status Offline
Floor 20 Posted 2009-04-10 00:10 ·  中国 江苏 南京 电信
新手上路
Credits 14
Posts 10
Joined 2009-03-20 01:38
17-year member
UID 141797
Gender Male
Status Offline
Just use the DIR to get the file folder, and then create the file, isn't that enough?
Forum Jump: