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:
(http://img703.imageshack.us/img703/5783/g2ov.png)
(http://img812.imageshack.us/img812/4995/7bso.png)
Source:
REM =================
REM Console Settings:
REM =================
Title Filesize Truncator - By Elektro
Mode
Con Cols=150 Lines=50
CHCP 1252 1
>NUL & REM Windows-1252, Spanish-Latin.
REM =====
REM Info:
REM =====
Echo ------------------------------------------------------------------------------------------------------------
Echo This script will truncate to Zero the size of the files inside the working directory and it's subdirectories
Echo ------------------------------------------------------------------------------------------------------------
Echo Take extreme caution, truncating the filesize has the same effect as deleting the file
!! Echo -----------------------------------------------------------------------------------------
REM ====================
REM User defined values:
REM ====================
REM This value indicates the directory where to list it's file structure.
REM This value indicates the ubication of the logfile that will record info.
Set "Logfile=
%CD%\
%~n0.log"
REM This value indicates the File-Extensions to exclude during the process.
REM ( Use an ';' delimiter to separate multiple extensions )
Set "ExcludeExts=.bat;.cmd"
REM This value indicates the filenames to exclude during the process.
REM ( Use an ';' delimiter to separate multiple filenames )
Set "ExcludeNames=
%~nx0;Files.txt;Files2List.log"
REM This value indicates the files to exclude during the process.
REM ( Use an ';' delimiter to separate multiple files )
Set "ExcludeFiles=
%Logfile%"
REM This value indicates how the hidden files are threated when listing the file structure.
REM True = List files and also files with the 'hidden' attribute.
REM False = List only normal files without the 'hidden' attribute.
Set "IncludeHiddenFiles=True"
REM =====
REM Main:
REM =====
:: Warning question.
Choice /C "YN" /M "This will delete the files, you want to continue?"
:: Call Methods.
Call :
TruncateFiles "
%IncludeHiddenFiles%"
REM ========
REM Methods:
REM ========
:CreateLog
:: Create the Script Logfile and record starting info on it.
FSutil.exe File CreateNew "
%LogFile%" "0" 1
>NUL(
Echo =========================
Echo %DATE% ^| %TIME:~0,-3% Echo /\/\/\/\/\/\/\/\/\/\/\/\/
Echo [i] Working Directory...:
%WorkingDir% Echo [i] Include Hidden Files:
%IncludeHiddenFiles% Echo [i] Excluded Extensions.:
%ExcludeExts% Echo [i] Excluded Filenames..:
%ExcludeNames% Echo [i] Excluded Files......:
%ExcludeFiles% Echo [i] Log file............:
%LogFile% Echo =========================
)>"%LogFile%"
:: Display starting log info.
Type "%LogFile%" | MORE
:: Continue writting log.
(
)>>"%LogFile%"
:EndLog
(
Echo [i] Truncated Files:
%TruncatedFileCount% files.
Echo [i] Excluded Files.:
%ExcludedFileCount% files.
Echo [i] Elapsed Time...:
%ElapsedTime% )>>"%LogFile%"
:: Display ending information.
CLS
Type "%LogFile%"
:StartTimer
Set "StartingDate=
%Date%"
Set "StarttingTime=
%Time:~0,-3%"
:StopTimer
(
Echo Minutes = DateDiff
^("n", "
%StartingDate% %StarttingTime%", Now
^) )>"%TEMP%\%~n0 MinuteDiff.vbs"
For /F "Tokens=*"
%%#
In ( 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
)
:TakeOwn
(
Takeown.exe /F "%~f1"
ICacls.exe "%~f1" /Grant "%UserName%":"F"
Attrib.exe -R -A -S -H -I "%~f1"
:TruncateFiles
Echo [+] Truncating files with size greater than Zero, this operation could take some minutes long, please wait...
If /I "
%~1"
EQU "True"
(Call :
TruncateHiddenFiles) If /I "
%~1"
EQU "False"
(Call :
TruncateNormalFiles)
:TruncateNormalFiles
FOR /R "
%WorkingDir%"
%%#
in ("*"
) DO (
(
Echo "
%ExcludeExts%"
| Find.exe /I "
%%~x#" 1
>NUL 2
>&1
) && (
)
)
(
Echo "
%ExcludeNames%"
| Find.exe /I "
%%~nx#" 1
>NUL 2
>&1
) && (
)
)
(
Echo "
%ExcludeFiles%"
| Find.exe /I "
%%~f#" 1
>NUL 2
>&1
) && (
)
)
Call Echo [.] Truncating:
%%File:%WorkingDir
%=.%% FSUtil.exe File CreateNew "
%%~f#" "0" 1
>NUL Set /A "TruncatedFileCount+=1"
Call Echo %%File:%WorkingDir
%=.%%>>"%LogFile
%"
Set /A "ExcludedFileCount+=1"
)
)
)
:TruncateHiddenFiles
FOR /F "Tokens=* Delims="
%%#
in ('
Dir /B /S /A-D "
%WorkingDir%\*"'
) DO (
(
Echo "
%ExcludeExts%"
| Find.exe /I "
%%~x#" 1
>NUL 2
>&1
) && (
)
)
(
Echo "
%ExcludeNames%"
| Find.exe /I "
%%~nx#" 1
>NUL 2
>&1
) && (
)
)
(
Echo "
%ExcludeFiles%"
| Find.exe /I "
%%~f#" 1
>NUL 2
>&1
) && (
)
)
Call Echo [.] Truncating:
%%File:%WorkingDir
%=.%% FSUtil.exe File CreateNew "
%%~f#" "0" 1
>NUL Set /A "TruncatedFileCount+=1"
Call Echo %%File:%WorkingDir
%=.%%>>"%LogFile
%"
Set /A "ExcludedFileCount+=1"
)
)
)
REM ===============
REM Error Controls:
REM ===============
:CheckErrors
:: 'IncludeHiddenFiles' Value check.
If /I "
%IncludeHiddenFiles%"
NEQ "True"
If /I "
%IncludeHiddenFiles%"
NEQ "False"
( Echo [x] Error parsing parameter 'IncludeHiddenFiles',
Echo value '
%IncludeHiddenFiles%' is
not a Boolean value.
)
Saludos