中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-06-29 07:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 怎样自动删除空文件夹 查看 2,974 回复 14
楼 主 怎样自动删除空文件夹 发表于 2008-05-15 09:11 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
请教一下大家:
我想设置一下批处理每天自动删除空文件夹,因为我做的自动备份程序会复制空文件夹.
2 发表于 2008-05-15 10:04 ·  中国 上海 联通
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
你的自动备份程序用的哪个命令?看看那个命令是否自带了跳过空文件夹的开关。
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
wxs81514 +2 2008-05-15 10:34
3 发表于 2008-05-15 10:34 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
批处理是这样写的:
robocopy D:\ \\zhixinserver\%computername%\Other_new_files\Disk_D *.doc *.xls *.ppt *.dwg *.cdr *.pdf /s /xa:h /maxage:30 /mir
我只要最近30天更新过的文件,超过这个日期的文件自动删除,加了/mir就出现了空文件夹.
4 发表于 2008-05-15 14:46 ·  中国 上海 联通
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
用/PURGE和/S代替/MIR可以吗?


-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------

Started : Thu May 15 14:30:10 2008

Usage :: ROBOCOPY source destination ...]

source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
file :: File(s) to copy (names/wildcards: default is "*.*").

::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/LEV:n :: only copy the top n LEVels of the source directory tree.

/Z :: copy files in restartable mode.
/B :: copy files in Backup mode.
/ZB :: use restartable mode; if access denied use Backup mode.

/COPY:copyflag :: what to COPY (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

/SEC :: copy files with SECurity (equivalent to /COPY:DATS).
/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPY :: COPY NO file info (useful with /PURGE).

/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).

/MOV :: MOVe files (delete from source after copying).
/MOVE :: MOVE files AND dirs (delete from source after copying).

/A+: :: add the given Attributes to copied files.
/A-: :: remove the given Attributes from copied files.

/CREATE :: CREATE directory tree and zero-length files only.
/FAT :: create destination files using 8.3 FAT file names only.
/FFT :: assume FAT File Times (2-second granularity).
/256 :: turn off very long path (> 256 characters) support.

/MON:n :: MONitor source; run again when more than n changes seen.
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.

/RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
/PF :: check run hours on a Per File (not per pass) basis.

/IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.

::
:: File Selection Options :
::
/A :: copy only files with the Archive attribute set.
/M :: copy only files with the Archive attribute and reset it.
/IA: :: Include only files with any of the given Attributes set.
/XA: :: eXclude files with any of the given Attributes set.

/XF file ... :: eXclude Files matching given names/paths/wildcards.
/XD dirs ... :: eXclude Directories matching given names/paths.

/XC :: eXclude Changed files.
/XN :: eXclude Newer files.
/XO :: eXclude Older files.
/XX :: eXclude eXtra files and directories.
/XL :: eXclude Lonely files and directories.
/IS :: Include Same files.
/IT :: Include Tweaked files.

/MAX:n :: MAXimum file size - exclude files bigger than n bytes.
/MIN:n :: MINimum file size - exclude files smaller than n bytes.

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
/MINLAD:n :: MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).

/XJ :: eXclude Junction points. (normally included by default).

::
:: Retry Options :
::
/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.

/REG :: Save /R:n and /W:n in the Registry as default settings.

/TBD :: wait for sharenames To Be Defined (retry error 67).

::
:: Logging Options :
::
/L :: List only - don't copy, timestamp or delete any files.
/X :: report all eXtra files, not just those selected.
/V :: produce Verbose output, showing skipped files.
/TS :: include source file Time Stamps in the output.
/FP :: include Full Pathname of files in the output.

/NS :: No Size - don't log file sizes.
/NC :: No Class - don't log file classes.
/NFL :: No File List - don't log file names.
/NDL :: No Directory List - don't log directory names.

/NP :: No Progress - don't display % copied.
/ETA :: show Estimated Time of Arrival of copied files.

/LOG:file :: output status to LOG file (overwrite existing log).
/LOG+:file :: output status to LOG file (append to existing log).

/TEE :: output to console window, as well as the log file.

/NJH :: No Job Header.
/NJS :: No Job Summary.

::
:: Job Options :
::
/JOB:jobname :: take parameters from the named JOB file.
/SAVE:jobname :: SAVE parameters to the named job file
/QUIT :: QUIT after processing command line (to view parameters).
/NOSD :: NO Source Directory is specified.
/NODD :: NO Destination Directory is specified.
/IF :: Include the following Files.
5 发表于 2008-05-15 14:57 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
积分 2,278
发帖 1,020
注册 2007-11-19 13:34
18年会员
UID 103127
性别 男
状态 离线
这个是论坛里的代码,我引用下:
:删除目录树内非只读的所有空目录
for /f "delims=" %a in ('dir/a/s/b^|sort /r')do rd "%a" 2>nul
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
wxs81514 +1 2008-05-16 15:03
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
6 发表于 2008-05-15 15:22 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
可以了,非常感谢!这一下不用想办法去删空文件夹了.
还有个问题请教一下:
用上述命令备份时能不能去除某些文件夹不操作,比如"recycled",这个是回收站.
7 发表于 2008-05-15 15:28 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
或者不备份隐藏文件夹也行,因为"recycled"是隐藏文件夹
8 发表于 2008-05-15 15:40 ·  中国 上海 联通
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
Originally posted by wxs81514 at 2008-5-15 03:28 PM:
或者不备份隐藏文件夹也行,因为"recycled"是隐藏文件夹

看帮助文档的时候一定要仔细啊^_^

-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------

Started : Thu May 15 14:30:10 2008

Usage :: ROBOCOPY source destination ...]

source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
file :: File(s) to copy (names/wildcards: default is "*.*").

::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/LEV:n :: only copy the top n LEVels of the source directory tree.

/Z :: copy files in restartable mode.
/B :: copy files in Backup mode.
/ZB :: use restartable mode; if access denied use Backup mode.

/COPY:copyflag :: what to COPY (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

/SEC :: copy files with SECurity (equivalent to /COPY:DATS).
/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPY :: COPY NO file info (useful with /PURGE).

/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).

/MOV :: MOVe files (delete from source after copying).
/MOVE :: MOVE files AND dirs (delete from source after copying).

/A+: :: add the given Attributes to copied files.
/A-: :: remove the given Attributes from copied files.

/CREATE :: CREATE directory tree and zero-length files only.
/FAT :: create destination files using 8.3 FAT file names only.
/FFT :: assume FAT File Times (2-second granularity).
/256 :: turn off very long path (> 256 characters) support.

/MON:n :: MONitor source; run again when more than n changes seen.
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.

/RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
/PF :: check run hours on a Per File (not per pass) basis.

/IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.

::
:: File Selection Options :
::
/A :: copy only files with the Archive attribute set.
/M :: copy only files with the Archive attribute and reset it.
/IA: :: Include only files with any of the given Attributes set.
/XA: :: eXclude files with any of the given Attributes set.

/XF file ... :: eXclude Files matching given names/paths/wildcards.
/XD dirs ... :: eXclude Directories matching given names/paths.

/XC :: eXclude Changed files.
/XN :: eXclude Newer files.
/XO :: eXclude Older files.
/XX :: eXclude eXtra files and directories.
/XL :: eXclude Lonely files and directories.
/IS :: Include Same files.
/IT :: Include Tweaked files.

/MAX:n :: MAXimum file size - exclude files bigger than n bytes.
/MIN:n :: MINimum file size - exclude files smaller than n bytes.

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
/MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n.
/MINLAD:n :: MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).

/XJ :: eXclude Junction points. (normally included by default).

::
:: Retry Options :
::
/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.

/REG :: Save /R:n and /W:n in the Registry as default settings.

/TBD :: wait for sharenames To Be Defined (retry error 67).

::
:: Logging Options :
::
/L :: List only - don't copy, timestamp or delete any files.
/X :: report all eXtra files, not just those selected.
/V :: produce Verbose output, showing skipped files.
/TS :: include source file Time Stamps in the output.
/FP :: include Full Pathname of files in the output.

/NS :: No Size - don't log file sizes.
/NC :: No Class - don't log file classes.
/NFL :: No File List - don't log file names.
/NDL :: No Directory List - don't log directory names.

/NP :: No Progress - don't display % copied.
/ETA :: show Estimated Time of Arrival of copied files.

/LOG:file :: output status to LOG file (overwrite existing log).
/LOG+:file :: output status to LOG file (append to existing log).

/TEE :: output to console window, as well as the log file.

/NJH :: No Job Header.
/NJS :: No Job Summary.

::
:: Job Options :
::
/JOB:jobname :: take parameters from the named JOB file.
/SAVE:jobname :: SAVE parameters to the named job file
/QUIT :: QUIT after processing command line (to view parameters).
/NOSD :: NO Source Directory is specified.
/NODD :: NO Destination Directory is specified.
/IF :: Include the following Files.
9 发表于 2008-05-15 19:03 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
谢谢,英文不怎么好,看不太懂,不过经指定还是看懂了,试了可以,但又出现一个新问题:
备份时我想排除{Documents and Settings},但把它写进去电脑就把它认为是三个文件夹了,即 "Documents"," and"," Settings",怎样才可以让它认成一个文件夹.
10 发表于 2008-05-15 19:37 ·  中国 重庆 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
对于有空格的目录,加个双引号试试。
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
wxs81514 +1 2008-05-16 15:06
11 发表于 2008-05-16 10:18 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
HAT真是太厉害了,什么都懂啊,一试果然灵.
12 发表于 2008-05-16 10:48 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
HAT,你好,不知怎么称呼你?感谢你这段时间为我解决了一系列问题.使我学到了不少东西,为我的工作帮了大忙. 还有三个贴子的问题,比较麻烦,不知道是不是你没看到,还是想请教一下.哪怕提供点思路都好.贴子主题如下:
1.从文件中读取电脑名称和密码批量建立用户
2.用管理员权限同步服务器时间
3.检测并自动取消共享
4.怎样让局域网的电脑按指定顺序进行备份
13 发表于 2008-05-16 15:07 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
我在用下面代码备时又出现新问题:
robocopy C:\ \\zhixinserver\%computername%\Other_new_files\Disk_F *.doc *.xls *.ppt *.dwg *.cdr *.pdf /xd "Documents and Settings" "Program Files" recycler recycled WINDOWS winnt /xa:h /maxage:30 /PURGE /S
目标文件夹内并是30天内更新过的文件,而是增量备份.
14 发表于 2008-05-16 15:24 ·  中国 浙江 杭州 电信
新手上路
积分 4
发帖 2
注册 2008-04-18 16:03
18年会员
UID 116254
性别 男
状态 离线
Originally posted by wxs81514 at 2008-5-16 10:48 AM:
1.从文件中读取电脑名称和密码批量建立用户
2.用管理员权限同步服务器时间
3.检测并自动取消共享
4.怎样让局域网的电脑按指定顺序进行备份


提问前试着自己多搜一下
第一个用户密码用 username : pass 的格式写在文件里用for读出来,然后使用
net user username \"pass\" /add
net localgroup administrators username /add
添加, 添加受限用户把第二句的 administrators 换成 users

第二个要先改注册表指定同步时间服务器,具体看
http://bbs.nfan.org/read.php?tid=42382

第三个不知道你是要取消还是禁用
net share c$ /delete
net share d$ /delete
....
禁用的话直接用net stop Server禁掉服务好了

第四个不懂,什么叫指定顺序备份 ..

[ Last edited by bg5hfc on 2008-5-16 at 03:26 PM ]
15 发表于 2008-05-16 15:58 ·  中国 广东 东莞 电信
初级用户
★★
积分 118
发帖 52
注册 2008-05-07 09:39
18年会员
UID 117968
性别 男
状态 离线
14楼的朋友,谢谢你,这些问题我也是查了很久没有查到才发贴的.
第三个我是要禁止使用共享功能. 想请教一下:net stop Server,我了解过了,它会停掉所有的网络服务器,比信使什么的.能不能仅停止共享服务.
论坛跳转: