Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for airregncmd.bat

(view source code of airregncmd.bat as plain text)

  1. @ECHO OFF
  2. IF     "%~1"=="" GOTO Syntax
  3. IF NOT "%~2"=="" GOTO Syntax
  4. ECHO.%~1| FINDSTR.EXE /R /X /I /C:"N[0-9][0-9]*[0-9A-Z]*" >NUL 2>&1 || GOTO Syntax
  5. IF NOT EXIST MASTER.txt  IF NOT EXIST "%~dp0MASTER.txt"  GOTO Download
  6. IF NOT EXIST ACFTREF.txt IF NOT EXIST "%~dp0ACFTREF.txt" GOTO Download
  7.  
  8. SETLOCAL ENABLEDELAYEDEXPANSION
  9. SET NNumber=%~1
  10. SET NNumber=%NNumber:~1%
  11. IF EXIST MASTER.txt  (SET Master=MASTER.txt)   ELSE (IF EXIST %~dps0MASTER.txt  SET Master=%~dps0MASTER.txt)
  12. IF EXIST ACFTREF.txt (SET AcftRef=ACFTREF.txt) ELSE (IF EXIST %~dps0ACFTREF.txt SET AcftRef=%~dps0ACFTREF.txt)
  13.  
  14. REM Loop through the MASTER table to find the manufacturer/model code for the specified N-number
  15. FOR /F "tokens=1,3 delims=," %%A IN (%Master%) DO (
  16. 	IF %NNumber% EQU %%A (
  17. 		REM The N-number is recognized, now loop through the ACFTREF table to convert the manufacturer/model code to meaningful text
  18. 		SET Found=1
  19. 		FOR /F "tokens=1-3 delims=," %%C IN (%AcftRef%) DO (
  20. 			IF %%B EQU %%C (
  21. 				SET Aircraft=N%NNumber%
  22. 				REM Trim trailing whitespace from manufacturer name
  23. 				FOR %%F IN (%%D) DO (
  24. 					SET Aircraft=!Aircraft! %%F
  25. 				)
  26. 				REM Trim trailing whitespace from aircraft model
  27. 				FOR %%F IN (%%E) DO (
  28. 					SET Aircraft=!Aircraft! %%F
  29. 				)
  30. 				ECHO.!Aircraft!
  31. 				ENDLOCAL
  32. 				EXIT /B 0
  33. 			)
  34. 		)
  35. 	)
  36. )
  37. ENDLOCAL
  38.  
  39. REM This part of the code will only be reached if the aircraft wasn't found, hence returncode 2
  40. EXIT /B 2
  41.  
  42.  
  43. :Download
  44. ECHO.
  45. ECHO This script requires the FAA Aircraft Registry's Releasable Aircraft Database files in the current directory.
  46. ECHO Download and unZIP the files and restart this script in the directory where the unZIPed files are located.
  47. ECHO https://www.faa.gov/licenses_certificates/aircraft_certification/aircraft_registry/releasable_aircraft_download/
  48. ECHO.
  49. CHOICE.EXE /C YN /T 5 /D N /M "Do you want to open the download page now"
  50. IF %ErrorLevel% EQU 1 (
  51. 	START https://www.faa.gov/licenses_certificates/aircraft_certification/aircraft_registry/releasable_aircraft_download/
  52. 	ECHO.
  53. 	ECHO Download and unZIP the database file, then restart this
  54. 	ECHO script in the directory where the unZIPed files are located.
  55. 	ECHO.
  56. )
  57. EXIT /B 3
  58.  
  59.  
  60. :Syntax
  61. ECHO.
  62. ECHO AirRegNCmd.cmd,  Version 1.00 for Windows
  63. ECHO Search downloaded FAA registry database files for the specified aircraft
  64. ECHO registration number ^("N-number"^)
  65. ECHO.
  66. ECHO Usage:   AirRegNCmd.cmd  Nxxx
  67. ECHO.
  68. ECHO Where:   Nxxx is a valid aircraft registration "N-number", e.g. N18906
  69. ECHO.
  70. ECHO Example: AirRegNCmd.cmd N18906
  71. ECHO          will return:
  72. ECHO          N18906 LOCKHEED 12A
  73. ECHO.
  74. ECHO Notes:   This script requires the FAA Aircraft Registry's releasable
  75. ECHO          aircraft database files either in the current directory or in this
  76. ECHO          script's parent directory. The database files can be downloaded at:
  77. ECHO          https://www.faa.gov/licenses_certificates/aircraft_certification
  78. ECHO          /aircraft_registry/releasable_aircraft_download/
  79. ECHO          You will be prompted to open the download page if the database
  80. ECHO          files aren't found.
  81. ECHO          Neither this script nor its author are associated with the FAA.
  82. ECHO          This script's return code ^("errorlevel"^) will equal 0 if the
  83. ECHO          specified aircraft registration was found, 2 if it wasn't,
  84. ECHO          3 if the database files weren't found, 1 on command line errors.
  85. ECHO.
  86. ECHO Written by Rob van der Woude
  87. ECHO https://www.robvanderwoude.com
  88. EXIT /B 1
  89.  

page last modified: 2024-04-16; loaded in 0.0211 seconds