中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-29 08:53
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » Find Files and Operate (View Path, Copy, Delete).bat (9.5 Update)
Printable Version  7,954 / 23
Floor1 vkill Posted 2006-08-31 14:02
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
*.bat

Now there is still a problem, originating from
for /f "tokens=* delims= " %%a in (%dati%_9.txt) do (find %dati%_6.txt /v /i "%%a">>%dati%_5.txt)
In this sentence, there are several repetitions in the generated search file for the number of lines stored in the filtered file. How to fix this?


Now I just want to restore the deletion and start over, making it more automated



[ Last edited by he200377 on 2006-9-6 at 02:52 ]
Floor2 namejm Posted 2006-08-31 14:55
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Not bad, relatively practical.

Of course, there are also flaws, and some may lead to very serious consequences:

1. For each variable set by set /p, the variable should be set to an empty value before receiving user input; otherwise, after returning to goto start next time, pressing a few Enter keys continuously will repeat the previous operation, which may cause loss of user data;

2. Once user input is to be received, there should be a few input error detection statements to detect more serious input errors to prevent accidents;

3. Always pay attention to the processing of strings with spaces; for example: copy %%i, the value of %%i may have spaces, and it will be wrong if not enclosed in quotes; in the sentence for "delims=," %%i in (a.txt), it seems that a sentence tokens=* should be added, and the %%i in del %%i should be enclosed in quotes with %%i... There are several similar places, please pay attention to modification;

4. During the execution process, there may be a long waiting time, so there should be a prompt on the screen, and irrelevant information should be cls'ed;

If the building owner can improve it a little more, this script will be more useful.

[ Last edited by namejm on 2006-8-31 at 15:00 ]
Floor3 vkill Posted 2006-08-31 15:13
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Thanks to the guidance from the person above.

Item 1: I really didn't think of this, this should be noted.

Item 2: I think I should also block, | & and spaces, because I tried that as long as these characters are input in the input state, it will force to exit. This is because I was lazy and didn't add filtering. Oh.

Item 3: Hmm, this modification is better.

Item 4: I think the execution is very fast, about 2s, so I didn't write a prompt.

Please help me modify it~ Hehe, thank you first. I'll see which places I didn't notice specifically.

[ Last edited by he200377 on 2006-8-31 at 15:15 ]
Floor4 namejm Posted 2006-08-31 17:14
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by he200377 at 2006-8-31 15:13:

  Article 2 I think it should also be blocked, | & and spaces, because I tried that as long as these characters are entered in the input state, it will force exit. This is because I was lazy and did not add filtering. Hey
  ——|, & and other characters are sensitive characters of CMD, you can't filter them out, only spaces are okay

  Article 4 I think the execution is very fast, about 2s, so I didn't write the prompt
  ——If the user specifies multiple paths, or there are many subfolders and files under a certain path, the search time will not be only two seconds. It seems that your test conditions are not sufficient


  In fact, there are still a few places to modify: for example, the cmd /c in the second sentence is redundant; if you want to be overly critical, some can still be found.
Floor5 namejm Posted 2006-08-31 17:22
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Here is the translated text:

  Come with a modified version, only modified most of the problems mentioned earlier, and slightly modified the prompt statements that are easy to cause misunderstandings. The situation in the input error detection part needs to be improved, but there is no time to perfect it for the time being; when querying, what prompt information to add, the original poster can decide by themselves, so I won't add it; the original poster can compare the previous and subsequent codes and continue to modify where improvement is needed:

@echo off
:start
cls
title Find and operate files (view path\copy\delete)
set name=
set /p name=Please enter the file name to be found (it is best to bring the suffix name):
set lj=
set /p lj=Please enter the search path (for example, enter c:\ if searching the C drive):


dir /a /s /b "%lj%" |find "%name%" >a.txt
if errorlevel 1 goto no
if errorlevel 0 goto ok

:no
echo There is no file you are looking for & pause && goto end

:ok
cls
echo ________________________________________________________________
echo Found file:
echo.
echo a View path ^| b Exit ^| c Copy ^| d Delete
echo ________________________________________________________________
set xz=
set /p xz= Please enter the operation code:
if not "%xz%"=="" (goto ok_%xz%) else (echo Invalid action & pause && goto ok)
echo Invalid action & pause && goto ok

:ok_a
cls
title View the path of the found file
type a.txt &pause& goto ok
:ok_b
goto end
:ok_c
cls
title Copy the found file
echo ________________________________________________________________
echo.
echo The default is to copy to the temp folder of the current directory. If there is no temp folder, it will be created automatically
echo.
echo y Execute default ^| 0 Return to the previous menu
echo ________________________________________________________________
set clj=
set /p clj= Please enter the location to copy to:
if %clj%==0 goto ok
if %clj%==y md temp & for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" temp\
for /f "tokens=* delims=" %%i in (a.txt) do copy "%%i" "%clj%\"
goto end
:ok_d
cls
title Delete the found file
echo ________________________________________________________________
echo.
echo This operation is highly dangerous, please confirm again that you want to delete?
echo.
echo y Confirm ^| 0 Return to the previous menu
echo ________________________________________________________________
set del_=
set /p del_= Please choose:
if "%del_%"=="" echo Invalid action & pause && goto ok
if %del_%==0 goto ok
if %del_%==y for /f "tokens=* delims=" %%i in (a.txt) do del /q /f "%%i"
echo Invalid action & pause && goto ok

:end
del /q a.txt
goto start


[ Last edited by namejm on 2006-8-31 at 17:27 ]
Floor6 vkill Posted 2006-08-31 18:11
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Thanks, I'll go back and take another look
Floor7 vkill Posted 2006-09-01 13:23
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Make a mark

Because it uses call: label parameter

Attachments
做恢复删除的时候想到的.rar (871 bytes)
Floor8 namejm Posted 2006-09-01 17:17
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Re he200377's top post:

  The code you have now has a fatal error: The statement dir /a /s /b "%lj%" |find "%name%" >%dati%.txt cannot achieve the query, so I modified the relevant statement to achieve the intention of the exact match search you wanted:


  As for not searching the directory where the script file is located, I haven't thought of an efficient way for the time being. The alternative is to delete the records of the directory where the script file is located from the found results.

  There are still other small problems: For example, before each query, you need to clear the log content to avoid mixing with the previous results.
Floor9 namejm Posted 2006-09-01 17:18
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by he200377 at 2006-9-1 13:23:
Make a mark

It's because of using call :label parameter

I don't understand the intention of your posting this thread. Could you please explain it?
Floor10 vkill Posted 2006-09-01 17:29
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
For example, before each query, you need to clear the log content to avoid mixing with the results of the previous time.

The file generated each time is named with the date + time (precise to seconds), so even if there is an interruption in the middle, it doesn't matter. In principle, the same - named file will not be generated.

[ Last edited by he200377 on 2006 - 9 - 1 at 17:39 ]
Floor11 vkill Posted 2006-09-01 17:31
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by namejm at 2006-9-1 17:18:

I didn't understand the intention of your posting this thread, could you please explain it?

Just thought of using it during testing and tried it out
Floor12 vkill Posted 2006-09-01 17:39
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Don't understand this? "%%~nxi" is the file name. Checked previous posts ~dp is the path, I think this is the file name.

//Tried it and understood

[ Last edited by he200377 on 2006-9-1 at 17:48 ]
Floor13 namejm Posted 2006-09-01 22:09
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by he200377 at 2006-9-1 17:29:
For example, before each query, you need to clear the log content to avoid mixing with the previous results

Each generated file is named with the date + time (precise to seconds), so even if there are...


  You still missed a very important file: fc_name.txt. If you miss this file, it will be a big problem - if you query different files several times and then directly select delete, heh heh, just wait to cry nose吧:P
Floor14 namejm Posted 2006-09-01 22:13
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The function of searching for a specified file throughout the entire disk. I made one the other day, and I'll post it for you to refer to.


[ Last edited by namejm on 2006-9-1 at 23:08 ]
Floor15 vkill Posted 2006-09-03 01:37
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Originally posted by namejm at 2006-9-1 22:13:
  The function of searching for a specified file across the entire disk. I made one the other day, and I'll post it for your reference.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023