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 07:33
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 【Solved】Copy only the folder without including its contents View 3,047 Replies 19
Original Poster Posted 2009-04-05 04:00 ·  中国 广西 百色 平果市 电信
初级用户
Credits 49
Posts 37
Joined 2007-05-08 09:38
19-year member
UID 87820
Gender Male
Status Offline
Little brother wants to copy all folders and subfolders under a certain folder, but not copy the files inside the folders (except for jpg and gif image formats). How to write this? Thank you!
If there are no jpg or gif files in a certain folder? Then do we still need to copy that folder? Yes.

[ Last edited by ganjie on 2009-4-6 at 01:21 ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
HAT -8 2009-04-06 01:58
ZJHJ -4 2009-04-06 07:15
dosihz -1 2009-04-06 07:31
yishanju +8 2009-04-06 09:06
Floor 2 Posted 2009-04-05 08:58 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
19-year member
UID 59720
Status Offline
Floor 3 Posted 2009-04-05 11:03 ·  中国 湖北 荆州 洪湖市 电信
初级用户
★★
Credits 161
Posts 114
Joined 2009-02-20 13:00
17-year member
UID 139375
Gender Male
Status Offline
That makes sense. Why didn't I think of that... First copy all the files and folders. Then delete the files that are not JPG or GIF.

The original poster said: "Don't just give me a Chinese explanation, and don't just give me a short piece of code and let me figure it out by myself. If that's the case, replies are declined"... I'm wondering if I should reply to you. But having a Chinese explanation is better than nothing, right?
Floor 4 Posted 2009-04-05 11:56 ·  中国 四川 成都 电信
新手上路
Credits 9
Posts 7
Joined 2006-06-22 23:07
19-year member
UID 57425
Status Offline
robocopy Log log2 /mir /zb /xf *.*

Just copy using robocopy while ignoring all files
Floor 5 Posted 2009-04-05 11:59 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
C:\Documents and Settings\Administrator>xcopy /?
Copies files and directory trees.

XCOPY source ] ]


...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
but doesn't change the attribute.
/M Copies only files with the archive attribute set,
and clears the archive attribute.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose source
time is newer than the destination time.
/EXCLUDE:file1...
Specifies a list of files containing strings. Each string
must be in a separate line in the file. If any string matches
the full path of the file to be copied, that file will not be copied.
For example, specifying a string like \obj\ or .obj will exclude
all files under directory obj or files with the .obj extension.
/P Prompts for creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories including empty ones.
Same as /S /E. Can be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination is a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files to be copied.
/G Allows copying unencrypted files to destinations that do not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure but does not copy files.
Does not include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy resets read-only attributes.
/N Copies using generated short names.
/O Copies file ownership and ACL information.
/X Copies file auditing settings (implies /O).
/Y Copies file auditing settings (implies /O).
Existing destination files.
/-Y Causes prompting to confirm rewriting an
existing destination file.
/Z Copies network files in restartable mode.

The command-line switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 6 Posted 2009-04-05 11:59 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Try XCOPY /T to create directory structure

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 7 Posted 2009-04-05 14:49 ·  中国 湖北 荆州 洪湖市 电信
初级用户
★★
Credits 161
Posts 114
Joined 2009-02-20 13:00
17-year member
UID 139375
Gender Male
Status Offline
People have all said: no Chinese explanations, and no trying to figure it out by himself. Brother yishanju, just post a complete code segment.
Floor 8 Posted 2009-04-05 23:04 ·  中国 广西 百色 电信
初级用户
Credits 49
Posts 37
Joined 2007-05-08 09:38
19-year member
UID 87820
Gender Male
Status Offline
It's not that I don't want to find a way, but that I'm already trying to find a way. Because the source file is very large, there are hundreds of gigabytes of files. The picture files alone that need to be copied might exceed a gigabyte. Copying all and then deleting, this kind of reply is obviously irresponsible without considering the poster's mood. But I'm grateful for everyone's enthusiastic replies. Thanks! I've already made three batch files by myself, and then used call to call them to achieve the goal. Thanks again!

[ Last edited by ganjie on 2009-4-5 at 23:34 ]
Floor 9 Posted 2009-04-06 08:45 ·  中国 广西 百色 电信
初级用户
Credits 49
Posts 37
Joined 2007-05-08 09:38
19-year member
UID 87820
Gender Male
Status Offline
The complete code of this post is as follows, and it has been tested!
@echo off
::The target folder name is temp
set wjj=temp
::Copy folders and subfolders
for /f "delims=" %%a in ('dir/b/s/ad') do (
if not exist "%wjj%\" md "%wjj%"
set "var=%%a"
setlocal enabledelayedexpansion
set var=!var:*%cd%=!
md "%wjj%!var!"
endlocal
)
::Copy jpg and gif files
for /f "delims=" %%a in ('dir/b/s/a-d *.jpg *.gif') do (
set "var=%%a"
setlocal enabledelayedexpansion
set var=!var:*%cd%=!
copy /y "%%a" "%wjj%!var!"
endlocal
)
pause

Thanks to Suifeng from the batch processing forum.
Floor 10 Posted 2009-04-06 09:33 ·  中国 上海 浦东新区 电信
中级用户
★★
一看二跟三动手
Credits 396
Posts 188
Joined 2005-10-23 13:21
20-year member
UID 43919
From 上海
Status Offline
1, Create the same folder.
2, Copy the image file.
Reasonable.
*/. . . * .
.\* . * dosz
*/ . ./\~~~~~~~~~~~~'\. ^|◆
\* ,/,..,\,...........,\.◆
^|^| ..▎# ▎田 田 ▎ ^| ▎◆
^|^| ^&^&▎ ▎ ▎'^|'▎ o
^|^| ##■■■■■■■■■■〓
Floor 11 Posted 2009-04-06 09:43 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
21-year member
UID 29114
Gender Male
Status Offline
Hey, it's a pity that the original poster's system doesn't have XCOPY!
Floor 12 Posted 2009-04-06 10:22 ·  中国 上海 浦东新区 电信
中级用户
★★
一看二跟三动手
Credits 396
Posts 188
Joined 2005-10-23 13:21
20-year member
UID 43919
From 上海
Status Offline
Originally posted by balinger at 2009-4-6 09:43:
Hey, it's a pity that there's no XCOPY in the owner's system!

If that's the case, then it's the "copy first and then delete" in the "2nd floor"
*/. . . * .
.\* . * dosz
*/ . ./\~~~~~~~~~~~~'\. ^|◆
\* ,/,..,\,...........,\.◆
^|^| ..▎# ▎田 田 ▎ ^| ▎◆
^|^| ^&^&▎ ▎ ▎'^|'▎ o
^|^| ##■■■■■■■■■■〓
Floor 13 Posted 2009-04-06 11:47 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
The code on the 9th floor, after md, you can immediately copy *.jpg... &copy *.gif... and omit the subsequent for. It should be more efficient.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
26933062 +5 2009-04-06 13:31
精简
=> 个人网志
Floor 14 Posted 2009-04-06 13:03 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
It's not that I don't want to find a way, but that I'm already trying to find a way. Because the source file is very large, there are hundreds of gigabytes of files. The image files alone may exceed a gigabyte. Copying all and then deleting, and then posting back, is obviously an irresponsible reply without considering the mood of the person who posted it.

Why didn't you state at the top that the source file is very large? Isn't this a waste of other people's time? You always feel that others' replies are irresponsible, why don't you think about whether your own way of asking questions is responsible? Have you considered the mood of the person who is helping you solve the problem?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
netbenton +2 2009-04-06 13:08
Floor 15 Posted 2009-04-06 13:04 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Originally posted by balinger at 2009-4-6 09:43 AM:
Hey, it's a pity that the owner's system doesn't have XCOPY!

What did you conclude that the owner's system doesn't have XCOPY from?
Forum Jump: