Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. setlocal enabledelayedexpansion
  3.  
  4. :: ---- Set the window title
  5. SET title=%~n0
  6. TITLE %title%
  7.  
  8. :: ---- CODE TO VIEW STARTING DIRECTORY
  9. ECHO.
  10. ECHO "%~f0%"
  11. ECHO.
  12. ECHO.
  13. ECHO Generating File Listing of Directory:
  14. ECHO.
  15. ECHO    %1%
  16. ECHO.
  17. ECHO.   ...including all sub-directories
  18. ECHO.
  19. ECHO.
  20. PING 127.0.0.1 -n 6 > NUL
  21.  
  22.  
  23. :: ---- remove any temp files from previous session (if there)
  24. IF EXIST %temp%\TempFileList.txt DEL %temp%\TempFileList.txt /Q
  25. IF EXIST %temp%\international.reg DEL %temp%\international.reg /Q
  26. IF EXIST %temp%\FILE_LISTING_ERRORS.txt DEL %temp%\FILE_LISTING_ERRORS.txt /Q
  27.  
  28.  
  29. :: ---- Make A Progress Bar
  30. set i=1
  31. (set /P j=WORKING) < NUL
  32. (set /P j=......) < NUL
  33. :start
  34. call :DisplayProgressBar %i%
  35.  
  36.  
  37. :: ---- Defines output file  prefix, separator and extension (can be changed)
  38. set fileprefix=__FILE_LISTING
  39. set separator=__
  40. set ext=txt
  41.  
  42. :: ---- Looks for the date format used
  43. START /WAIT REGEDIT /E "%Temp%.\international.reg" "HKEY_CURRENT_USER\Control Panel\International"
  44. FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\international.reg" ^| FIND "sShortDate"') DO SET sShortDate=%%A
  45. set sShortDate=%sShortDate:"=%
  46. if %sShortDate%==dd/MM/yyyy goto startUK1
  47. if %sShortDate%==d/M/yyyy goto startUK2
  48. if %sShortDate%==d/M/yy goto startUK3
  49. if %sShortDate%==dd/MM/yy goto startUK4
  50. if %sShortDate%==d/MM/yyyy goto startUK5
  51. if %sShortDate%==d-MM-yyyy goto startUK5
  52. if %sShortDate%==MM/dd/yyyy goto startUS1
  53. if %sShortDate%==M/d/yyyy goto startUS2
  54. if %sShortDate%==M/d/yy goto startUS3
  55. if %sShortDate%==MM/dd/yy goto startUS4
  56. if %sShortDate%==yyyy-MM-dd goto startFC1
  57. if %sShortDate%==yyyy/MM/dd goto startFC1
  58. if %sShortDate%==yyyy-MM-d goto startFC5
  59. if %sShortDate%==yyyy/MM/d goto startFC5
  60. if %sShortDate%==yyyy-M-d goto startFC2
  61. if %sShortDate%==yy-M-d goto startFC3
  62. if %sShortDate%==yy-MM-dd goto startFC4
  63.  
  64. :: ---- Displays an error message and quits if the date format does not fit the ones above
  65. echo Error! Could not determine the format used for the Date.
  66. echo.
  67. echo Open the registry at "HKEY_CURRENT_USER\Control Panel\International",
  68. echo and look for the value of the key "sShortDate"
  69. echo.
  70. pause
  71. goto :EOF
  72.  
  73. :startUK1
  74. :: ---- Gets the current date from format "dd/MM/yyyy" (UK, Spanish, French environments) and convert it
  75. set YEAR=%date:~-4%
  76. set MONTH=%date:~3,2%
  77. set DAY=%date:~0,2%
  78. goto begin
  79.  
  80. :startUK2
  81. :: ---- Gets the current date from format "d/M/yyyy" (UK, Spanish, French environments) and convert it
  82. set YEAR=%date:~-4%
  83. set MONTH=%date:~7,2%
  84. set DAY=%date:~4,2%
  85. goto begin
  86.  
  87. :startUK3
  88. :: ---- Gets the current date from format "d/M/yy" (UK, Spanish, French environments) and convert it
  89. set YEAR=%date:~-2%
  90. set MONTH=%date:~7,2%
  91. set DAY=%date:~4,2%
  92. goto begin
  93.  
  94. :startUK4
  95. :: ---- Gets the current date from format "dd/MM/yy" (UK, Spanish, French environments) and convert it
  96. set YEAR=%date:~-2%
  97. set MONTH=%date:~3,2%
  98. set DAY=%date:~0,2%
  99. goto begin
  100.  
  101. :startUK5
  102. :: ---- Gets the current date from format "d/MM/yyyy" (UK, Spanish, French environments) and convert it
  103. set YEAR=%date:~-4%
  104. set MONTH=%date:~7,2%
  105. set DAY=%date:~4,2%
  106. goto begin
  107.  
  108. :startUS1
  109. :: ---- Gets the current date from format "MM/dd/yyyy" (US environment) and convert it
  110. set YEAR=%date:~-4%
  111. set MONTH=%date:~0,2%
  112. set DAY=%date:~3,2%
  113. goto begin
  114.  
  115. :startUS2
  116. :: ---- Gets the current date from format "M/d/yyyy" (US environment) and convert it
  117. set YEAR=%date:~-4%
  118. set MONTH=%date:~4,2%
  119. set DAY=%date:~7,2%
  120. goto begin
  121.  
  122. :startUS3
  123. :: ---- Gets the current date from format "M/d/yy" (US environment) and convert it
  124. set YEAR=%date:~-2%
  125. set MONTH=%date:~4,2%
  126. set DAY=%date:~7,2%
  127. goto begin
  128.  
  129. :startUS4
  130. :: ---- Gets the current date from format "MM/dd/yy" (US environment) and convert it
  131. set YEAR=%date:~-2%
  132. set MONTH=%date:~0,2%
  133. set DAY=%date:~3,2%
  134. goto begin
  135.  
  136. :startFC1
  137. :: ---- Gets the current date from format "yyyy-MM-dd" (French-Canadian environment) and convert it
  138. set YEAR=%date:~0,4%
  139. set MONTH=%date:~5,2%
  140. set DAY=%date:~8,2%
  141. goto begin
  142.  
  143. :startFC2
  144. :: ---- Gets the current date from format "yyyy-M-d" (French-Canadian environment) and convert it
  145. set YEAR=%date:~4,4%
  146. set MONTH=%date:~9,2%
  147. set DAY=%date:~12,2%
  148. goto begin
  149.  
  150. :startFC3
  151. :: ---- Gets the current date from format "yy-M-d" (French-Canadian environment) and convert it
  152. set YEAR=%date:~4,2%
  153. set MONTH=%date:~7,2%
  154. set DAY=%date:~10,2%
  155. goto begin
  156.  
  157. :startFC4
  158. :: ---- Gets the current date from format "yy-MM-dd" (French-Canadian environment) and convert it
  159. set YEAR=%date:~0,2%
  160. set MONTH=%date:~3,2%
  161. set DAY=%date:~6,2%
  162. goto begin
  163.  
  164. :startFC5
  165. :: ---- Gets the current date from format "yyyy/MM/d" (French-Canadian environment) and convert it
  166. set YEAR=%date:~4,4%
  167. set MONTH=%date:~9,2%
  168. set DAY=%date:~12,2%
  169. goto begin
  170.  
  171.  
  172.  
  173.  
  174. :begin
  175. :: ---- Counts characters in YEAR
  176. set count=1
  177. set countYEAR=%YEAR%
  178.  
  179. :loop
  180. set countYEAR=%countYEAR:~1%
  181. if "%countYEAR%"=="" goto convert
  182. set /a count=%count%+1
  183. goto loop
  184.  
  185. :convert
  186. :: ---- Converts YEAR from 2-digits to 4-digits (works until 2099)
  187. if %count%==4 goto list
  188. set YEAR=20%YEAR%
  189.  
  190. :list
  191. :: ---- Defines the date format wanted
  192. set TODAY=%YEAR%-%MONTH%-%DAY%
  193.  
  194.  
  195.  
  196.  
  197. ::      ----------- NOTES ON SETTING THE TIME - THE OPTIONS --------------------
  198. ::
  199. ::      When the hour has only 1 digit (before 10 AM), It has a space instead of a zero.
  200. ::      Therefore we need to add this code to remove that space:
  201. ::              if "%time:~0,1%"==" " set HOUR=%time: =%
  202. ::      Or this code to replace it by a zero:
  203. ::              if "%time:~0,1%"==" " set HOUR=%time: =0%
  204. ::      ------------------------------------------------------------------------
  205.  
  206.  
  207.  
  208. :: ---- Defines HOUR
  209. set HOUR=%time%
  210. if "%time:~0,1%"==" " set HOUR=%time: =0%
  211. set HOUR=%HOUR:~0,-3%
  212. set HOUR=%HOUR::=%
  213.  
  214.  
  215. :: ---- code for Progress Bar
  216. ping -n 1 127.0.0.1 > NUL
  217. set /a i = i + 1
  218. if /i %i% leq 100 goto :start
  219.  
  220.  
  221. CD %1
  222.  
  223.  
  224. :: ---- GENERATE THE TEXT FILE
  225.  
  226. ECHO. ^ >> %temp%\TempFileList.txt
  227. ECHO ^. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . >> %temp%\TempFileList.txt
  228. ECHO ^. >> %temp%\TempFileList.txt
  229. ECHO ^. FILE LISTING OF .... %1 >> %temp%\TempFileList.txt
  230. ECHO ^. >> %temp%\TempFileList.txt
  231. ECHO ^. AT TIME ............ %TODAY%-%hour% >> %temp%\TempFileList.txt
  232. ECHO ^. >> %temp%\TempFileList.txt
  233. ECHO ^. CONTENTS ........... * LISTING 1: ROOT DIRECTORY >> %temp%\TempFileList.txt
  234. ECHO ^.                      * LISTING 2: ROOT FILE >> %temp%\TempFileList.txt
  235. ECHO ^.                      * LISTING 3: ALL (SUB)DIRECTORIES AND FILES >> %temp%\TempFileList.txt
  236. ECHO ^. >> %temp%\TempFileList.txt
  237. ECHO ^. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . >> %temp%\TempFileList.txt
  238. ECHO. ^ >> %temp%\TempFileList.txt
  239. ECHO. ^ >> %temp%\TempFileList.txt
  240. ECHO. ^ >> %temp%\TempFileList.txt
  241. ECHO. ^ >> %temp%\TempFileList.txt
  242. ECHO. ^ >> %temp%\TempFileList.txt
  243. ECHO. ^ >> %temp%\TempFileList.txt
  244. ECHO. ^ >> %temp%\TempFileList.txt
  245. ECHO. ^ >> %temp%\TempFileList.txt
  246. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  247. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  248. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  249. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  250. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  251. ECHO ^----------          LISTING 1: ROOT DIRECTORY                ------------- >> %temp%\TempFileList.txt
  252. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  253. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  254. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  255. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  256. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  257. ECHO. ^ >> %temp%\TempFileList.txt
  258. DIR /A:D/B >>%temp%\TempFileList.txt 2>>%temp%\FILE_LISTING_ERRORS.txt
  259.  
  260. :: ---- code for Progress Bar
  261. ping -n 1 127.0.0.1 > NUL
  262. set /a i = i + 1
  263. if /i %i% leq 100 goto :start
  264.  
  265.  
  266. ECHO. ^ >> %temp%\TempFileList.txt
  267. ECHO. ^ >> %temp%\TempFileList.txt
  268. ECHO. ^ >> %temp%\TempFileList.txt
  269. ECHO. ^ >> %temp%\TempFileList.txt
  270. ECHO. ^ >> %temp%\TempFileList.txt
  271. ECHO. ^ >> %temp%\TempFileList.txt
  272. ECHO. ^ >> %temp%\TempFileList.txt
  273. ECHO. ^ >> %temp%\TempFileList.txt
  274. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  275. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  276. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  277. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  278. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  279. ECHO ^----------          LISTING 2: ROOT FILE                     ------------- >> %temp%\TempFileList.txt
  280. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  281. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  282. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  283. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  284. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  285. ECHO. ^ >> %temp%\TempFileList.txt
  286. DIR /A:-D/B >>%temp%\TempFileList.txt 2>>%temp%\FILE_LISTING_ERRORS.txt
  287.  
  288.  
  289. :: ---- code for Progress Bar
  290. ping -n 1 127.0.0.1 > NUL
  291. set /a i = i + 1
  292. if /i %i% leq 100 goto :start
  293.  
  294.  
  295. ECHO. ^ >> %temp%\TempFileList.txt
  296. ECHO. ^ >> %temp%\TempFileList.txt
  297. ECHO. ^ >> %temp%\TempFileList.txt
  298. ECHO. ^ >> %temp%\TempFileList.txt
  299. ECHO. ^ >> %temp%\TempFileList.txt
  300. ECHO. ^ >> %temp%\TempFileList.txt
  301. ECHO. ^ >> %temp%\TempFileList.txt
  302. ECHO. ^ >> %temp%\TempFileList.txt
  303. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  304. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  305. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  306. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  307. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  308. ECHO ^----------     LISTING 3: ALL (SUB)DIRECTORIES AND FILES     ------------- >> %temp%\TempFileList.txt
  309. ECHO ^----------                                                   ------------- >> %temp%\TempFileList.txt
  310. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  311. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  312. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  313. ECHO ^-------------------------------------------------------------------------- >> %temp%\TempFileList.txt
  314. ECHO. ^ >> %temp%\TempFileList.txt
  315. DIR /A/O/S/B >>%temp%\TempFileList.txt 2>>%temp%\FILE_LISTING_ERRORS.txt
  316.  
  317.  
  318. :: ---- code for Progress Bar
  319. ping -n 1 127.0.0.1 > NUL
  320. set /a i = i + 1
  321. if /i %i% leq 100 goto :start
  322.  
  323.  
  324.  
  325. MOVE /Y %temp%\TempFileList.txt %1\%fileprefix%%separator%%TODAY%-%hour%.%ext%
  326.  
  327. :: ---- code for Progress Bar
  328. ping -n 1 127.0.0.1 > NUL
  329. set /a i = i + 1
  330. if /i %i% leq 100 goto :start
  331.  
  332.  
  333.  
  334.  
  335. :: --------- CLEARS VARIABLE VALUES
  336. set fileprefix=
  337. set separator=
  338. set ext=
  339. set count=
  340. set countYEAR=
  341. set sShortDate=
  342. set YEAR=
  343. set MONTH=
  344. set DAY=
  345. set TODAY=
  346. set HOUR=
  347. set TIME=
  348.  
  349.  
  350.  
  351. :: ---- code for Progress Bar
  352. ping -n 1 127.0.0.1 > NUL
  353. set /a i = i + 1
  354. if /i %i% leq 100 goto :start
  355.  
  356.  
  357.  
  358. FIND /I "The directory name" %temp%\FILE_LISTING_ERRORS.txt > NUL 2>&1
  359. IF ERRORLEVEL 1 (
  360. ECHO. & ECHO. & ECHO SUCCESSFULLY COMPLETED < NUL
  361. ) ELSE (
  362. ECHO. & ECHO. & TYPE %temp%\FILE_LISTING_ERRORS.txt
  363. ECHO. & ECHO. & ECHO SUCCESSFULLY COMPLETED - WITH ABOVE ERRORS < NUL
  364. )
  365. ECHO.
  366. ECHO.
  367. ECHO PRESS ANY KEY TO EXIT . . .
  368. PAUSE > NUL
  369. IF EXIST %temp%\TempFileList.txt DEL %temp%\TempFileList.txt /Q
  370. IF EXIST %temp%\international.reg DEL %temp%\international.reg /Q
  371. IF EXIST %temp%\FILE_LISTING_ERRORS.txt DEL %temp%\FILE_LISTING_ERRORS.txt /Q
  372. EXIT
  373.  
  374.  
  375.  
  376. :: ---- looping code for Progress Bar
  377. :DisplayProgressBar
  378. (Set /P j=.) < NUL
  379. title %1%% Completed
  380. exit /b
  381. endlocal
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388. :: ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  389. :: -----------------------------------------------------------------------
  390. :: COMMAND LINE REFERENCE  -  "DIR" COMMAND
  391. :: -----------------------------------------------------------------------
  392. :: ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  393. ::
  394. ::
  395. :: DIR (command)
  396. :: ==============
  397. ::
  398. :: Displays a list of a directory's files and subdirectories. Used without parameters, dir displays the disk's volume label and serial number, followed by a list of directories and files on the disk, including their names and the date and time each was last modified. For files, dir displays the name extension and the size in bytes. Dir also displays the total number of files and directories listed, their cumulative size, and the free space (in bytes) remaining on the disk.
  399. ::
  400. ::
  401. :: Syntax
  402. :: ========
  403. ::
  404. :: dir [Drive:][Path][FileName] [...] [/p] [/q] [/w] [/d] [/a[[:]attributes]][/o[[:]SortOrder]] [/t[[:]TimeField]] [/s] [/b] [/l] [/n] [/x] [/c] [/4]
  405. ::
  406. ::
  407. :: Parameters
  408. :: ============
  409. ::
  410. :: [Drive:][Path]
  411. ::    Specifies the drive and directory for which you want to see a listing.
  412. ::    
  413. :: [FileName]
  414. ::    Specifies a particular file or group of files for which you want to see a listing.
  415. ::    
  416. :: /p
  417. ::   Displays one screen of the listing at a time. To see the next screen, press any key on the keyboard.
  418. ::  
  419. :: /q
  420. ::   Displays file ownership information.
  421. ::
  422. :: /w
  423. ::   Displays the listing in wide format, with as many as five file names or directory names on each line.
  424. ::
  425. :: /d
  426. ::   Same as /w but files are sorted by column.
  427. ::
  428. :: /a [[:] attributes]
  429. ::   Displays only the names of those directories and files with the attributes you specify. If you omit /a, dir displays the names of all files except hidden and system files. If you use /a without specifying attributes, dir displays the names of all files, including hidden and system files. The following list describes each of the values you can use for attributes. The colon (:) is optional. Use any combination of these values, and do not separate the values with spaces.
  430. ::
  431. ::
  432. ::   ------------------------------------------------------------------
  433. ::     Value                   Description
  434. ::   ------------------------------------------------------------------
  435. ::     h                       Hidden files
  436. ::     s                       System files
  437. ::     d                       Directories
  438. ::     a                       Files ready for archiving
  439. ::     r                       Read-only files
  440. ::     -h                      Files that are not hidden
  441. ::     -s                      Files other than system files
  442. ::     -d                      Files only (not directories)
  443. ::     -a                      Files that have not changed since the last backup
  444. ::     -r                      Files that are not read-only
  445. ::   ------------------------------------------------------------------
  446. ::
  447. ::
  448. :: /o [[:]SortOrder]
  449. ::   Controls the order in which dir sorts and displays directory names and file names. If you omit /o, dir displays the names in the order in which they occur in the directory. If you use /o without specifying SortOrder, dir displays the names of the directories, sorted in alphabetic order, and then displays the names of files, sorted in alphabetic order. The colon (:) is optional. The following list describes each of the values you can use for SortOrder. Use any combination of the values, and do not separate these values with white spaces.
  450. ::  
  451. ::   ---------------------------------------------------------------------
  452. ::     Value           Description
  453. ::   ---------------------------------------------------------------------
  454. ::     n               In alphabetic order by name
  455. ::     e               In alphabetic order by extension
  456. ::     d               By date and time, earliest first
  457. ::     s               By size, smallest first
  458. ::     g               With directories grouped before files
  459. ::     -n              In reverse alphabetic order by name (Z through A)
  460. ::     -e              In reverse alphabetic order by extension (.ZZZ through .AAA)
  461. ::     -d              By date and time, latest first
  462. ::     -s              By size, largest first
  463. ::     -g              With directories grouped after files
  464. ::   ---------------------------------------------------------------------
  465. ::
  466. ::
  467. :: /t [[:]TimeField]
  468. ::   Specifies which time field to display or use for sorting. The following list describes each of the values you can use for TimeField.
  469. ::  
  470. ::   -----------------------------------------------
  471. ::     Value       Description
  472. ::   -----------------------------------------------
  473. ::     c           Creation
  474. ::     a           Last access
  475. ::     w           Last written
  476. ::   -----------------------------------------------
  477. ::
  478. ::
  479. :: /s
  480. :: Lists every occurrence, in the specified directory and all subdirectories, of the specified file name.
  481. ::
  482. :: /b
  483. :: Lists each directory name or file name, one per line, including the file name extension. /b does not display heading information or a summary. /b overrides /w.
  484. ::
  485. :: /l
  486. :: Displays unsorted directory names and file names in lowercase. /l does not convert extended characters to lowercase.
  487. ::
  488. :: /n
  489. :: Displays a long list format with file names on the far right of the screen.
  490. ::
  491. :: /x
  492. :: Displays the short names generated for files on NTFS and FAT volumes. The display is the same as the display for /n, but short names are displayed after the long name.
  493. ::
  494. :: /c
  495. :: Displays the thousand separator in file sizes.
  496. ::
  497. :: /4
  498. :: Displays four-digit year format.
  499. ::
  500. :: /?
  501. :: Displays help at the command prompt.
  502. ::
  503. ::
  504. ::
  505. :: Remarks
  506. :: ========
  507. ::
  508. :: ---- Using multiple filenames ----
  509. ::     You can use multiple filenames. Separate file names with spaces, commas, or semicolons. You can use wildcard characters (that is, ? and *) in FileName to display a group of files.
  510. ::
  511. :: ---- Using wildcards ----
  512. ::     You can use wildcards (that is, ? and *) to display a list of a subset of files and subdirectories.
  513. ::
  514. :: ---- Specifying file display attributes ----
  515. ::     If you use /a with more than one value in attributes, dir displays the names of only those files with all the specified attributes. For example, if you use /a with r and -h for attributes by using either /a:r-h or /ar-h, dir displays only the names of read-only files that are not hidden.
  516. ::
  517. :: ---- Specifying file name sorting ----
  518. :: If you specify more than one SortOrder value, dir sorts the file names by the first criterion first, then by the second criterion, and so on. For example, if you use /o with the e and -s values for SortOrder by using either /o:e-s or /oe-s, dir sorts the names of directories and files by extension, with the largest first, and then displays the final result. The alphabetic sorting by extension causes file names with no extensions to appear first, then directory names, and then file names with extensions.
  519. ::
  520. :: ---- Using redirection symbols and pipes ----
  521. ::     When you use a redirection symbol (>) to send dir output to a file or a pipe (|) to send dir output to another command, use /a:-d and /b to list the file names only. You can use FileName with /b and /s to specify that dir is to search the current directory and its subdirectories for all file names that match FileName. Dir lists only the drive letter, directory name, file name, and file name extension, one path per line, for each file name it finds. Before you use a pipe for redirection, you should set the TEMP environment variable in your Autoexec.nt file.
  522. ::
  523. :: ---- Presetting dir parameters ----
  524. ::     You can preset dir parameters by including set with the DIRCMD environment variable in your Autoexec.nt file. You can use any valid combination of dir parameters with set dircmd, including the location and name of a file.
  525. ::
  526. :: For example, to use the DIRCMD environment variable to set the wide display format (that is, /w) as the default format, type the following command in your Autoexec.nt file:
  527. ::
  528. :: set dircmd=/w
  529. ::
  530. :: For a single use of the dir command, you can override a parameter by using the DIRCMD environment variable. To do so, type the parameter that you want to override at the dir command prompt, preceding the parameter with a minus sign. For example:
  531. ::
  532. :: dir /-w
  533. ::
  534. :: To change the DIRCMD default settings, type:
  535. ::
  536. :: set=NewParameter
  537. ::
  538. :: The new default settings are effective for all subsequent dir commands until you use set dircmd again or until you restart your computer.
  539. ::
  540. :: To clear all default settings, type:
  541. ::
  542. :: set dircmd=
  543. ::
  544. :: To view the current settings of the DIRCMD environment variable, type:
  545. ::
  546. :: set
  547. ::
  548. :: Set displays a list of environment variables and their settings. For more information about setting environment variables, see Related Topics.
  549. ::
  550. :: -- The dir command, with different parameters, is available from the Recovery Console.
  551. ::
  552. ::
  553. ::
  554. :: Examples
  555. :: =========
  556. ::
  557. :: To display all directories, one after the other, in alphabetical order, in wide format and pausing after each screen, make sure that the root directory is the current directory, and then type:
  558. ::
  559. :: dir /s/w/o/p
  560. ::
  561. :: Dir lists the name of the root directory, the names of the subdirectories of the root directory, and the names of the files in the root directory, including extensions. Then, dir lists the subdirectory names and file names in each subdirectory in the tree.
  562. ::
  563. ::
  564. ::
  565. :: To alter the preceding example so that dir displays the file names and extensions, but omits the directory names, type:
  566. ::
  567. :: dir /s/w/o/p/a:-d
  568. ::
  569. ::
  570. ::
  571. :: To print a directory listing, type:
  572. ::
  573. :: ir > prn
  574. ::
  575. :: When you specify prn, the directory list is sent to the printer attached to the LPT1 port. If your printer is attached to a different port, you must replace prn with the name of the correct port.
  576. ::
  577. :: You can also redirect output of the dir command to a file by replacing prn with a file name. You can also type a path. For example, to direct dir output to the file Dir.doc in the Records directory, type:
  578. ::
  579. :: dir > \records\dir.doc
  580. ::
  581. :: If Dir.doc does not exist, dir creates it, unless the Records directory does not exist. In that case, the following message appears:
  582. ::
  583. :: File creation error
  584. ::
  585. ::
  586. ::
  587. :: To display a list of all the file names with the .txt extension in all directories on drive C, type:
  588. ::
  589. :: dir c:\*.txt /w/o/s/p
  590. ::
  591. :: Dir displays, in wide format, an alphabetized list of the matching file names in each directory and pauses each time the screen fills up, until you press a key to continue.
  592. ::
  593. ::
  594. ::
  595. :: Formatting legend
  596. :: ===================
  597. ::
  598. :: --------------------------------------------------------------------------------------------------------------------------------
  599. :: Format                                                                         Meaning
  600. :: --------------------------------------------------------------------------------------------------------------------------------
  601. :: Italic                                                                         Information that the user must supply
  602. :: Bold                                                                            Elements that the user must type exactly as shown
  603. :: Ellipsis (...)                                                                 Parameter that can be repeated several times in a command line
  604. :: Between brackets ([])                                                          Optional items
  605. :: Between braces ({}); choices separated by pipe (|). Example: {even|odd}       Set of choices from which the user must choose only one
  606. :: Courier font                                                                   Code or program output
  607. ::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement