找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 22221|回复: 6

[文本处理] 批处理工具添加后缀。用于文件扩展名丢失

[复制链接]
发表于 2011-10-23 23:51:47 | 显示全部楼层 |阅读模式
  1. @echo off & setlocal EnableDelayedExpansion
  2. title [Get File Type] y.s.
  3. mode con: cols=80 lines=10 & color f0
  4. :start
  5.         cls
  6.         echo.
  7.         echo *Before you use this script,try it as a TXT file first.
  8.         echo *Make sure that the batch file and the target file in the same folder.
  9.         echo *Type in "all" to check all files in this folder.
  10.         echo *The Tab key may speed up your typing.
  11.         echo.
  12.         set/p file =^>^>Please type in the file name:
  13.         call :head
  14.         if !file! ==all (cls&echo.&echo.&echo.&set/p=^>        Being proessed,please wait..<nul&call :all)
  15.         set file=!file:"=!
  16.         call :check
  17.         cls
  18.         echo.&echo.&echo.
  19.         set/p=^>        Being processed,please wait...<nul
  20.         set numble=1
  21.         call :temp
  22.         call :compare
  23.         call :ASCI
  24.         call :check_type
  25.         call :result
  26.         call :appendix
  27.         del temp*.ys
  28.         start File_Type.txt
  29. exit
  30. :all
  31.         call :temp
  32.         for /f "delims=" %%a in ('dir /b /a:-d-s-h') do (
  33.                 set switch=1
  34.                 if "%%a"=="File_Type.txt" (set switch=0)
  35.                 if "%%a"=="File_Type.bat" (set switch=0)
  36.                 if "%%a"=="TEMP1.YS" (set switch=0)
  37.                 if !switch!==1 (set/a number+=1)
  38.                 if !switch!==1 (set file=%%a)
  39.                 if !switch!==1 (call :compare)
  40.                 if !switch!==1 (call :ASCI)
  41.                 if !switch!==1 (call :check_type)
  42.                 if !switch!==1 (call :result)
  43.         )
  44.         call :appendix
  45.         start File_Type.txt
  46.         del temp*.ys
  47.         exit
  48. :check
  49.         if not exist "!file!" (
  50.                 echo No such file!
  51.                 set/p =press any key to try again...<nul&pause>nul
  52.                 goto :start
  53.         )
  54.         goto :eof
  55. :compare
  56.         set code=
  57.         set begin=0
  58.         for /f "skip=1 tokens=3" %%i in ('fc /b "temp1.ys" "!file!"') do (
  59.                 if !begin!==0 (if %%i==00 (set code=!code!%%i) else (set begin=1))
  60.                 if !begin!==1 (if %%i==00 (goto :eof) else (set code=!code!%%i))
  61.         )
  62.         goto :eof
  63. :ASCI
  64.         set ASCI=
  65.         set/a line=0
  66.         for /f "skip=3 delims=" %%i in ('fc /lb5 "!file!" "temp1.ys"') do (
  67.                 set/a line+=1
  68.                 set ASCI=!ASCI! %%i
  69.                 if !line!==2 goto :eof
  70.         )
  71.         goto :eof
  72. :check_type
  73.         set possible=Unknow
  74.         for /f "skip=116 delims=" %%i in (File_Type.bat) do (
  75.                 set aa=%%i
  76.                 if "!aa:~6!"==":eof" (goto :eof)
  77.                 if "!code:~0,4!"=="!aa:~56,4!" (set possible=!aa:~6,34!)
  78.         )
  79.         goto :eof
  80. :head
  81.         echo [%date% %time%]>File_Type.txt
  82.         echo.>>File_Type.txt
  83.         echo *If the report shows the File Type is Unknown,search the Hex Code below in Google.com for further info *>>File_Type.txt
  84.         echo *Or the ASCI Code may show some direct info about the file *>>File_Type.txt
  85.         echo.>>File_Type.txt
  86.         echo ************************************* Report *************************************>>File_Type.txt
  87.         goto :eof
  88. :result
  89.         echo.>>File_Type.txt
  90.         echo         ^< No.!number! ^> >>File_Type.txt
  91.         echo __________________________>>File_Type.txt
  92.         echo [!file!]>>File_Type.txt
  93.         echo __________________________>>File_Type.txt
  94.         echo Hex Code:!code:~0,12!>>File_Type.txt
  95.         echo __________________________>>File_Type.txt
  96.         echo ASCI Code:!ASCI:~0,16!>>File_Type.txt
  97.         echo __________________________>>File_Type.txt
  98.         echo File Type:!possible!>>File_Type.txt
  99.         echo __________________________>>File_Type.txt
  100.         echo.>>File_Type.txt
  101.         goto :eof
  102. :appendix
  103.         echo **********************************************************************************>>File_Type.txt
  104.         echo.>>File_Type.txt
  105.         echo.>>File_Type.txt
  106.         echo Thank you for your use.If you have any advice,please contact me. 0^>_^<0>>File_Type.txt
  107.         echo.>>File_Type.txt
  108.         echo * E-mail: y.s.outside@gmail.com *>>File_Type.txt
  109.         echo.>>File_Type.txt
  110.         echo.>>File_Type.txt
  111.         echo ************************************* Appendix *************************************>>File_Type.txt
  112.         echo.>>File_Type.txt
  113.         echo These are some common file type information:>>File_Type.txt
  114.         echo.>>File_Type.txt
  115.         echo * Hex Code may shorter than the codes below,so be careful *>>File_Type.txt
  116.         echo.>>File_Type.txt
  117.         echo ________________________________________>>File_Type.txt
  118.         echo EXE(exe)           Head Hex Code:4D5A >>File_Type.txt
  119.         echo ________________________________________>>File_Type.txt
  120.         echo JPEG(jpg)           Head Hex Code:FFD8FFE0 >>File_Type.txt
  121.         echo ________________________________________>>File_Type.txt
  122.         echo PNG(png)           Head Hex Code:89504E47 >>File_Type.txt
  123.         echo ________________________________________>>File_Type.txt
  124.         echo GIF(gif)           Head Hex Code:47494638 >>File_Type.txt
  125.         echo ________________________________________>>File_Type.txt
  126.         echo TIFF(tif)           Head Hex Code:49492A00 >>File_Type.txt
  127.         echo ________________________________________>>File_Type.txt
  128.         echo Windows Bitmap(bmp)           Head Hex Code:424D >>File_Type.txt
  129.         echo ________________________________________>>File_Type.txt
  130.         echo CAD(dwg)           Head Hex Code:41433130 >>File_Type.txt
  131.         echo ________________________________________>>File_Type.txt
  132.         echo WorldPerfect(wpd)           Head Hex Code:FF575043 >>File_Type.txt
  133.         echo ________________________________________>>File_Type.txt
  134.         echo Postscript(eps or ps)           Head Hex Code:252150532D41646F6265 >>File_Type.txt
  135.         echo ________________________________________>>File_Type.txt
  136.         echo Adobe Acrobat(pdf)           Head Hex Code:255044462D312E >>File_Type.txt
  137.         echo ________________________________________>>File_Type.txt
  138.         echo Quicken(qdf)           Head Hex Code:AC9EBD8F >>File_Type.txt
  139.         echo ________________________________________>>File_Type.txt
  140.         echo Windows Password(pwl)           Head Hex Code:E3828596 >>File_Type.txt
  141.         echo ________________________________________>>File_Type.txt
  142.         echo ZIP Archive(zip)           Head Hex Code:504B0304 >>File_Type.txt
  143.         echo ________________________________________>>File_Type.txt
  144.         echo Adobe Photoshop(psd)           Head Hex Code:38425053 >>File_Type.txt
  145.         echo ________________________________________>>File_Type.txt
  146.         echo Rich Text Format(rtf)           Head Hex Code:41433130 >>File_Type.txt
  147.         echo ________________________________________>>File_Type.txt
  148.         echo XML(xml)           Head Hex Code:3C3F786D6C >>File_Type.txt
  149.         echo ________________________________________>>File_Type.txt
  150.         echo HTML(html)           Head Hex Code:68746D6C3E >>File_Type.txt
  151.         echo ________________________________________>>File_Type.txt
  152.         echo Email [thorough only](eml)           Head Hex Code:44656C69766572792D646174653A >>File_Type.txt
  153.         echo ________________________________________>>File_Type.txt
  154.         echo Outlook Express(dbx)           Head Hex Code:CFAD12FEC5FD746F >>File_Type.txt
  155.         echo ________________________________________>>File_Type.txt
  156.         echo Outlook(pst)           Head Hex Code:2142444E >>File_Type.txt
  157.         echo ________________________________________>>File_Type.txt
  158.         echo MS Office(xls or doc or ppt)           Head Hex Code:D0CF11E0 >>File_Type.txt
  159.         echo ________________________________________>>File_Type.txt
  160.         echo MS Access(mdb)           Head Hex Code:5374616E64617264204A >>File_Type.txt
  161.         echo ________________________________________>>File_Type.txt
  162.         echo RAR Archive(rar)           Head Hex Code:52617221 >>File_Type.txt
  163.         echo ________________________________________>>File_Type.txt
  164.         echo 7Z(7-zip)           Head Hex Code:377ABCAF271C >>File_Type.txt
  165.         echo ________________________________________>>File_Type.txt
  166.         echo Wave(wav)           Head Hex Code:57415645 >>File_Type.txt
  167.         echo ________________________________________>>File_Type.txt
  168.         echo APE(ape)           Head Hex Code:4D414320960F >>File_Type.txt
  169.         echo ________________________________________>>File_Type.txt
  170.         echo MP3(mp3)           Head Hex Code:49443303 >>File_Type.txt
  171.         echo ________________________________________>>File_Type.txt
  172.         echo FLV(flv)           Head Hex Code:464C56 >>File_Type.txt
  173.         echo ________________________________________>>File_Type.txt
  174.         echo MKV(mkv)           Head Hex Code:1A45DFA3 >>File_Type.txt
  175.         echo ________________________________________>>File_Type.txt
  176.         echo AVI(avi)           Head Hex Code:41564920 >>File_Type.txt       
  177.         echo ________________________________________>>File_Type.txt
  178.         echo ASS(ass)           Head Hex Code:FFFE5B >>File_Type.txt
  179.         echo ________________________________________>>File_Type.txt
  180.         echo Real Audio(ram)           Head Hex Code:2E7261FD >>File_Type.txt
  181.         echo ________________________________________>>File_Type.txt
  182.         echo Real Media(rm)           Head Hex Code:2E524D46 >>File_Type.txt
  183.         echo ________________________________________>>File_Type.txt
  184.         echo MPEG(mpg)           Head Hex Code:000001BA >>File_Type.txt
  185.         echo ________________________________________>>File_Type.txt
  186.         echo MPEG(mpg)           Head Hex Code:000001B3 >>File_Type.txt
  187.         echo ________________________________________>>File_Type.txt
  188.         echo Quicktime(mov)           Head Hex Code:6D6F6F76 >>File_Type.txt
  189.         echo ________________________________________>>File_Type.txt
  190.         echo Windows Media(asf)           Head Hex Code:3026B2758E66CF11 >>File_Type.txt
  191.         echo ________________________________________>>File_Type.txt
  192.         echo MIDI(mid)           Head Hex Code:4D546864 >>File_Type.txt
  193.         echo ________________________________________>>File_Type.txt
  194.         goto :eof
  195. :temp
  196.         more +197 "%~f0"|debug>nul&goto :eof
  197.         e 0 ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee
  198.         rcx
  199.         10
  200.         n TEMP1.YS
  201.         w
  202.         q       
  203.        
复制代码
 楼主| 发表于 2011-10-24 00:11:53 | 显示全部楼层
最好以视频的形式一步一步讲解。在此先谢谢!
其次这个文件怎么使用? 打开后看到 请输入文件名
无论输入什么 包括Tab键 都显示 没有这样的文件 按任意键可以再试一次…
发表于 2011-10-24 09:42:01 | 显示全部楼层
最好你给报销一下往返机票,我可以抽空过去面对面的讲解。
发表于 2011-10-24 13:14:56 | 显示全部楼层
回复 3# HAT


    版主讲一下原理呗?好添加别的后缀啊
发表于 2011-10-24 13:47:02 | 显示全部楼层
回复 3# HAT


  第120行          echo JPEG(jpg)           Head Hex Code:FFD8FFFE0 >>File_Type.txt

是不是多了个'F'?
FFD8FFE0

评分

参与人数 1技术 +1 收起 理由
surup + 1 谢谢指出错误

查看全部评分

 楼主| 发表于 2011-10-24 18:39:05 | 显示全部楼层
回复 5# sxw

嗯啊 的确是多了个F
发表于 2011-10-24 19:06:40 | 显示全部楼层
额~也写过一个,原理相同,就是应对原来解决那个恶意改名的批处理丢失ini的时候没法恢复的情况,就是对头进行判定。但是也不能完全解决,比如exe和dll就相同……那个恶意批处理还记忆犹新,好像还有和Batcher的插曲啥的……叫什么垃圾清理,结果用的人都杯具了……
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 06:19 , Processed in 0.023521 second(s), 12 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表