中国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-08-11 07:04
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Questions about merging folders?
Printable Version  2,334 / 21
Floor1 q1a2z3q1a2z3 Posted 2008-08-16 00:10
初级用户 Posts 41 Credits 88
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.
Floor2 HAT Posted 2008-08-16 00:18
版主 Posts 5,017 Credits 9,023
```
@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
)
)
```
Floor3 q1a2z3q1a2z3 Posted 2008-08-16 09:50
初级用户 Posts 41 Credits 88
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 ]
Floor4 HAT Posted 2008-08-16 11:53
版主 Posts 5,017 Credits 9,023
When posting pictures, you need to put the link inside the img tag. Let me first check the effect:




Floor5 HAT Posted 2008-08-16 12:15
版主 Posts 5,017 Credits 9,023
```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
)
)
)
```
Floor6 q1a2z3q1a2z3 Posted 2008-08-16 12:51
初级用户 Posts 41 Credits 88
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!
Floor7 q1a2z3q1a2z3 Posted 2008-08-16 14:54
初级用户 Posts 41 Credits 88
Same-named files, unable to rename? The final merged folder can only save one file.
Floor8 lxmxn Posted 2008-08-16 14:59
版主 Posts 4,938 Credits 11,386
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
Floor9 HAT Posted 2008-08-16 19:13
版主 Posts 5,017 Credits 9,023
```
@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
)
)
)
```
Floor10 BC Posted 2008-08-16 19:17
中级用户 Posts 175 Credits 338
Suggestions, can you add annotations when writing in the future? Novices find it very hard to understand...
Floor11 HAT Posted 2008-08-16 19:21
版主 Posts 5,017 Credits 9,023
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.
Floor12 BC Posted 2008-08-16 19:32
中级用户 Posts 175 Credits 338
Floor13 BC Posted 2008-08-16 19:33
中级用户 Posts 175 Credits 338
What does "%%~nxb" mean?
Floor14 HAT Posted 2008-08-16 19:54
版主 Posts 5,017 Credits 9,023
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
Floor15 BC Posted 2008-08-16 21:12
中级用户 Posts 175 Credits 338
Oh, so that's how it is. Is your computer in English version? Not bad oh
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023