Advertisement
hypnoticvalerie

Create a list of files in a Win10 folder with makelist.bat

Oct 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.93 KB | None | 0 0
  1. REM #######################################################################
  2. REM #### Folder Contents List Script for Notepad++ v1 by Valerie Vixen ####
  3. REM #######################################################################
  4. REM ### Put this in your %PATH% somewhere or add its location to %PATH% ###
  5. REM #######################################################################
  6.  
  7. CLS
  8. @ECHO Off
  9. SETLOCAL EnableDelayedExpansion
  10. SET arguments=%*
  11.  
  12. RD /S /Q %temp%\folder-list\ 2>nul
  13. MKDIR %temp%\folder-list
  14.  
  15. :check
  16. REM Checking to see if arguments were passed.
  17. IF NOT DEFINED %1 [ GOTO root ]
  18. GOTO definedfolder
  19.  
  20. :root
  21. for %%N in (.) do set WorkingFolderName=%%~nxN
  22.  
  23. @ECHO No arguments passed. Creating file in current working folder (%WorkingFolderName%).
  24.  
  25. SET ListFile=%temp%\folder-list\%WorkingFolderName%.FolderContents.txt
  26. DEL /F /Q "%cd%\%WorkingFolderName%.FolderContents.txt" 2>nul
  27. REM Cleaning up so the index file itself doesn't get listed, if it already exists.
  28. FOR %%F IN (*) DO (ECHO %%~nxF>>"%ListFile%")
  29. REM Boom! Send that list of files to the text file in TEMP!
  30. robocopy /NS /NC /NFL /NDL /NJH /NJS /J /MT:2 %temp%\folder-list "%cd%" 2>nul
  31. SET ListFile=%cd%\%WorkingFolderName%.FolderContents.txt
  32. GOTO cleanup
  33. REM Move the list file to the proper folder and head to the endgame.
  34.  
  35. :definedfolder
  36. CLS
  37. CALL DeQuote arguments
  38. REM Removing quotes from arguments.
  39. for %%N in ("%arguments%\.") do set WorkingFolderName=%%~nxN
  40. for /d %%D in ("%arguments%\.") do set WorkingFolder=%%~fD
  41. SET ListFile=%temp%\folder-list\%WorkingFolderName%.FolderContents.txt
  42. REM Defining important stuff
  43. IF EXIST "%WorkingFolder%" GOTO verified
  44. REM Does the folder defined by the user even exist? If no, then fail.
  45. REM Could also fail if folder isn't writeable.
  46. @ECHO Oops! no such folder as %WorkingFolderName%
  47. GOTO :eof
  48.  
  49. :verified
  50. DEL /F /Q "%WorkingFolder%\%WorkingFolderName%.FolderContents.txt" 2>nul
  51. REM Cleaning up so the index file itself doesn't get listed, if it already exists.
  52. for %%F in ("%WorkingFolder%\*") do (echo %%~nxF>>"%ListFile%")
  53. REM Boom! Send that list of files to the text file in TEMP!
  54. robocopy /NS /NC /NFL /NDL /NJH /NJS /J /MT:2 %temp%\folder-list "%WorkingFolder%" 2>nul
  55. SET ListFile=%WorkingFolder%\%WorkingFolderName%.FolderContents.txt
  56. @ECHO Creating contents list in %ListFile% and opening Notepad++
  57. GOTO cleanup
  58. REM Move the list file to the proper folder and head to the endgame.
  59.  
  60. :cleanup
  61. RD /S /Q %temp%\folder-list\ 2>nul
  62. IF EXIST "%ListFile%" GOTO NoteStart
  63. @ECHO Nothing to do!
  64. GOTO :eof
  65.  
  66. :NoteStart
  67. Start Notepad++ %ListFile%
  68. REM You can replace this command with
  69. REM Start Notepad %ListFile%
  70. REM or
  71. REM TYPE %listfile%
  72. REM Or whatever you want. Remove it entirely! Nothing will break.
  73. GOTO :eof
  74.  
  75. :DeQuote
  76. for /f "delims=" %%A in ('echo %%%1%%') do set %1=%%~A
  77. REM Credit to SS64.com for the "quotation strip" function.
  78. REM I found it here: https://ss64.com/nt/syntax-dequote.html
  79. Goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement