![]() |
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: 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. |
|
| 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 |