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-08-11 07:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Questions about merging folders? View 2,340 Replies 21
Original Poster Posted 2008-08-16 00:10 ·  中国 江苏 苏州 电信
初级用户
Credits 88
Posts 41
Joined 2006-05-13 21:57
20-year member
UID 55479
Status Offline
Questions about merging folders?

I need to merge several folders under drive D, but the folder names change frequently, so I feel at a loss.

I don't know how to merge these folders into one folder.
Floor 2 Posted 2008-08-16 00:18 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
@echo off
set mypath=C:\test
if not exist "%mypath%\dstfolder" (
md "%mypath%\dstfolder"
)
for /f "tokens=*" %%a in ('dir /s /b /ad "%mypath%"') do (
if "%%a" neq "%mypath%\dstfolder" (
move /y %%a "%mypath%\dstfolder">nul 2>nul
)
)
```
Floor 3 Posted 2008-08-16 09:50 ·  中国 江苏 苏州 电信
初级用户
Credits 88
Posts 41
Joined 2006-05-13 21:57
20-year member
UID 55479
Status Offline
I want to move all files (except the phrases.ini file) in the folders from 1 to 8 (including their subfolders) to the "Merge" folder. If there are files with the same name in the directory, rename the same - named files to the original file name.old.

Note: The names of the folders often change, not necessarily 1 - 8.

phrases.ini

As shown in the figure:
http://v.iseeclan.com/?i=2008-8/3/8241740/1.JPG

The desired effect:
http://v.iseeclan.com/?i=2008-8/3/8240003/1.JPG

[ Last edited by q1a2z3q1a2z3 on 2008-8-16 at 01:27 PM ]
Floor 4 Posted 2008-08-16 11:53 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
When posting pictures, you need to put the link inside the img tag. Let me first check the effect:




Floor 5 Posted 2008-08-16 12:15 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```batch
@echo off
set mypath=E:
if not exist "%mypath%\Merge" (
md "%mypath%\Merge"
)
for /f "tokens=*" %%a in ('dir /s /b /ad "%mypath%"') do (
if "%%a" neq "%mypath%\Merge" (
for /f "tokens=*" %%b in ('dir /s /b /a-d "%%a" 2^>nul') do (
if exist "%mypath%\Merge\%%~nxb" (
ren "%mypath%\Merge\%%~nxb" "%mypath%\Merge\%%~nb.old">nul 2>nul
)
move "%%b" "%mypath%\Merge">nul 2>nul
)
)
)
```
Floor 6 Posted 2008-08-16 12:51 ·  中国 江苏 苏州 电信
初级用户
Credits 88
Posts 41
Joined 2006-05-13 21:57
20-year member
UID 55479
Status Offline
Dear HAT!

I have nothing more to say to you! So touched.

Helping a batch processing weakling like me again and again, -^^-

A native of Chongqing, with no self-interested motives, treating a stranger's bat as his own cause, what kind of spirit is this? This is the spirit of internationalism, this is the spirit of communism, and every Chinese should learn this spirit.

Thanks again!
Floor 7 Posted 2008-08-16 14:54 ·  中国 江苏 苏州 电信
初级用户
Credits 88
Posts 41
Joined 2006-05-13 21:57
20-year member
UID 55479
Status Offline
Same-named files, unable to rename? The final merged folder can only save one file.
Floor 8 Posted 2008-08-16 14:59 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by q1a2z3q1a2z3 at 2008-8-16 12:51:
Dear HAT!

There's nothing more I can say to you! So moved.

Helping me, a batch processing weakling, again and again, -^^-

A person from Chongqing, with no self-interested motives, to ...

Orz
Floor 9 Posted 2008-08-16 19:13 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
@echo off
set mypath=E:
if not exist "%mypath%\Merge" (
md "%mypath%\Merge"
)
for /f "tokens=*" %%a in ('dir /s /b /ad "%mypath%"') do (
if "%%a" neq "%mypath%\Merge" (
for /f "tokens=*" %%b in ('dir /s /b /a-d "%%a" 2^>nul') do (
if exist "%mypath%\Merge\%%~nxb" (
ren "%mypath%\Merge\%%~nxb" "%%~nb.old">nul 2>nul
)
move "%%b" "%mypath%\Merge">nul 2>nul
)
)
)
```
Floor 10 Posted 2008-08-16 19:17 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Suggestions, can you add annotations when writing in the future? Novices find it very hard to understand...
Floor 11 Posted 2008-08-16 19:21 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Just ask any question you don't understand, writing comments is a waste of time. If you don't understand at all, first look at the tutorial.
Floor 12 Posted 2008-08-16 19:32 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Floor 13 Posted 2008-08-16 19:33 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
What does "%%~nxb" mean?
Floor 14 Posted 2008-08-16 19:54 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
for /?
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
Floor 15 Posted 2008-08-16 21:12 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Oh, so that's how it is. Is your computer in English version? Not bad oh
Forum Jump: