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-23 02:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Unresolved] Batch non-empty judgment access and deletion of slightly deformed directories View 14,731 Replies 67
Original Poster Posted 2008-02-29 21:22 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Supplement. It can be judged by combining the rd command with ||, but this will delete the empty directory with a dot. Is there any other method, like dir or something?
Declare that the code idea similar to the following is not counted. This changes the creation date of the file.

rd 123..\ 2>nul||echo Not empty
md 123..\ 2>nul

-------------------------------------------------------------------------------------------------------------
Supplementary at 17:30
Still have to rely on myself. Now I post the code for everyone to share. If it's good, collect it.
(May be invalid for other abnormal directories with dots, will be improved later.)
@echo off&setlocal enabledelayedexpansion
:by plp626@cn-dos.net on 2008-3-1
echo The following are all non-empty abnormal directories with dots in the current directory and their contained files:
set ln=----------------------------------------------
set m=0
for /f "tokens=4-5" %%a in ('dir/ad/x^|findstr /e \.') do (
echo %%b|findstr E>nul||dir/b %%a|find/v ":">nul&&(set/a m+=1
echo !m!!ln!&echo The directory of %%~dpb%%b:&echo.
dir/a/b %%a
) )
pause


Attached code:

Access
@echo off
:by plp626@cn-dos.net on 2008-3-3
if "%1"=="" dir/a&goto :eof
if "%1"=="/f" goto f
if "%1"=="/c" more "%~dpnx0"&goto :eof
if "%1"=="/?" goto syntax
set folder=%1
echo %folder%|findstr /e \.>nul&&set folder=%folder:.=\.%||(dir/a %1)
for /f "tokens=4-5" %%a in ('dir/ad/x^|findstr /e \.') do (
for /f "tokens=1-2" %%i in ('echo %%a %%b^|findstr /ec:" %folder%"') do (
dir/a/s/x %%i
) )
goto :eof
:f
dir /a/b|findstr /e \.||echo No abnormal directory with suffix dot found in the current path
goto :eof
:syntax
echo Enhanced dir command, can access abnormal directories with dots.&echo.
echo /f View abnormal directories in the current path
echo /c View the source code of %~nx0. &echo.
echo usage1:
echo When accessing abnormal directories, directly enter the abnormal directory name you see.
echo When accessing directories in abnormal directories, use the short name. (Will be improved later)
echo When accessing normal directories, it is the same as the dir command. If there are spaces, add double quotes.
echo.&echo example:
echo Access 123. directory: %~n0 123.
goto :eof

Delete (Paste the code directly into the command line. Do not run it in the path where the ghost backup file is located!)

Even if there are Con, Prn, Aux, Nul, Lpt?, Com? etc. (? means numbers 1-9) in the directory that are not abnormal directories with dots, they will be deleted as well.

::Delete any abnormal directory with dot in the current directory
for /f "delims=" %a in ('dir/ad/b^|findstr /e "\."') do rd /q/s "\\?\%a" 2>nul


::Delete any abnormal directory with dot in the current directory and its subdirectories
for /f "delims=" %a in ('dir/ad/s/b^|findstr /e "\."') do rd /q/s "\\?\%a" 2>nul


::Delete any empty abnormal directory with dot in the directory tree of the current path and display non-empty abnormal directories
for /f "delims=" %a in ('dir/ad/s/b^|findstr /e "\."') do rd "%a.\" 2>nul||echo %a


[ Last edited by plp626 on 2008-4-27 at 12:11 AM ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
523066680 +2 2008-03-15 18:16
regvip2008 +2 2008-04-17 14:29
qinbuer +4 2008-06-29 21:27
Floor 2 Posted 2008-03-01 00:40 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
No one? Did I not explain clearly enough?
Posting this thread isn't because I'm making trouble for no reason. Because some USB flash drive viruses actually exist in these malformed directories.
Files can also be stored in malformed directories.
For example, using the command
copy *.* 123..\

you can copy all files in the current path to the 123. folder.
Now the question is how to judge whether there are files in this malformed directory, that is, whether it's non-empty.
Hope everyone actively participates!

[ Last edited by plp626 on 2008-3-1 at 12:43 AM ]
Floor 3 Posted 2008-03-01 12:17 ·  中国 江苏 苏州 移动
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Strangely enough, although the file was copied in, the attribute of its folder is still 0 bytes when checked!
Floor 4 Posted 2008-03-01 12:18 ·  中国 江苏 苏州 移动
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Strangely enough, although the file was copied in, the property of its folder is still 0 bytes when checked!
Floor 5 Posted 2008-03-01 14:45 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
There are quite a few abnormal directories on the machines in the school computer lab, and most abnormal directories have no files placed in them. I just want to see which directories have files.
Hope the experts can give some pointers, I'm very grateful!

[ Last edited by plp626 on 2008-3-1 at 06:59 PM ]
Floor 6 Posted 2008-03-01 15:36 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Haha. Finally figured it out.

This post is closed!

[ Last edited by plp626 on 2008-3-1 at 03:51 PM ]
Floor 7 Posted 2008-03-01 17:20 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The LZ has figured it out. Can you share the method?
致精致简!
Floor 8 Posted 2008-03-01 18:42 ·  中国 广东 揭阳 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Another thing is that if you put a nul\ inside a., you can't directly use Rd ae216~1 /s /q to delete it. You have to enter ae216~1 and then Rd nul... (Just a personal opinion)
Floor 9 Posted 2008-03-01 19:44 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
523066680 said:
My code algorithm is designed based on the file name suffix being ".".
I will consider this when I have time combined with the first code. It shouldn't be difficult.
Floor 10 Posted 2008-03-01 21:10 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
It's really troublesome to do it actually, give a test code
Please delete it:
@echo off
for %%a in (plp 626 cn dos 1 0 fdf d ret 就是 lo aux com1 nul con pp 465 漂来漂 看 ai) do (
md %%a...\ %%a...\...\
for %%b in (con nul aux com1) do (
md %%a...\%%b\
copy *.bat "%%a...\%%b\"
md %%a...\%%b\con\
) )


[ Last edited by plp626 on 2008-3-1 at 09:57 PM ]
Floor 11 Posted 2008-03-01 21:46 ·  中国 湖北 武汉 电信
初级用户
Credits 108
Posts 49
Joined 2008-02-26 18:54
18-year member
UID 111491
Gender Male
Status Offline
I'm afraid we can only use start to open these abnormal directories to judge whether they are empty........
Floor 12 Posted 2008-03-01 21:52 ·  中国 湖北 武汉 电信
初级用户
Credits 108
Posts 49
Joined 2008-02-26 18:54
18-year member
UID 111491
Gender Male
Status Offline
It can also be judged using type. The test code is as follows:
md d:\1_11..\&echo %random%>d:\1_11..\11.txt&type d:\1_11..\11.txt
Floor 13 Posted 2008-03-01 23:31 ·  中国 重庆 电信
初级用户
Credits 34
Posts 14
Joined 2007-12-13 18:21
18-year member
UID 105563
Gender Male
Status Offline
Got it. Not bad.
Floor 14 Posted 2008-03-02 00:05 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
We see that the original folder shown is missing a dot.

If you put a 123 in the same directory.
And create a 123 directory.
When you access 123., you are actually accessing the 123 folder. So in terms of size, it can display the size of the 123 directory. If there is no 123 directory, it is 0.

The system recognizes 123. as the attributes of 123... So you can't see the actual size, and the same reason you can't double-click to access it is this. After you create 123, it is equivalent to accessing the 123 folder.

You can also delete 123., and there is no error prompt, because it will delete the 123 directory.

PS:
I don't know if you can guess after reading the above?

Accessing a directory with a dot is not necessarily starting with start...

Once you know the above, it's easy to understand...
It should be original hehe. At least I didn't copy it from elsewhere.




md 123...\
Accessing this directory is accessing that abnormal directory with a dot, and you can also get information like size~
Floor 15 Posted 2008-03-02 00:34 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Hehe, this has been discussed long ago.

What you are accessing are all the information of the 123 directory. In fact, the 123... directory still exists, and the content inside it you can't see by double-clicking the 123 directory.
致精致简!
1 2 3 5 Next ›
Forum Jump: