Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo OFF
- REM =================
- REM Console Settings:
- REM =================
- Title Files2List - By Elektro
- Mode Con Cols=150 Lines=50
- CHCP 1252 1>NUL & REM Windows-1252, Spanish-Latin.
- REM =====
- REM Info:
- REM Remove this line if have a bug; This script was build by Elektro http://foro.el-hacker.com/f82/aporte-batch-files2list-439209/
- REM =====
- Echo+
- Echo ----------------------------------------------------------------------------------------------------------------------------------
- Echo This script writes a textfile containing the relative paths of the file structure at the working directory and it's subdirectories
- Echo ----------------------------------------------------------------------------------------------------------------------------------
- Echo+
- REM ====================
- REM User defined values:
- REM ====================
- REM This value indicates the directory where to list it's file structure.
- Set "WorkingDir=%CD%"
- REM This value indicates the resulting file list.
- Set "OutputFile=%CD%\Files.txt"
- 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"
- REM This value indicates the files to exclude during the process.
- REM ( Use an ';' delimiter to separate multiple files )
- Set "ExcludeFiles=%OutputFile%;%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 =====
- :: Call Methods.
- Call :CheckErrors
- Call :CreateLog
- Call :StartTimer
- Call :ListFiles "%IncludeHiddenFiles%"
- Call :StopTimer
- Call :EndLog
- Pause&Exit
- 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 Files 2 List
- Echo =========================
- Echo %DATE% ^| %TIME:~0,-3%
- Echo /\/\/\/\/\/\/\/\/\/\/\/\/
- Echo+
- Echo [i] Working Directory...: %WorkingDir%
- Echo [i] Include Hidden Files: %IncludeHiddenFiles%
- Echo+
- Echo [i] Excluded Extensions.: %ExcludeExts%
- Echo [i] Excluded Filenames..: %ExcludeNames%
- Echo [i] Excluded Files......: %ExcludeFiles%
- Echo+
- Echo [i] Output file.........: %OutputFile%
- Echo [i] Log file............: %LogFile%
- Echo+
- Echo =========================
- )>"%LogFile%"
- :: Display starting log info.
- Type "%LogFile%" | MORE
- :: Continue writting log.
- (
- Echo+
- Echo Excluded Files:
- Echo ===============
- Echo+
- )>>"%LogFile%"
- Goto:EOF
- :EndLog
- (
- Echo+
- Echo [i] Done! | MORE
- Echo [i] Listed Files..: %ListedFileCount% files.
- Echo [i] Excluded Files: %ExcludedFileCount% files.
- Echo [i] Elapsed Time..: %ElapsedTime%
- Echo+
- )>>"%LogFile%"
- :: Display ending information.
- CLS
- Type "%LogFile%"
- Goto:EOF
- :StartTimer
- Set "StartingDate=%Date%"
- Set "StarttingTime=%Time:~0,-3%"
- Goto :EOF
- :StopTimer
- (
- Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
- Echo WScript.Echo Minutes ^& " Minutes"
- )>"%TEMP%\%~n0 MinuteDiff.vbs"
- For /F "Tokens=*" %%# In (
- 'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
- ) Do (
- Set "ElapsedTime=%%#"
- )
- Goto:EOF
- :ListFiles
- Echo [+] Collecting files, this operation could take some minutes long, please wait...
- If /I "%~1" EQU "True" (Call :ListHiddenFiles)
- If /I "%~1" EQU "False" (Call :ListNormalFiles)
- Goto:EOF
- :ListNormalFiles
- (FOR /R "%WorkingDir%" %%# in ("*") DO (
- Set "Exclude="
- If Defined ExcludeExts (
- (
- Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Defined ExcludeNames (
- (
- Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Defined ExcludeFiles (
- (
- Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Not Defined Exclude (
- Set "File=%%~f#"
- Call Echo %%File:%WorkingDir%=.%%
- Set /A "ListedFileCount+=1"
- ) Else (
- Set "File=%%~f#"
- Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
- Set /A "ExcludedFileCount+=1"
- )
- ))>"%OutputFile%"
- Goto :EOF
- :ListHiddenFiles
- (FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /A-D "%WorkingDir%\*"') DO (
- Set "Exclude="
- If Defined ExcludeExts (
- (
- Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Defined ExcludeNames (
- (
- Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Defined ExcludeFiles (
- (
- Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
- ) && (
- Call Set "Exclude=True"
- )
- )
- If Not Defined Exclude (
- Set "File=%%~f#"
- Call Echo %%File:%WorkingDir%=.%%
- Set /A "ListedFileCount+=1"
- ) Else (
- Set "File=%%~f#"
- Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
- Set /A "ExcludedFileCount+=1"
- )
- ))>"%OutputFile%"
- Goto:EOF
- 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.
- Pause&Exit
- )
- Goto:EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement