elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [APORTE] [BATCH] Filesize Truncator
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [APORTE] [BATCH] Filesize Truncator  (Leído 1,424 veces)
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.810



Ver Perfil
[APORTE] [BATCH] Filesize Truncator
« en: 14 Abril 2014, 05:01 am »

Filesize Truncator

Este Script trunca el tamaño de los archivos que estén en el directorio de trabajo actual y en sus subdirectorios.
Nota: El directorio y otras propiedades se pueden modificar en las variables documentadas del código.

En realidad lo que hace es eliminar permanentemente el archivo, y luego se crea un archivo de 0 bytes con el mismo nombre y en la misma ubicación que el que se borró.

Esto es util por ejemplo si necesitamos crear una estructura de carpetas y archivos pero estos pesan demasiado tamaño y solo necesitamos mantener los nombres de los archivos y sus ubicaciones...

El Script tiene 2 métodos de búsqueda de archivos, el modo normal y el modo que incluye archivos ocultos.

Imágenes:




Source:
Código
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title Filesize Truncator - By Elektro
  10. Mode Con Cols=150 Lines=50
  11. CHCP 1252 1>NUL & REM Windows-1252, Spanish-Latin.
  12.  
  13.  
  14.  
  15. REM =====
  16. REM Info:
  17. REM =====
  18.  
  19. Echo  ------------------------------------------------------------------------------------------------------------
  20. Echo  This script will truncate to Zero the size of the files inside the working directory and it's subdirectories
  21. Echo  ------------------------------------------------------------------------------------------------------------
  22. Echo  Take extreme caution, truncating the filesize has the same effect as deleting the file !!
  23. Echo  -----------------------------------------------------------------------------------------
  24.  
  25.  
  26.  
  27. REM ====================
  28. REM User defined values:
  29. REM ====================
  30.  
  31. REM This value indicates the directory where to list it's file structure.
  32. Set "WorkingDir=%CD%"
  33.  
  34. REM This value indicates the ubication of the logfile that will record info.
  35. Set "Logfile=%CD%\%~n0.log"
  36.  
  37. REM This value indicates the File-Extensions to exclude during the process.
  38. REM ( Use an ';' delimiter to separate multiple extensions )
  39. Set "ExcludeExts=.bat;.cmd"
  40.  
  41. REM This value indicates the filenames to exclude during the process.
  42. REM ( Use an ';' delimiter to separate multiple filenames )
  43. Set "ExcludeNames=%~nx0;Files.txt;Files2List.log"
  44.  
  45. REM This value indicates the files to exclude during the process.
  46. REM ( Use an ';' delimiter to separate multiple files )
  47. Set "ExcludeFiles=%Logfile%"
  48.  
  49. REM This value indicates how the hidden files are threated when listing the file structure.
  50. REM  True = List files and also files with the 'hidden' attribute.
  51. REM False = List only normal files without the 'hidden' attribute.
  52. Set "IncludeHiddenFiles=True"
  53.  
  54.  
  55.  
  56. REM =====
  57. REM Main:
  58. REM =====
  59.  
  60. :: Warning question.
  61. Call :CreateLog
  62. Choice /C "YN" /M "This will delete the files, you want to continue?"
  63. If %ErrorLevel% NEQ 1 (Exit)
  64.  
  65. :: Call Methods.
  66. Call :CheckErrors
  67. Call :StartTimer
  68. Call :TruncateFiles "%IncludeHiddenFiles%"
  69. Call :StopTimer
  70. Call :EndLog
  71. Pause&Exit
  72.  
  73.  
  74.  
  75. REM ========
  76. REM Methods:
  77. REM ========
  78.  
  79. :CreateLog
  80. :: Create the Script Logfile and record starting info on it.
  81. FSutil.exe File CreateNew "%LogFile%" "0" 1>NUL
  82. (
  83. Echo    Filesize Truncator
  84. Echo =========================
  85. Echo   %DATE% ^| %TIME:~0,-3%
  86. Echo /\/\/\/\/\/\/\/\/\/\/\/\/
  87. Echo [i] Working Directory...: %WorkingDir%
  88. Echo [i] Include Hidden Files: %IncludeHiddenFiles%
  89. Echo [i] Excluded Extensions.: %ExcludeExts%
  90. Echo [i] Excluded Filenames..: %ExcludeNames%
  91. Echo [i] Excluded Files......: %ExcludeFiles%
  92. Echo [i] Log file............: %LogFile%
  93. Echo =========================
  94. )>"%LogFile%"
  95.  
  96. :: Display starting log info.
  97. Type "%LogFile%" | MORE
  98.  
  99. :: Continue writting log.
  100. (
  101. Echo Excluded Files:
  102. Echo ===============
  103. )>>"%LogFile%"
  104.  
  105. Goto:EOF
  106.  
  107.  
  108. :EndLog
  109. (
  110. Echo [i] Done!
  111. Echo [i] Truncated Files: %TruncatedFileCount% files.
  112. Echo [i] Excluded Files.: %ExcludedFileCount% files.
  113. Echo [i] Elapsed Time...: %ElapsedTime%
  114. )>>"%LogFile%"
  115.  
  116. :: Display ending information.
  117. CLS
  118. Type "%LogFile%"
  119. Goto:EOF
  120.  
  121.  
  122. :StartTimer
  123. Set "StartingDate=%Date%"
  124. Set "StarttingTime=%Time:~0,-3%"
  125. Goto :EOF
  126.  
  127.  
  128. :StopTimer
  129. (
  130. Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  131. Echo WScript.Echo Minutes ^& " Minutes"
  132. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  133.  
  134. For /F "Tokens=*" %%# In (
  135. 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  136. ) Do (
  137. Set "ElapsedTime=%%#"
  138. )
  139.  
  140. Goto:EOF
  141.  
  142.  
  143. :TakeOwn
  144. (
  145. Takeown.exe /F "%~f1"
  146. ICacls.exe "%~f1" /Grant "%UserName%":"F"
  147. Attrib.exe -R -A -S -H -I "%~f1"
  148. )>NUL || (Exit /B 1)
  149. Goto:EOF
  150.  
  151.  
  152. :TruncateFiles
  153. Echo [+] Truncating files with size greater than Zero, this operation could take some minutes long, please wait...
  154. If /I "%~1" EQU "True"  (Call :TruncateHiddenFiles)
  155. If /I "%~1" EQU "False" (Call :TruncateNormalFiles)
  156. Goto:EOF
  157.  
  158.  
  159. :TruncateNormalFiles
  160. FOR /R "%WorkingDir%" %%# in ("*") DO (
  161.  
  162. If %%~z# NEQ 0 (
  163.  
  164. Set "Exclude="
  165.  
  166. If Defined ExcludeExts (
  167. (
  168. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  169. ) && (
  170. Call Set "Exclude=True"
  171. )
  172. )
  173.  
  174. If Defined ExcludeNames (
  175. (
  176. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  177. ) && (
  178. Call Set "Exclude=True"
  179. )
  180. )
  181.  
  182. If Defined ExcludeFiles (
  183. (
  184. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  185. ) && (
  186. Call Set "Exclude=True"
  187. )
  188. )
  189.  
  190. If Not Defined Exclude (
  191. Set "File=%%~f#"
  192. Call Echo [.] Truncating: %%File:%WorkingDir%=.%%
  193. Call :TakeOwn "%%~f#"
  194. Del /Q "%%~f#"
  195. FSUtil.exe File CreateNew "%%~f#" "0" 1>NUL
  196. Set /A "TruncatedFileCount+=1"
  197. ) Else (
  198. Set "File=%%~f#"
  199. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  200. Set /A "ExcludedFileCount+=1"
  201. )
  202. )
  203. )
  204. Goto:EOF
  205.  
  206.  
  207. :TruncateHiddenFiles
  208. FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /A-D "%WorkingDir%\*"') DO (
  209.  
  210. If %%~z# NEQ 0 (
  211.  
  212. Set "Exclude="
  213.  
  214. If Defined ExcludeExts (
  215. (
  216. Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  217. ) && (
  218. Call Set "Exclude=True"
  219. )
  220. )
  221.  
  222. If Defined ExcludeNames (
  223. (
  224. Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  225. ) && (
  226. Call Set "Exclude=True"
  227. )
  228. )
  229.  
  230. If Defined ExcludeFiles (
  231. (
  232. Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  233. ) && (
  234. Call Set "Exclude=True"
  235. )
  236. )
  237.  
  238. If Not Defined Exclude (
  239. Set "File=%%~f#"
  240. Call Echo [.] Truncating: %%File:%WorkingDir%=.%%
  241. Call :TakeOwn "%%~f#"
  242. Del /Q "%%~f#"
  243. FSUtil.exe File CreateNew "%%~f#" "0" 1>NUL
  244. Set /A "TruncatedFileCount+=1"
  245. ) Else (
  246. Set "File=%%~f#"
  247. Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  248. Set /A "ExcludedFileCount+=1"
  249. )
  250.  
  251. )
  252. )
  253. Goto:EOF
  254.  
  255.  
  256.  
  257. REM ===============
  258. REM Error Controls:
  259. REM ===============
  260.  
  261. :CheckErrors
  262. :: 'IncludeHiddenFiles' Value check.
  263. If /I "%IncludeHiddenFiles%" NEQ "True" If /I "%IncludeHiddenFiles%" NEQ "False" (
  264. Echo [x] Error parsing parameter 'IncludeHiddenFiles',
  265. Echo     value '%IncludeHiddenFiles%' is not a Boolean value.
  266. Pause&Exit
  267. )
  268.  
  269. Goto:EOF

Saludos


« Última modificación: 14 Abril 2014, 05:12 am por Eleкtro » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Batch] Un pequeño aporte « 1 2 »
Scripting
najmuddin 13 7,564 Último mensaje 25 Junio 2008, 21:21 pm
por najmuddin
[Batch] Aporte Generador Diccionario
Scripting
Geormarsch 9 6,777 Último mensaje 18 Septiembre 2012, 14:27 pm
por Geormarsch
[Batch] Aporte, Soy electronico
Scripting
Geormarsch 5 3,833 Último mensaje 9 Enero 2012, 10:24 am
por leogtz
[APORTE] [BATCH] Acentos en los programas Batch - La mejor solución
Scripting
Príncipe_Azul 5 12,140 Último mensaje 2 Mayo 2014, 00:09 am
por cyberalejo17
[APORTE] [BATCH] Files2List
Scripting
Eleкtro 2 1,978 Último mensaje 14 Abril 2014, 04:40 am
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines