Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for truename.rex

(view source code of truename.rex as plain text)

  1. /* TRUENAME.CMD                                             */
  2. /* Equivalent for MS-DOS' TRUENAME command (at least for    */
  3. /* NET USEd drives)                                         */
  4. /* Written by Rob van der Woude                             */
  5. /* http://www.robvanderwoude.com                            */
  6. /*                                                          */
  7. /* Written for both OS/2 2.1+ and Windows 95/NT with Regina */
  8. /* Rexx (Resource Kit) and Patrick TJ McPhee's RegUtil      */
  9. /* (http://www.interlog.com/~ptjm/)                         */
  10.  
  11. /* Initialize RexxUtil if necessary */
  12. if RxFuncQuery( "SysDriveMap" ) <> 0 then do
  13. 	call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  14. 	call SysLoadFuncs
  15. end
  16.  
  17. parse upper arg parameters
  18. if           parameters   = "" then call Syntax
  19. if pos( "?", parameters ) >  0 then call Syntax
  20. if pos( "/", parameters ) >  0 then call Syntax
  21. if pos( ",", parameters ) >  0 then call Syntax
  22. if pos( ";", parameters ) >  0 then call Syntax
  23. select
  24. 	when left( parameters, 2 ) = "\\" then call Syntax
  25. 	when left( parameters, 1 ) = "\" then do
  26. 		drive = left( directory( ), 2 )
  27. 		path  = parameters
  28. 	end
  29. 	when length( parameters ) < 2 then do
  30. 		drive = left( directory( ), 2 )
  31. 		path  = substr( directory( )||parameters, 3 )
  32. 	end
  33. 	when substr( parameters, 2, 1 ) = ":",
  34.            & datatype( left( parameters, 1 ), "U" ) = 1 then do
  35. 		drive = left( parameters, 2 )
  36. 		path  = substr( parameters, 3 )
  37. 	end
  38. 	otherwise do
  39. 		drive = left( directory( ), 2 )
  40. 		path  = substr( directory( )||parameters, 3 )
  41. 	end
  42. end
  43.  
  44. parse upper source os .
  45.  
  46. localdrives  = SysDriveMap( "A", "LOCAL" )
  47. if pos( drive, localdrives ) > 0 then do
  48. 	truename = drive||path
  49. 	say truename
  50. 	EXIT 0
  51. end
  52.  
  53. start = "A"
  54. do i = 65 to 90
  55. 	char = D2C( i )
  56. 	if pos( char||":", localdrives ) = 0 then leave
  57. 	start = D2C( i + 1 )
  58. end
  59.  
  60. /*
  61. do i = 1 by 1 until localdrives = ""
  62. 	parse value localdrives with local.i localdrives
  63. 	local.0 = i
  64. end
  65. */
  66.  
  67. remotedrives = SysDriveMap( start, "REMOTE" )
  68. if pos( drive, remotedrives ) > 0 then do
  69. 	tempfile = SysTempFileName( "TRUE????" )
  70. 	'@NET USE '||drive||' | find "\\" > '||tempfile
  71. 	line = linein( tempfile )
  72. 	call lineout tempfile
  73. 	parse value line with ."\\"strunc
  74. 	unc = "\\"||strunc
  75. 	if left( path, 1 ) <> "\" then do
  76. 		"@CD "||drive||" > "||tempfile
  77. 		line = linein( tempfile )
  78. 		call lineout tempfile
  79. 		path = substr( line, 3 )
  80. 	end
  81. 	call SysFileDelete tempfile
  82. 	truename = unc||path
  83. 	say truename
  84. 	EXIT 0
  85. end
  86. say "UNKNOWN"
  87. EXIT 1
  88.  
  89.  
  90. Syntax: procedure
  91. 	call SysCls
  92. 	say
  93. 	say "TrueName,  Version 1.01"
  94. 	say "Partial port of MS-DOS' TRUENAME command"
  95. 	say "Written by Rob van der Woude"
  96. 	say "http://www.robvanderwoude.com"
  97. 	say
  98. 	say "Usage:    TRUENAME { drive | path | filename }"
  99. 	say
  100. 	say "Returns:  the local name or UNC of the specified drive/path/filename"
  101. 	EXIT 1
  102. return
  103.  

page last uploaded: 2017-07-06, 12:37