中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-11 06:04
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 合并文件夹的疑问? 查看 2,330 回复 21
楼 主 合并文件夹的疑问? 发表于 2008-08-16 00:10 ·  中国 江苏 苏州 电信
初级用户
积分 88
发帖 41
注册 2006-05-13 21:57
20年会员
UID 55479
状态 离线
合并文件夹的疑问?

合并 D盘下 若干文件夹,因为文件夹的名字经常变动,所以感觉无从下手。

不知怎样把这些文件夹合并成一个文件夹。
2 发表于 2008-08-16 00:18 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
@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
)
)
3 发表于 2008-08-16 09:50 ·  中国 江苏 苏州 电信
初级用户
积分 88
发帖 41
注册 2006-05-13 21:57
20年会员
UID 55479
状态 离线
想把1-8(包括其中的子文件夹)的文件夹中的文件(phrases.ini文件除外)都放到到”合并“文件夹。如果在目录中存在同名的文件,则把同名的文件重新命名为原文件名.old

注释:文件夹的名字经常变动,不一定是1-8

phrases.ini

如图:
http://v.iseeclan.com/?i=2008-8/3/8241740/1.JPG



要达到的效果
http://v.iseeclan.com/?i=2008-8/3/8240003/1.JPG

[ Last edited by q1a2z3q1a2z3 on 2008-8-16 at 01:27 PM ]
4 发表于 2008-08-16 11:53 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
贴图的时候,需要把链接放到img标签里面,我先看看效果:




5 发表于 2008-08-16 12:15 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
@echo off
set mypath=E:
if not exist "%mypath%\合并" (
md "%mypath%\合并"
)
for /f "tokens=*" %%a in ('dir /s /b /ad "%mypath%"') do (
if "%%a" neq "%mypath%\合并" (
for /f "tokens=*" %%b in ('dir /s /b /a-d "%%a" 2^>nul') do (
if exist "%mypath%\合并\%%~nxb" (
ren "%mypath%\合并\%%~nxb" "%mypath%\合并\%%~nb.old">nul 2>nul
)
move "%%b" "%mypath%\合并">nul 2>nul
)
)
)
6 发表于 2008-08-16 12:51 ·  中国 江苏 苏州 电信
初级用户
积分 88
发帖 41
注册 2006-05-13 21:57
20年会员
UID 55479
状态 离线
亲爱的HAT!

对于你我已经无话可说了!太感动了。

一而再、再而三的帮助我这样一个批处理的弱者的,-^^-

一个重庆人,毫无利己的动机,把一个陌生人的bat当作他自己的事业,这是什么精神?这是国际主义的精神,这是共产主义的精神,每一个中国人都要学习这种精神。

再次感谢!
7 发表于 2008-08-16 14:54 ·  中国 江苏 苏州 电信
初级用户
积分 88
发帖 41
注册 2006-05-13 21:57
20年会员
UID 55479
状态 离线
同名文件,无法重命名?最后合并的文件夹只能保存一个文件。
8 发表于 2008-08-16 14:59 ·  中国 湖北 武汉 联通
版主
★★★★★
积分 11,386
发帖 4,938
注册 2006-07-23 17:10
20年会员
UID 59080
状态 离线
Originally posted by q1a2z3q1a2z3 at 2008-8-16 12:51:
亲爱的HAT!

对于你我已经无话可说了!太感动了。

一而再、再而三的帮助我这样一个批处理的弱者的,-^^-

一个重庆人,毫无利己的动机,把一 ...

Orz
9 Re 7楼 发表于 2008-08-16 19:13 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
@echo off
set mypath=E:
if not exist "%mypath%\合并" (
md "%mypath%\合并"
)
for /f "tokens=*" %%a in ('dir /s /b /ad "%mypath%"') do (
if "%%a" neq "%mypath%\合并" (
for /f "tokens=*" %%b in ('dir /s /b /a-d "%%a" 2^>nul') do (
if exist "%mypath%\合并\%%~nxb" (
ren "%mypath%\合并\%%~nxb" "%%~nb.old">nul 2>nul
)
move "%%b" "%mypath%\合并">nul 2>nul
)
)
)
10 发表于 2008-08-16 19:17 ·  中国 广东 江门 电信
中级用户
★★
积分 338
发帖 175
注册 2007-10-21 15:30
18年会员
UID 100351
性别 男
状态 离线
建议一下,能否以后在写的时候加上注解呢?
新手很难看地懂...
11 发表于 2008-08-16 19:21 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
哪句不懂问哪句吧,写注释浪费时间。
完全不懂的话,先看看教程。
12 发表于 2008-08-16 19:32 ·  中国 广东 江门 电信
中级用户
★★
积分 338
发帖 175
注册 2007-10-21 15:30
18年会员
UID 100351
性别 男
状态 离线
嗯,这样也行...
13 发表于 2008-08-16 19:33 ·  中国 广东 江门 电信
中级用户
★★
积分 338
发帖 175
注册 2007-10-21 15:30
18年会员
UID 100351
性别 男
状态 离线
%%~nxb

是什么意思?
14 Re 13楼 发表于 2008-08-16 19:54 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
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
15 发表于 2008-08-16 21:12 ·  中国 广东 江门 电信
中级用户
★★
积分 338
发帖 175
注册 2007-10-21 15:30
18年会员
UID 100351
性别 男
状态 离线
哦,原来这样,hat你的机是英文版?不错哦
论坛跳转: