Advertisement
SIAC

[Batch] Create List of all files inside of any carpet

May 11th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.05 KB | None | 0 0
  1. @Echo OFF
  2.  
  3.  
  4.  
  5. REM =================
  6. REM Console Settings:
  7. REM =================
  8.  
  9. Title Files2List - 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 Remove this line if have a bug; This script was build by Elektro http://foro.el-hacker.com/f82/aporte-batch-files2list-439209/
  18. REM =====
  19.  
  20. Echo+
  21. Echo  ----------------------------------------------------------------------------------------------------------------------------------
  22. Echo  This script writes a textfile containing the relative paths of the file structure at the working directory and it's subdirectories
  23. Echo  ----------------------------------------------------------------------------------------------------------------------------------
  24. Echo+
  25.  
  26.  
  27.  
  28. REM ====================
  29. REM User defined values:
  30. REM ====================
  31.  
  32. REM This value indicates the directory where to list it's file structure.
  33. Set "WorkingDir=%CD%"
  34.  
  35. REM This value indicates the resulting file list.
  36. Set "OutputFile=%CD%\Files.txt"
  37.  
  38. REM This value indicates the ubication of the logfile that will record info.
  39. Set "Logfile=%CD%\%~n0.log"
  40.  
  41. REM This value indicates the File-Extensions to exclude during the process.
  42. REM ( Use an ';' delimiter to separate multiple extensions )
  43. Set "ExcludeExts=.bat;.cmd"
  44.  
  45. REM This value indicates the filenames to exclude during the process.
  46. REM ( Use an ';' delimiter to separate multiple filenames )
  47. Set "ExcludeNames=%~nx0"
  48.  
  49. REM This value indicates the files to exclude during the process.
  50. REM ( Use an ';' delimiter to separate multiple files )
  51. Set "ExcludeFiles=%OutputFile%;%Logfile%"
  52.  
  53. REM This value indicates how the hidden files are threated when listing the file structure.
  54. REM  True = List files and also files with the 'hidden' attribute.
  55. REM False = List only normal files without the 'hidden' attribute.
  56. Set "IncludeHiddenFiles=True"
  57.  
  58.  
  59.  
  60. REM =====
  61. REM Main:
  62. REM =====
  63.  
  64. :: Call Methods.
  65. Call :CheckErrors
  66. Call :CreateLog
  67. Call :StartTimer
  68. Call :ListFiles "%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+
  84. Echo       Files 2 List
  85. Echo =========================
  86. Echo   %DATE% ^| %TIME:~0,-3%
  87. Echo /\/\/\/\/\/\/\/\/\/\/\/\/
  88. Echo+
  89. Echo [i] Working Directory...: %WorkingDir%
  90. Echo [i] Include Hidden Files: %IncludeHiddenFiles%
  91. Echo+
  92. Echo [i] Excluded Extensions.: %ExcludeExts%
  93. Echo [i] Excluded Filenames..: %ExcludeNames%
  94. Echo [i] Excluded Files......: %ExcludeFiles%
  95. Echo+
  96. Echo [i] Output file.........: %OutputFile%
  97. Echo [i] Log file............: %LogFile%
  98. Echo+
  99. Echo =========================
  100. )>"%LogFile%"
  101.  
  102. :: Display starting log info.
  103. Type "%LogFile%" | MORE
  104.  
  105. :: Continue writting log.
  106. (
  107. Echo+
  108. Echo Excluded Files:
  109. Echo ===============
  110. Echo+
  111. )>>"%LogFile%"
  112.  
  113. Goto:EOF
  114.  
  115.  
  116. :EndLog
  117. (
  118. Echo+
  119. Echo [i] Done!           | MORE
  120. Echo [i] Listed Files..: %ListedFileCount% files.
  121. Echo [i] Excluded Files: %ExcludedFileCount% files.
  122. Echo [i] Elapsed Time..: %ElapsedTime%
  123. Echo+
  124. )>>"%LogFile%"
  125.  
  126. :: Display ending information.
  127. CLS
  128. Type "%LogFile%"
  129. Goto:EOF
  130.  
  131.  
  132. :StartTimer
  133. Set "StartingDate=%Date%"
  134. Set "StarttingTime=%Time:~0,-3%"
  135. Goto :EOF
  136.  
  137.  
  138. :StopTimer
  139. (
  140.  Echo Minutes = DateDiff^("n", "%StartingDate% %StarttingTime%", Now^)
  141.  Echo WScript.Echo Minutes ^& " Minutes"
  142. )>"%TEMP%\%~n0 MinuteDiff.vbs"
  143.  
  144. For /F "Tokens=*" %%# In (
  145.     'Cscript.exe /Nologo "%TEMP%\%~n0 MinuteDiff.vbs"'
  146. ) Do (
  147.     Set "ElapsedTime=%%#"
  148. )
  149.  
  150. Goto:EOF
  151.  
  152.  
  153. :ListFiles
  154. Echo [+] Collecting files, this operation could take some minutes long, please wait...
  155. If /I "%~1" EQU "True"  (Call :ListHiddenFiles)
  156. If /I "%~1" EQU "False" (Call :ListNormalFiles)
  157. Goto:EOF
  158.  
  159.  
  160. :ListNormalFiles
  161. (FOR /R "%WorkingDir%" %%# in ("*") DO (
  162.  
  163.     Set "Exclude="
  164.  
  165.     If Defined ExcludeExts (
  166.         (
  167.             Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  168.         ) && (
  169.             Call Set "Exclude=True"
  170.         )
  171.     )
  172.  
  173.     If Defined ExcludeNames (
  174.         (
  175.             Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  176.         ) && (
  177.             Call Set "Exclude=True"
  178.         )
  179.     )
  180.  
  181.     If Defined ExcludeFiles (
  182.         (
  183.             Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  184.         ) && (
  185.             Call Set "Exclude=True"
  186.         )
  187.     )
  188.  
  189.     If Not Defined Exclude (
  190.         Set "File=%%~f#"
  191.         Call Echo %%File:%WorkingDir%=.%%
  192.         Set /A "ListedFileCount+=1"
  193.     ) Else (
  194.         Set "File=%%~f#"
  195.         Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  196.         Set /A "ExcludedFileCount+=1"
  197.     )
  198.  
  199. ))>"%OutputFile%"
  200. Goto :EOF
  201.  
  202.  
  203. :ListHiddenFiles
  204. (FOR /F "Tokens=* Delims=" %%# in ('Dir /B /S /A-D "%WorkingDir%\*"') DO (
  205.  
  206.     Set "Exclude="
  207.  
  208.     If Defined ExcludeExts (
  209.         (
  210.             Echo "%ExcludeExts%" | Find.exe /I "%%~x#" 1>NUL 2>&1
  211.         ) && (
  212.             Call Set "Exclude=True"
  213.         )
  214.     )
  215.  
  216.     If Defined ExcludeNames (
  217.         (
  218.             Echo "%ExcludeNames%" | Find.exe /I "%%~nx#" 1>NUL 2>&1
  219.         ) && (
  220.             Call Set "Exclude=True"
  221.         )
  222.     )
  223.  
  224.     If Defined ExcludeFiles (
  225.         (
  226.             Echo "%ExcludeFiles%" | Find.exe /I "%%~f#" 1>NUL 2>&1
  227.         ) && (
  228.             Call Set "Exclude=True"
  229.         )
  230.     )
  231.  
  232.     If Not Defined Exclude (
  233.         Set "File=%%~f#"
  234.         Call Echo %%File:%WorkingDir%=.%%
  235.         Set /A "ListedFileCount+=1"
  236.     ) Else (
  237.         Set "File=%%~f#"
  238.         Call Echo %%File:%WorkingDir%=.%%>>"%LogFile%"
  239.         Set /A "ExcludedFileCount+=1"
  240.     )
  241.  
  242. ))>"%OutputFile%"
  243. Goto:EOF
  244.  
  245.  
  246.  
  247. REM ===============
  248. REM Error Controls:
  249. REM ===============
  250.  
  251. :CheckErrors
  252. :: 'IncludeHiddenFiles' Value check.
  253. If /I "%IncludeHiddenFiles%" NEQ "True" If /I "%IncludeHiddenFiles%" NEQ "False" (
  254.     Echo [x] Error parsing parameter 'IncludeHiddenFiles',
  255.     Echo     value '%IncludeHiddenFiles%' is not a Boolean value.
  256.     Pause&Exit
  257. )
  258.  
  259. Goto:EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement