.
.
求助:从4个文件夹中取出相同的文件名,存放在 "9999.txt"中
4个文件夹,每个文件夹有好多个xls文件,而其中都有两个或数个相同的文件名称,现在要把这相同的文件名称取出来,在9999.txt文件中列示。
注:仅文件名称取出来,不相同的不列出来
哪位大佬,帮我码一下,谢谢。
以下是我对大佬们的各种贴子经过不断地观摹学习修改测试,确定了以下四个方案的代码,彻底符合了自已的要求。今天我这个新手很高兴,看到了批处理的强大。我一定要好好地学习,天天向上。呵呵。
4个文件夹分别为 1 2 3 4,各个文件夹中有各种文件,但其中有一个或数个同时在4个文件夹中同时都存在的文件
方案一,最佳最快,点击即完成- echo off
- @echo off
- cd /d "%~dp0"
- if exist Ok.txt del /f OK.txt
-
- for %%i in (1\*.*) do echo %%~nxi>>1111.txt
- for %%j in (2\*.*) do echo %%~nxj>>2222.txt
- findstr /belig:1111.txt 2222.txt >W1.txt
-
-
- for %%k in (3\*.*) do echo %%~nxk>>3333.txt
- for %%m in (4\*.*) do echo %%~nxm>>4444.txt
- findstr /belig:3333.txt 4444.txt >W2.txt
-
-
- findstr /belig:w1.txt w2.txt >OK.txt
- del /f 1111.txt & del /f 2222.txt & del /f 3333.txt & del /f 4444.txt & del /f w1.txt & del /f w2.txt
- pause&exit
复制代码 方案二:第二快- @echo off
- cd /d "%~dp0"
- if exist 1234Ok.txt del /f 1234OK.txt
-
- for /f "delims=" %%a in ('dir /s/b/a-d "1\"') do (
- echo %%~nxa >>W11.txt
- )
- for /f "delims=" %%b in ('dir /s/b/a-d "2\"') do (
- echo %%~nxb >>W22.txt
- )
- for /f "delims=" %%c in ('dir /s/b/a-d "3\"') do (
- echo %%~nxc >>W33.txt
- )
- for /f "delims=" %%d in ('dir /s/b/a-d "4\"') do (
- echo %%~nxd >>W44.txt
- )
- type "W11.txt" | findstr /belig:"w22.txt">1122.txt
- type "W33.txt" | findstr /belig:"w44.txt">3344.txt
- type "1122.txt" | findstr /belig:"3344.txt">1234OK.txt
- del /f w11.txt & del /f w22.txt & del /f w33.txt & del /f w44.txt & del /f 1122.txt & del /f 3344.txt
- pause&exit
复制代码 方案三 第三(稍慢)- @echo off
- if exist OK08.txt del /f ok08.txt
-
- for /f "delims=" %%a in ('dir /s/b/a-d "1\"') do (
- for /f "delims=" %%b in ('dir /s/b/a-d "2\"') do (
-
- if "%%~nxa"=="%%~nxb" echo %%~nxa >>w1.txt
- ))
-
- for /f "delims=" %%i in ('dir /s/b/a-d "3\"') do (
- for /f "delims=" %%k in ('dir /s/b/a-d "4\"') do (
- if "%%~nxi"=="%%~nxk" echo %%~nxi >>w2.txt
- ))
-
- findstr /belig:w1.txt w2.txt >>OK08.txt
- del w1.txt & del w2.txt
-
- pause&exit
复制代码 方案四 超级超级慢 但像我这种新手理解起来很省力- @echo off
- cd /d "%~dp0"
- if exist w13.txt del /f w13.txt
-
- for /f "delims=" %%a in ('dir /s/b/a-d "1\"') do (
- for /f "delims=" %%b in ('dir /s/b/a-d "2\"') do (
- for /f "delims=" %%c in ('dir /s/b/a-d "3\"') do (
- for /f "delims=" %%d in ('dir /s/b/a-d "4\"') do (
-
- if "%%~nxa"=="%%~nxb" if "%%~nxb"=="%%~nxc" if "%%~nxc"=="%%~nxd" echo %%~nxd >>w13.txt
- ))))
-
- pause&exit
复制代码
|