China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 08:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to automatically delete empty folders View 2,975 Replies 14
Original Poster Posted 2008-05-15 09:11 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
Ask everyone:
I want to set up a batch script to automatically delete empty folders every day, because the automatic backup program I made will copy empty folders.
Floor 2 Posted 2008-05-15 10:04 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Which command does your automatic backup program use? Check if that command has a built-in switch to skip empty folders.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wxs81514 +2 2008-05-15 10:34
Floor 3 Posted 2008-05-15 10:34 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
The batch processing is written like this:
robocopy D:\ \\zhixinserver\%computername%\Other_new_files\Disk_D *.doc *.xls *.ppt *.dwg *.cdr *.pdf /s /xa:h /maxage:30 /mir
I only want the files that have been updated in the last 30 days. Files older than this date are automatically deleted. But when I add /mir, empty folders appear.
Floor 4 Posted 2008-05-15 14:46 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Can /PURGE and /S be used instead of /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.
Floor 5 Posted 2008-05-15 14:57 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
This is the code in the forum, I will quote it:
:Delete all empty directories that are not read-only in the directory tree
for /f "delims=" %a in ('dir/a/s/b^|sort /r')do rd "%a" 2>nul
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wxs81514 +1 2008-05-16 15:03
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 6 Posted 2008-05-15 15:22 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
Okay, thank you very much! Now there's no need to figure out how to delete empty folders.

There's another question I'd like to ask:
When backing up with the above command, can certain folders be excluded from the operation, such as "recycled", which is the recycle bin.
Floor 7 Posted 2008-05-15 15:28 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
Or you don't need to back up hidden folders. Because "recycled" is a hidden folder
Floor 8 Posted 2008-05-15 15:40 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Originally posted by wxs81514 at 2008-5-15 03:28 PM:
Or you can not back up hidden folders, because "recycled" is a hidden folder

You must be careful when reading the help document ^_^

-------------------------------------------------------------------------------
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.
Floor 9 Posted 2008-05-15 19:03 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
Thanks, my English is not very good, I can't understand it very well, but after being specified, I still understand it, and it worked, but a new problem appeared:
When backing up, I want to exclude {Documents and Settings}, but if I write it in, the computer thinks it is three folders, namely "Documents", "and", "Settings". How can I make it recognize it as one folder.
Floor 10 Posted 2008-05-15 19:37 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Try adding double quotes for directories with spaces.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wxs81514 +1 2008-05-16 15:06
Floor 11 Posted 2008-05-16 10:18 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
HAT is really amazing, knows everything, and it worked at first try.
Floor 12 Posted 2008-05-16 10:48 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
HAT, hello, I don't know how to address you? Thank you for solving a series of problems for me during this time. It has enabled me to learn a lot and has been of great help to my work. There are still three post problems, which are more troublesome. I don't know if you haven't seen them or I want to ask for advice. Even providing some ideas would be good. The post topics are as follows:
1. Batch create users by reading computer names and passwords from files
2. Synchronize server time with administrator privileges
3. Detect and automatically cancel sharing
4. How to make computers in the LAN back up in a specified order
Floor 13 Posted 2008-05-16 15:07 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
I'm getting a new issue when using the following code:
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
The target folder is not files updated within 30 days, but an incremental backup.
Floor 14 Posted 2008-05-16 15:24 ·  中国 浙江 杭州 电信
新手上路
Credits 4
Posts 2
Joined 2008-04-18 16:03
18-year member
UID 116254
Gender Male
Status Offline
Originally posted by wxs81514 at 2008-5-16 10:48 AM:
1. Batch create users by reading computer names and passwords from a file
2. Synchronize server time with administrator privileges
3. Detect and automatically cancel shares
4. How to make LAN computers back up in a specified order


Try to search more by yourself before asking
For the first one, write user passwords in the format of username : pass in the file, read them with for, then use
net user username \"pass\" /add
net localgroup administrators username /add
To add, replace administrators with users for adding restricted users

For the second one, first modify the registry to specify the time synchronization server, specifically see
http://bbs.nfan.org/read.php?tid=42382

For the third one, I don't know if you want to cancel or disable
net share c$ /delete
net share d$ /delete
....
For disabling, just use net stop Server to disable the service directly

For the fourth one, I don't understand, what does specified order backup mean ..

[ Last edited by bg5hfc on 2008-5-16 at 03:26 PM ]
Floor 15 Posted 2008-05-16 15:58 ·  中国 广东 东莞 电信
初级用户
★★
Credits 118
Posts 52
Joined 2008-05-07 09:39
18-year member
UID 117968
Gender Male
Status Offline
Friend on the 14th floor, thank you. I also spent a long time looking up these problems before posting. For the third one, I want to prohibit the use of the sharing function. I would like to ask: net stop Server, I have learned that it will stop all network servers, including the messenger and so on. Can I only stop the sharing service?
Forum Jump: