标题: [文本处理] 批处理工具添加后缀。用于文件扩展名丢失 [打印本页]
作者: surup 时间: 2011-10-23 23:51 标题: 批处理工具添加后缀。用于文件扩展名丢失
- @echo off & setlocal EnableDelayedExpansion
- title [Get File Type] y.s.
- mode con: cols=80 lines=10 & color f0
- :start
- cls
- echo.
- echo *Before you use this script,try it as a TXT file first.
- echo *Make sure that the batch file and the target file in the same folder.
- echo *Type in "all" to check all files in this folder.
- echo *The Tab key may speed up your typing.
- echo.
- set/p file =^>^>Please type in the file name:
- call :head
- if !file! ==all (cls&echo.&echo.&echo.&set/p=^> Being proessed,please wait..<nul&call :all)
- set file=!file:"=!
- call :check
- cls
- echo.&echo.&echo.
- set/p=^> Being processed,please wait...<nul
- set numble=1
- call :temp
- call :compare
- call :ASCI
- call :check_type
- call :result
- call :appendix
- del temp*.ys
- start File_Type.txt
- exit
- :all
- call :temp
- for /f "delims=" %%a in ('dir /b /a:-d-s-h') do (
- set switch=1
- if "%%a"=="File_Type.txt" (set switch=0)
- if "%%a"=="File_Type.bat" (set switch=0)
- if "%%a"=="TEMP1.YS" (set switch=0)
- if !switch!==1 (set/a number+=1)
- if !switch!==1 (set file=%%a)
- if !switch!==1 (call :compare)
- if !switch!==1 (call :ASCI)
- if !switch!==1 (call :check_type)
- if !switch!==1 (call :result)
- )
- call :appendix
- start File_Type.txt
- del temp*.ys
- exit
- :check
- if not exist "!file!" (
- echo No such file!
- set/p =press any key to try again...<nul&pause>nul
- goto :start
- )
- goto :eof
- :compare
- set code=
- set begin=0
- for /f "skip=1 tokens=3" %%i in ('fc /b "temp1.ys" "!file!"') do (
- if !begin!==0 (if %%i==00 (set code=!code!%%i) else (set begin=1))
- if !begin!==1 (if %%i==00 (goto :eof) else (set code=!code!%%i))
- )
- goto :eof
- :ASCI
- set ASCI=
- set/a line=0
- for /f "skip=3 delims=" %%i in ('fc /lb5 "!file!" "temp1.ys"') do (
- set/a line+=1
- set ASCI=!ASCI! %%i
- if !line!==2 goto :eof
- )
- goto :eof
- :check_type
- set possible=Unknow
- for /f "skip=116 delims=" %%i in (File_Type.bat) do (
- set aa=%%i
- if "!aa:~6!"==":eof" (goto :eof)
- if "!code:~0,4!"=="!aa:~56,4!" (set possible=!aa:~6,34!)
- )
- goto :eof
- :head
- echo [%date% %time%]>File_Type.txt
- echo.>>File_Type.txt
- echo *If the report shows the File Type is Unknown,search the Hex Code below in Google.com for further info *>>File_Type.txt
- echo *Or the ASCI Code may show some direct info about the file *>>File_Type.txt
- echo.>>File_Type.txt
- echo ************************************* Report *************************************>>File_Type.txt
- goto :eof
- :result
- echo.>>File_Type.txt
- echo ^< No.!number! ^> >>File_Type.txt
- echo __________________________>>File_Type.txt
- echo [!file!]>>File_Type.txt
- echo __________________________>>File_Type.txt
- echo Hex Code:!code:~0,12!>>File_Type.txt
- echo __________________________>>File_Type.txt
- echo ASCI Code:!ASCI:~0,16!>>File_Type.txt
- echo __________________________>>File_Type.txt
- echo File Type:!possible!>>File_Type.txt
- echo __________________________>>File_Type.txt
- echo.>>File_Type.txt
- goto :eof
- :appendix
- echo **********************************************************************************>>File_Type.txt
- echo.>>File_Type.txt
- echo.>>File_Type.txt
- echo Thank you for your use.If you have any advice,please contact me. 0^>_^<0>>File_Type.txt
- echo.>>File_Type.txt
- echo * E-mail: y.s.outside@gmail.com *>>File_Type.txt
- echo.>>File_Type.txt
- echo.>>File_Type.txt
- echo ************************************* Appendix *************************************>>File_Type.txt
- echo.>>File_Type.txt
- echo These are some common file type information:>>File_Type.txt
- echo.>>File_Type.txt
- echo * Hex Code may shorter than the codes below,so be careful *>>File_Type.txt
- echo.>>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo EXE(exe) Head Hex Code:4D5A >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo JPEG(jpg) Head Hex Code:FFD8FFE0 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo PNG(png) Head Hex Code:89504E47 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo GIF(gif) Head Hex Code:47494638 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo TIFF(tif) Head Hex Code:49492A00 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Windows Bitmap(bmp) Head Hex Code:424D >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo CAD(dwg) Head Hex Code:41433130 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo WorldPerfect(wpd) Head Hex Code:FF575043 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Postscript(eps or ps) Head Hex Code:252150532D41646F6265 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Adobe Acrobat(pdf) Head Hex Code:255044462D312E >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Quicken(qdf) Head Hex Code:AC9EBD8F >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Windows Password(pwl) Head Hex Code:E3828596 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo ZIP Archive(zip) Head Hex Code:504B0304 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Adobe Photoshop(psd) Head Hex Code:38425053 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Rich Text Format(rtf) Head Hex Code:41433130 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo XML(xml) Head Hex Code:3C3F786D6C >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo HTML(html) Head Hex Code:68746D6C3E >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Email [thorough only](eml) Head Hex Code:44656C69766572792D646174653A >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Outlook Express(dbx) Head Hex Code:CFAD12FEC5FD746F >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Outlook(pst) Head Hex Code:2142444E >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MS Office(xls or doc or ppt) Head Hex Code:D0CF11E0 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MS Access(mdb) Head Hex Code:5374616E64617264204A >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo RAR Archive(rar) Head Hex Code:52617221 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo 7Z(7-zip) Head Hex Code:377ABCAF271C >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Wave(wav) Head Hex Code:57415645 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo APE(ape) Head Hex Code:4D414320960F >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MP3(mp3) Head Hex Code:49443303 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo FLV(flv) Head Hex Code:464C56 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MKV(mkv) Head Hex Code:1A45DFA3 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo AVI(avi) Head Hex Code:41564920 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo ASS(ass) Head Hex Code:FFFE5B >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Real Audio(ram) Head Hex Code:2E7261FD >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Real Media(rm) Head Hex Code:2E524D46 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MPEG(mpg) Head Hex Code:000001BA >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MPEG(mpg) Head Hex Code:000001B3 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Quicktime(mov) Head Hex Code:6D6F6F76 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo Windows Media(asf) Head Hex Code:3026B2758E66CF11 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- echo MIDI(mid) Head Hex Code:4D546864 >>File_Type.txt
- echo ________________________________________>>File_Type.txt
- goto :eof
- :temp
- more +197 "%~f0"|debug>nul&goto :eof
- e 0 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
- rcx
- 10
- n TEMP1.YS
- w
- q
-
复制代码
作者: surup 时间: 2011-10-24 00:11
最好以视频的形式一步一步讲解。在此先谢谢!
其次这个文件怎么使用? 打开后看到 请输入文件名
无论输入什么 包括Tab键 都显示 没有这样的文件 按任意键可以再试一次…
作者: HAT 时间: 2011-10-24 09:42
最好你给报销一下往返机票,我可以抽空过去面对面的讲解。
作者: sxw 时间: 2011-10-24 13:14
回复 3# HAT
版主讲一下原理呗?好添加别的后缀啊
作者: sxw 时间: 2011-10-24 13:47
回复 3# HAT
第120行 echo JPEG(jpg) Head Hex Code:FFD8FFFE0 >>File_Type.txt
是不是多了个'F'?
FFD8FFE0
作者: surup 时间: 2011-10-24 18:39
回复 5# sxw
嗯啊 的确是多了个F
作者: bluewing009 时间: 2011-10-24 19:06
额~也写过一个,原理相同,就是应对原来解决那个恶意改名的批处理丢失ini的时候没法恢复的情况,就是对头进行判定。但是也不能完全解决,比如exe和dll就相同……那个恶意批处理还记忆犹新,好像还有和Batcher的插曲啥的……叫什么垃圾清理,结果用的人都杯具了……
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |