user access to choice of drive letters


Gammatech

Recommended Posts

I have used the .FileSaveDialog where the user is going to save a single file successfully. I now want to add a routine that will save a user selectable set of files to a drive selected by the user. Most probably the drive will be a memory stick plugged into a USB port which tends to have different letters assigned almost at the whim of WINDOZE. The FileSaveDialog or something similar needs to run to get the drive and path and then a loop can load the individual file names and save them to Drive\path\FileName. Is this possible?

My first thoughts are along the lines of:

// Save to disk the selected data files
Private Count = 0
Private Count1 = 0
// first navigate to disk
FileName = File.FileSaveDialog(FileName,"C:\","*.CSV","Performance Files")
If(IsEmpty(FileName))
   // User escaped from save dialogue
   Return
Else
   // user completed save dialogue
   For(Count = 0, Count < 11, Count++)
	  If(PerformanceSet[Count])
		 TrendSavePeriod = Count + 2
		 BeginSeq(TrendMake)
		 Private Handle = File.Open(FileName,0,1,0,1)
		 For(Private Count1 = 0, Count1 < TrendRecords, Count1 ++)
			File.Write(Handle,TempStr[Count1])
		 EndFor
		 File.Flush(Handle)
		 File.Close(Handle)
	  EndIf
   EndFor
   If(PerformanceSet[11])
	  // Save entire Batch file
   EndIf
   If(PerformanceSet[12])
	  // Save entire Shift file
   EndIf
EndIf

You have to pass a File Name to the FileOpenDailog as an empty file name coming back indicates a user escape. My sequence 'TrendMake' Generates the correct filename and loads up the string array TempStr with the individual lines of data. The second loop writes each line out . I seem to need about half of the FileSaveDialog!

Any help would be appreciated.

Martin

Link to comment
Share on other sites

Yes, you can do it. Just use reverseFind() to find the last \ in the returned file name and strip off that file name. Alternatively (if you are going to write to the root), just use a combo box. There are only 26 possible drive letters unless you are going to support network logging (and then you could just map the network drive to a letter).

Link to comment
Share on other sites

Yes, I had thought of the combo box for the possible Drive letters but the user may not be aware of the drive letter if it is a removable disk. Particularly if the document is running full screen there is only the sound from Windoze as the removable drive is inserted. Is there any way to find out what drives actually exist? The FileSaveDialog only shows those that exist. I'll look at the ReverseFind suggestion, to get a Drive/Path and then pass that to my TrendMake routine. Thanks.

Martin

Link to comment
Share on other sites

There is no way I know to enumerate through current drive letters. If you query each one (using, say File.getfilepathlist() you'll trigger "Insert the CD" sort of messages on some drives. There might be a way to use getfilepathlist(), but I'm not sure what to pass it to get above c:\ There is probably something for the My Computer but I don't know what it is off hand.

Link to comment
Share on other sites

  • 1 month later...

Hi,

I have tried out the File.GetFilePathList within a For loop to interrogate every drive from A to Z

// clear existing choices from combobox

For(Private Count = 0, Count < 26, Count ++)

ReturnedPath = File.GetFilePathList(CHR(Count +65) + ":\*.")

If(!IsEmpty(ReturnedPath))

// populate combo box with available Drive choice

EndIf

EndFor

on Vista and XP at least, drives that are physically not there (A,B and F to Z) return the empty string so can easily be detected. The CD drive returns the empty string if no disk but reads it if a disk is there. Memory stick is read if there are any files but Empty string if no files. On an XP machine with Floppy drive the drive is tested (light comes on briefly) but returns empty string if no disk. I haven't tried it with a disk.

I used this to populate a combo box.

The Tree component seems to be ideal for a "Disk browser" but I can't seem to populate the Child(1)...Child(n) I only fill the TreeListA...E etc without any ability to expand or collapse the list. The Help is the same as the user manual section on Tree Lists. Can you explain a bit more how to populate tree lists with the array data returned from GetFilePathList.

Thanks,

Martin

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

With a bit of experimenting I have managed to populate a tree list component with the actual drives that exist (in my case on the trial Vista machine C: , D: & F:) Where F: is a CD drive and D: is a memory stick. I have then filled the children with the primary subfolders for the drives and I can expand or contract the children as required. Further folders below the primary subfolders do not show as the array returned from GetFilePathList only goes one folder deep. Presumably I would have to issue GetFilePathList at the SubFolder level to get any children of each SubFolder.

However, If I enter in the events panel { ? "clicked"} (without the curly braces) then clicking on ANY element of the tree causes the action. How do I track which element was clicked on and hopefully get the data that was set as the tree was built

TIA

Martin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.