Author Topic: How to discover the newly assigned USB drive letter?  (Read 398 times)

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1435
  • Karma: +28/-0
    • View Profile
How to discover the newly assigned USB drive letter?
« on: May 14, 2025, 05:50:11 am »
I'm using a little nifty REXX script to download pics off of my DSLR's memory card:

- issue the LVM rediscover attached media with '@LVM.EXE /RediscoverPRM'
- if no errors encountered start doing the copy

My problem is that when I created that script I never attempted to figure out what that removable media assigned drive letter is...it was simpler to just use a static name (used to be drive 'W:' and assigned to the disk with LVM) and run with it.

Well, recently I added a few NAS shares to my NetDrive and happened to map this to the drive letter which was previously assigned to the USB storage media card. Now my script doesn't work b/c that old drive letter is no longer usable and the USB stuff is assigned 'D:' instead.

OK, seems simple, but where the heck do I even start with querrying this in REXX?

I took a stab at this by reading through Alex Taylor's "RxLVM Library Reference - Version 0.5.1 - March 18, 2007", but that's really about all sorts of disk functions, so not what I'm looking for.

Any other references I could look up for this functionality?

Thanks!
« Last Edit: May 14, 2025, 02:26:48 pm by Dariusz Piatkowski »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5391
  • Karma: +128/-1
    • View Profile
Re: How to discover the newly assigned USB drive letter?
« Reply #1 on: May 14, 2025, 06:56:43 am »
Use LVM to change the cards drive letter? Pick a high one and probably won't need to change it again.
Otherwise you'll have to figure out how to query LVM.

Neil Waldhauer

  • Hero Member
  • *****
  • Posts: 1124
  • Karma: +30/-0
    • View Profile
    • Blonde Guy
Re: How to discover the newly assigned USB drive letter?
« Reply #2 on: May 14, 2025, 03:25:31 pm »
Code: [Select]
x = SysDriveMap()
externalDiskLetter = ''
do while x <> ''
   parse var x this x
   i = SysDriveInfo(this)
   parse var i letter free total label
   if strip(label) = 'Blue 2TB' | strip(label) = 'Red 2TB' then do
      externalDiskLetter = strip(letter)
   end
end
Expert consulting for ArcaOS, OS/2 and eComStation
http://www.blondeguy.com

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 332
  • Karma: +7/-0
    • View Profile
Re: How to discover the newly assigned USB drive letter?
« Reply #3 on: May 14, 2025, 08:37:31 pm »
One of the new functions in the REXXUTIL.DLL from Object-Oriented REXX may also help you:

SysFileSystemType
get the name of the file system for a drive

Example

  cfs = SysFileSystemType('C:')
  efs = SysFileSystemType('E:')
  SAY 'The file system on drive C: is' cfs
  SAY 'The file system on drive E: is' efs

The following is a sample of output from this example:

  The file system on drive C: is HPFS
  The file system on drive E: is JFS

Rich Walsh

  • Sr. Member
  • ****
  • Posts: 401
  • Karma: +30/-0
  • ONU! (OS/2 is NOT Unix!)
    • View Profile
Re: How to discover the newly assigned USB drive letter?
« Reply #4 on: May 15, 2025, 04:14:37 am »
No need to get fancy here...

SysDriveMap() before calling LVM.
SysDriveMap() after calling LVM.
What changed?

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 332
  • Karma: +7/-0
    • View Profile
Re: How to discover the newly assigned USB drive letter?
« Reply #5 on: May 15, 2025, 10:04:40 pm »
No need to get fancy here...

SysDriveMap() before calling LVM.
SysDriveMap() after calling LVM.
What changed?

something like:

Code: [Select]
/* Comment */
...
before = SysDriveMap()
'@LVM.EXE /RediscoverPRM'
after = SysDriveMap()
DO i = 1 TO WORDS( after )
  IF 0 = POS( SUBWORD( after, i, 1 ), before )  THEN
    SAY SUBWORD( after, i, 1 ) "must be the drive we're looking for!"
END

Nice!