Advertisement
1iJaCk

hide_meta.bat

Jun 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 13.98 KB | None | 0 0
  1. :: by JaCk | Release 08/13/2017 | https://pastebin.com/QnyiHWWq | hide_meta.bat ---- Hides "Meta" files and directories Recursively.  
  2. ::  -- "Meta" items are dictated by [func_process_meta_files]
  3.  
  4. :: Changelog
  5. :: * 08/13/2017 - Changed filtering to findstr instead off for loop to speed up processing.  Rewrote hide bunctions to support more funky dunky chark-ters
  6. :: * 07/04/2017 - Fixed issue when for .actors directory not being processed, needs to be set as an extension
  7. :: * 07/04/2017 - Fixed issue when entering Double Quoted entry into prompt
  8. :: * 07/04/2017 - Changed hide output msg to be slightly cleaner -imo
  9. :: * 07/04/2017 - Changed Prompted help msg to be slightly clearer
  10. :: + 07/04/2017 - Added "extrathumbs" to the meta list
  11. :: + 06/22/2017 - Intial Release
  12. :::::::::::::::::::::::::::::::::::::::
  13.  
  14. ::
  15. :: JK'D Blame-Game Agreement 1.0b, "Finger-Pointer Edition", written by JaCk
  16. ::
  17. ::: No Warranty, No Guarantee, No Support, AS-IS
  18. :::
  19. ::: USE AT YOUR OWN RISK
  20. ::: By sheer discretion and without notification, JaCk, retains the all rights, including exemptions, revocation of exemptions of this agreement!
  21. :::
  22. ::: By Running this script or ANY portion of it's, this script's, contents, you agree to the following:
  23. ::: - that you fully understand what these commands, expressions, functions, and/or script(s) or portions of script(s) do
  24. ::: - that you take responsibility for any actions, damages, physical losses, intellectual property losses, and/or losses of ANY kind
  25. ::: - that you take responsibility for any revenue, profits, physical gains, intellectual property gains, and/or gains of ANY kind
  26. ::: - that you DO NOT seek compensation of any kind, monies or otherwise, in ANY FORM, from previous, current and future parties; not limited to:
  27. :::    -- anyone
  28. :::    -- everyone
  29. :::    -- it's author(s)
  30. :::    -- it's contributor(s)
  31. :::    -- any beneficiaries
  32. :::    -- users
  33. :::    -- distributors
  34. ::
  35. :::::::::::::::::::::::::::::::::::::::
  36.  
  37. :::::::::::::::::::::::::::::::::::::::
  38. ::
  39. :: - Most Functions are sourced from JaCks "AVScraper.bat" which were sourced from "AVDumpme.bat"
  40. :: -- On that note, this is not the most efficient script, if you do not like that write your own.
  41. ::
  42. :: - Concepts sourced from a recollection (JaCk's brain dump) of
  43. :: -- methods found stackexchange site(s) by various users customized with JaCk's taste
  44. ::             ::    ::
  45. :::::::::::::::::::::::::::::::::::::::
  46.  
  47. @echo off && setlocal EnableDelayedExpansion
  48. rem Assigning Script Params to a variable
  49. set "params_main_script=%*"
  50.  
  51. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  52. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  53. ::::::                                                                 ::::::
  54.  ::::                        User Settings/Input                        ::::
  55. ::::::                                                                 ::::::
  56. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  57. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  58.  
  59. rem Hardcoded Path - bypassed only by passing in a parameter, default is NotSet
  60. set "var_process_dir="
  61.  
  62.  
  63. rem UTF8 support
  64. rem  Sets the console to be able to process utf8 character sets
  65. rem  Disable if you encounter weird problems
  66. rem  - Default: true
  67. rem  - Boolean: Enable  set to any of the following [yes/true/1]
  68. rem  - Boolean: Disable set to any of the following [no/false/0]
  69. set "_flag_utf8_support=true"
  70.  
  71. rem Hide any gif that matches everything except extension
  72. set "hm_filer_name_matches_gif=true"
  73.  
  74. rem Hide File/Directory filters -- file/folder endings
  75. set "hm_filer_name_ending=meta\> thumb\> thumbnail\> thumbnails\> extrafanart\> extrathumbs\> screenshots\> screenshot\> landscape\> backdrop\> clearart\> poster\> folder\> banner\> fanart\> disc\> logo\> palette\>"
  76.  
  77. rem Hide File/Directory filters --- Global match -- CAUTION - filters out when matched anywhere in dirtree/filename
  78. set "hm_filer_name_wany=archos"
  79.  
  80. rem Hide File/Directory filters --- Extension
  81. set "hm_filer_name_ext=.json\> .nfo\> .actors\> .description\> .xml\>"
  82.  
  83. rem filter exclusions
  84. set "hm_filter_ignore_items=.\-.Manga. .\-.Sound. Relation. .\\meta\\."
  85.  
  86. ::::  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  87. ::       -~-~-~-~-~-~-~-~-~-~-~-~-~-  ###  -~-~-~-~-~-~-~-~-~-~-~-~-~-       ::
  88. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  ::::
  89.  
  90.  
  91.  
  92. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  93. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  94. ::::::                                                                 ::::::
  95.  ::::                         Doo-Daads-Whatnots                        ::::
  96.  ::::                      Errochecking-Prompts-Misc                    ::::
  97. ::::::                                                                 ::::::
  98. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  100.  
  101. rem Process Booleans
  102. call :func_set_flag_booleans
  103.  
  104.  
  105. rem UTF8 Support
  106. if defined _flag_utf8_support (
  107.     call :func_char_encode_init
  108. )
  109.  
  110.  
  111. rem When Params are provided, ass-u-me that it is a Comma/QuotedSpaced/Semi-Colon separated list.
  112. rem  Even a "list" containing 1 item
  113. rem  Does not matter if items at quoted or not
  114. if defined params_main_script (
  115.     set "var_process_dir=!params_main_script!"
  116. )
  117.  
  118.  
  119. rem this help is only printed when the script is run without parameters
  120. if not defined var_process_dir (
  121.     echo/&echo/&echo/&echo/&echo/&echo/&echo/&echo/
  122.     echo/    Info: %~n0 Usage:
  123.     echo/      %~nx0 [Base Directory]
  124.     echo/
  125.     echo/     Notes:
  126.     echo/      ~ Quotes are optional
  127.     echo/      ~ Prompted input or passing parameters work the same way
  128.     echo/      ~ Directory Lists are accepted
  129.     echo/      ~ Windows environment variables also ok
  130.     echo/
  131.     echo/     Examples:
  132.     echo/       %~n0     C:\My Media\My Sub Dir
  133.     echo/       %~nx0 "C:\My Media\My Sub Dir","M:\My Personal Media\Home Videos",'S:\Hidden\Tr0n Spotting'
  134.     echo/       %~nx0 %Userprofile%\Videos
  135.     echo/
  136. )
  137.  
  138.  
  139. rem ask user input when parameters are missing
  140. if not defined var_process_dir (
  141.     echo/&echo/
  142.     set "input=!cd!"
  143.     echo/ -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  144.     echo/
  145.     echo/      Input: Enter Base Directory or
  146.     echo/            a list of Directories to process
  147.     echo/          
  148.     echo/      [Default: !input!]
  149.     echo/
  150.     echo/  -~-~- -~-~-~-~-~-~-~- -~-~-
  151.     set /p "input=Input > "
  152.     echo/ -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  153.     set "var_process_dir=!input!"
  154.     set "input="
  155. )
  156.  
  157.  
  158. rem Process the input
  159. rem   when surrounded by doublequotes, strip them as they are added in the next loop
  160. if defined var_process_dir if "!var_process_dir:~0,1!!var_process_dir:~-1,1!" equ """" (
  161.     set "var_process_dir=!var_process_dir:~1,-1!"
  162. )
  163.  
  164. rem append gif to the exlusion list as needed
  165. if defined hm_filer_name_matches_gif set hm_filter_ignore_items=.gif$ !hm_filter_ignore_items!
  166.  
  167. :: rem   Converting single quotes to double quotes
  168. :: rem   Stripping double sets of double quotes to a single set
  169. :: rem   Converting semi-colons to commas
  170. :: REM set "var_process_dir=!var_process_dir:'="!"
  171. :: REM set "var_process_dir=!var_process_dir:""="!"
  172. :: REM set "var_process_dir=!var_process_dir:""="!"
  173. :: REM set "var_process_dir=!var_process_dir:;=,!"
  174.  
  175.  
  176. rem Converts commas to Quoted Spaces and recurses through the list
  177. if defined var_process_dir (
  178.     for %%a in ("!var_process_dir:,= !") do (
  179.         call :func_process_meta_files "%%~a"
  180.     )
  181.     set "var_process_dir="
  182. ) else (
  183.     echo/    Info: No input recieved, exiting...
  184. )
  185.  
  186. if defined hm_cntr_hide (
  187.     echo/    Info: Total items hidden: !hm_cntr_hide!
  188.     set "hm_cntr_hide="
  189. )
  190.  
  191. rem UTF8 Support
  192. if defined _flag_utf8_support (
  193.     call :func_char_encode_deinit
  194.     set "_flag_utf8_support="
  195. )
  196.  
  197.  
  198. rem Scrub-de-dam
  199. if defined params_main_script (
  200.     set "params_main_script="
  201. )
  202.  
  203.  
  204. ::::  :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  205. ::       -~-~-~-~-~-~-~-~-~-~-~-~-~-  ###  -~-~-~-~-~-~-~-~-~-~-~-~-~-       ::
  206. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::  ::::
  207.  
  208.  
  209.  
  210. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  211. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  212. ::::::                                                                 ::::::
  213.  ::::                             Bunctions                             ::::
  214. ::::::                                                                 ::::::
  215. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  216. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  217. goto :eof
  218.  
  219. :::::::::::::::: :::: :::::::::::::::::
  220. rem International-love (utf8 only, otherwise, "get away from me you different, unclassified freak.  Wow, 'non-standards' really crep me out")
  221. rem  Above is a joke, No, I'm not going to explain it   ||  print Hello effing PC world && echo yes, pun intended
  222. :func_char_encode_init
  223. for /f "tokens=2 delims=:" %%c in ('chcp') do set "chcp_orig=%%c"
  224.  
  225. chcp 65001 2>nul 1>nul
  226. if not !errorlevel! equ 0 (
  227.     echo/    ERROR: CHCP: UTF8 Support unavailible
  228.     set "_flag_chcp_errored=true"
  229. )
  230.  
  231. goto :eof
  232. ::::::::::::::::::  :::::::::::::::::::
  233.  
  234.  
  235.  
  236. :::::::::::::::: :::: :::::::::::::::::
  237. rem Well it was a phan vacation, time to get back to the grind... You.. You... You UTF8 you. *teehee* *giggle*
  238. :func_char_encode_deinit
  239. if not defined _flag_chcp_errored (
  240.     chcp !chcp_orig! 1>nul
  241. ) else (
  242.     set "_flag_chcp_errored="
  243. )
  244.  
  245. goto :eof
  246. ::::::::::::::::::  :::::::::::::::::::
  247.  
  248.  
  249.  
  250. :::::::::::::::: :::: :::::::::::::::::
  251. rem Hide any items recursively
  252. rem  Usage - call func_hide_item "C:\myfolder\My file.ext"
  253. rem  Usage - call func_hide_item "C:\myfolder\My Subfolder"
  254. :func_hide_item
  255. set "params_hide_item=%*"
  256. set "params_hide_item=!params_hide_item:"=!"
  257.  
  258. rem Check item accessiblity, leave function on error
  259. if not exist "!params_hide_item!" (
  260.     echo/    Error: Hide: Unable to locate "!params_hide_item!"
  261.     goto :eof
  262. )
  263.  
  264. rem Check item hidden attribute, hide when needed
  265. dir /b /o /a:h "!params_hide_item!" 2>nul 1>nul
  266. if not !errorlevel! equ 0 (
  267.     echo/    Info: Hiding:  "!params_hide_item!"
  268.     call attrib +H /S /D /L "!params_hide_item!"
  269. )
  270.  
  271. set "params_hide_item="
  272. goto :eof
  273. ::::::::::::::::::  :::::::::::::::::::
  274.  
  275.  
  276.  
  277. :::::::::::::::: :::: :::::::::::::::::
  278. rem Hide any items recursively
  279. rem  Usage - call func_hide_item "C:\myfolder\My file.ext"
  280. rem  Usage - call func_hide_item "C:\myfolder\My Subfolder"
  281. :func_hide_pitem
  282. rem Check item accessiblity, leave function on error
  283. if not exist "%~1" (
  284.     echo/    Error: Hide: Unable to locate "%~1"
  285.     goto :eof
  286. )
  287.  
  288. rem Check item hidden attribute, hide when needed
  289. dir /b /o /a:h "%~1" 2>nul 1>nul
  290. if not !errorlevel! equ 0 (
  291.     echo/    Info: Hiding:  "%~nx1"
  292.     call attrib +H /S /D /L "%~1"
  293.     set /a "hm_cntr_hide+=1"
  294. )
  295.  
  296. goto :eof
  297. ::::::::::::::::::  :::::::::::::::::::
  298.  
  299.  
  300.  
  301. :::::::::::::::: :::: :::::::::::::::::
  302. rem Please note, when modifying the block below
  303. rem  [%%~xz] is file extension
  304. rem  [%%~nz] is file/directory name
  305. rem  [%%~fz] is full file/directory name with path
  306.  
  307. rem These two lines look for a specific string in the file/directory name.  When found [error state is 0] calls the hide function
  308. rem  echo "%%~nz" | findstr /i "archos" 2>nul 1>nul
  309. rem  if !errorlevel! equ 0 call :func_hide_item "%%~fz"
  310. REM set "params_process_meta_files=%*"
  311. REM set "params_process_meta_files=!params_process_meta_files:"=!"
  312. REM echo/    Info: Hide: Prep: "!params_process_meta_files!"
  313. REM 'dir /s /b /o:-n /a:-h "!params_process_meta_files!" 2^>nul ^| findstr /r /i /v ".gif$  .\-.Manga. .\-.Sound. Relation. .\\meta\\." 2^>nul'
  314. :func_process_meta_files
  315.  
  316. if not exist "%~1" (
  317.     echo/    Error: Unable to access "%~1"
  318.     echo/    Error: Unable to process "%~1"
  319.     goto :eof
  320. )
  321.  
  322. echo/
  323. echo/    Info: Hide: Prep: "%~1"
  324.  
  325. for /f "tokens=1* delims=" %%z in (
  326.     'dir /s /b /o:-n /a:-h "%~1" 2^>nul ^| findstr /r /i /v "!hm_filter_ignore_items!" 2^>nul'
  327. ) do (
  328.     if defined hm_filer_name_matches_gif if exist "%%~dpnz.gif" call :func_hide_pitem "%%~dpnz.gif"
  329.  
  330.     echo/"%%~nz" | findstr /r /i "!hm_filer_name_wany! !hm_filer_name_ending!" 2>nul 1>nul
  331.     if !errorlevel! equ 0 call :func_hide_pitem "%%~fz"
  332.    
  333.     echo/"%%~xz" | findstr /r /i "!hm_filer_name_ext!" 2>nul 1>nul
  334.     if !errorlevel! equ 0 call :func_hide_pitem "%%~fz"
  335. )
  336.  
  337. goto :eof
  338. ::::::::::::::::::  :::::::::::::::::::
  339.  
  340.  
  341. :::::::::::::::: :::: :::::::::::::::::
  342. rem For every variable that starts with [_flag_], check for true values and set/unset accordingly
  343. :func_set_flag_booleans
  344. for /f "tokens=1,* delims==" %%v in ('set _flag_') do (
  345.     set "_fvar_value=%%w"
  346.  
  347.               if "!_fvar_value:~0,1!" equ "1" ( set "%%v=true"
  348.     ) else if /i "!_fvar_value:~0,1!" equ "y" ( set "%%v=true"
  349.     ) else if /i "!_fvar_value:~0,1!" equ "t" ( set "%%v=true"
  350.     ) else set "%%v="
  351. )
  352. set "_fvar_value="
  353.  
  354. goto :eof
  355. ::::::::::::::::::  :::::::::::::::::::
  356.  
  357. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  358. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  359. ::::::        ::::::        ::::::        ::::::        ::::::        ::::::
  360.  ::::                        ::::          ::::                        ::::  
  361.   ::      -~-~-~-~-~-~-~      ::    ###     ::      -~-~-~-~-~-~-~      ::  
  362.  ::::                        ::::          ::::                        ::::  
  363. ::::::        ::::::        ::::::        ::::::        ::::::        ::::::
  364. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  365. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement