标题: 合并文件夹的疑问?
[打印本页]
作者: q1a2z3q1a2z3
时间: 2008-8-16 00:10
标题: 合并文件夹的疑问?
合并文件夹的疑问?
合并 D盘下 若干文件夹,因为文件夹的名字经常变动,所以感觉无从下手。
不知怎样把这些文件夹合并成一个文件夹。
作者: HAT
时间: 2008-8-16 00:18
@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
)
)
作者: q1a2z3q1a2z3
时间: 2008-8-16 09:50
想把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 ]
作者: HAT
时间: 2008-8-16 11:53
贴图的时候,需要把链接放到img标签里面,我先看看效果:

作者: HAT
时间: 2008-8-16 12:15
@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
)
)
)
作者: q1a2z3q1a2z3
时间: 2008-8-16 12:51
亲爱的HAT!
对于你我已经无话可说了!太感动了。
一而再、再而三的帮助我这样一个批处理的弱者的,-^^-
一个重庆人,毫无利己的动机,把一个陌生人的bat当作他自己的事业,这是什么精神?这是国际主义的精神,这是共产主义的精神,每一个中国人都要学习这种精神。
再次感谢!
作者: q1a2z3q1a2z3
时间: 2008-8-16 14:54
同名文件,无法重命名?最后合并的文件夹只能保存一个文件。
作者: lxmxn
时间: 2008-8-16 14:59
Quote: |
Originally posted by q1a2z3q1a2z3 at 2008-8-16 12:51:
亲爱的HAT!
对于你我已经无话可说了!太感动了。
一而再、再而三的帮助我这样一个批处理的弱者的,-^^-
一个重庆人,毫无利己的动机,把一 ... |
|
Orz
作者: HAT
时间: 2008-8-16 19:13
标题: Re 7楼
@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
)
)
)
作者: BC
时间: 2008-8-16 19:17
建议一下,能否以后在写的时候加上注解呢?
新手很难看地懂...
作者: HAT
时间: 2008-8-16 19:21
哪句不懂问哪句吧,写注释浪费时间。
完全不懂的话,先看看教程。
作者: BC
时间: 2008-8-16 19:32
嗯,这样也行...
作者: BC
时间: 2008-8-16 19:33
%%~nxb
是什么意思?
作者: HAT
时间: 2008-8-16 19:54
标题: Re 13楼
for /?
Quote: |
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 |
|
作者: BC
时间: 2008-8-16 21:12
哦,原来这样,hat你的机是英文版?不错哦
作者: q1a2z3q1a2z3
时间: 2008-8-18 00:04
如果文件名相同,更改文件名后,希望达到这样的效果。(需要改名的文件不只是word一种,这里只是举个例子。)
按照您的代码运行后是这样的结果(两个都是word文件)
[
Last edited by q1a2z3q1a2z3 on 2008-8-18 at 12:11 AM ]
作者: HAT
时间: 2008-8-18 09:46
标题: Re 16楼
@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%%~xb">nul 2>nul
)
move "%%b" "%mypath%\合并">nul 2>nul
)
)
)
作者: q1a2z3q1a2z3
时间: 2008-8-18 11:52
如果有三个文件重名,合并后只能保存两个文件。
如果是多个多个同名文件希望合并后能这样。
1.doc 1.old.doc 1.old.old.doc ................
作者: HAT
时间: 2008-8-18 11:57
Windows系统支持的最长路径是225吧,如果你有几十个重复的文件,就会超过这个阀值,这个方案在理论上不具备可行性,想其它方法吧。
作者: q1a2z3q1a2z3
时间: 2008-8-18 12:16
如果支持更改5个同名文件,应该不会超过系统限制?具体如何修改?
[
Last edited by q1a2z3q1a2z3 on 2008-8-18 at 01:04 PM ]
作者: 753tgb159asx
时间: 2009-2-4 09:59
我想保留原文件,并将合并后的文件改到别的盘,如何写啊。哪句话是删除原文件的意思。
作者: zhengqian529
时间: 2009-2-4 11:13
将HAT的代码执行完以后,使用XCOPY指令,移动到你想移动的盘符
删除原文件可以使用:del 指令
关于xcopy和del的用法,看del /?, xcopy /?