Cross Platform File Paths 
Author Message
 Cross Platform File Paths

Hi Guys,

When I try to access a file inside the same folder as my application using
the following it works on my Macintosh builds, but no my PC builds, and I am
not sure why?

f = GetFolderItem ( ":Data:MICDdata.txt" )

Cheers,
Scott



Wed, 17 Dec 2003 09:28:44 GMT  
 Cross Platform File Paths


Quote:
> Hi Guys,

> When I try to access a file inside the same folder as my application using
> the following it works on my Macintosh builds, but no my PC builds, and I am
> not sure why?

> f = GetFolderItem ( ":Data:MICDdata.txt" )

> Cheers,
> Scott

Windows doesn't use colons; it uses slashes.

--
 --



Wed, 17 Dec 2003 09:41:42 GMT  
 Cross Platform File Paths


:> Hi Guys,
:>
:> When I try to access a file inside the same folder as my application using
:> the following it works on my Macintosh builds, but no my PC builds, and I am
:> not sure why?
:>
:> f = GetFolderItem ( ":Data:MICDdata.txt" )
:>
:> Cheers,
:> Scott
:>

As another respondent said, it's because the colons aren't separators on
Windows.  But more to the point, this illustrates why so many in this
newsgroup and in the RB mailing list keep repeating the refrain "don't
do that".  Instead, you should always use the parent/child methods on a
FolderItem.  Remember that a FolderItem with the path of "" will refer
to your app's folder, and a getChild("name") will refer to some file or
folder inside it, and on down.  It may seem troublesome, but it's
guaranteed to work and be cross-platform.

= Steve =
--
Steve W. Jackson,  Montgomery, Alabama
http://www.mindspring.com/~sjacksn/stevehome.html



Wed, 17 Dec 2003 12:04:34 GMT  
 Cross Platform File Paths

Quote:
> Hi Guys,

> When I try to access a file inside the same folder as my application using
> the following it works on my Macintosh builds, but no my PC builds, and I am
> not sure why?

> f = GetFolderItem ( ":Data:MICDdata.txt" )

f=getfolderitem("")
if f<>nil then
f=f.child("data")
if f<>nil and f.exists then
f=f.child("MICDdata.txt")
else
msgbox "Data Folder missing!"
end if
end if

--
PLZ Suche
Das einzige Postleitzahlensuchprogramm fr Mac OS

Download unter <http://plz.macsw.de>



Wed, 17 Dec 2003 16:57:52 GMT  
 Cross Platform File Paths
Thanks,

I would do that, but actually I am trying to make it so the application can
find the file on a CD-ROM (even when the application is copied to the
computer). See my application is meant to be able to play videos and read
data from files on a CD-ROM. I want to make it so the application can be
burned on the CD-ROM and run from it, as well as being able to run it from
the desktop (or any location on the users machine) so I can put out updates
without having to re-make CD's, so...I am doing this:

  Dim i As Integer
  Dim n As Integer

  n = ( VolumeCount - 1 )
  // search for the MICD CD-ROM by name
  // use the volume with the lowest index if multiples are found
  For i = n DownTo 0
    If InStr( Volume( i ).Name, "MICD" ) <> 0 Then
      cdVolumeName = Volume( i ).Name
    End If
  Next

  // create path to data file on the MICD CD-ROM
  cdDataFilePath = cdVolumeName + App.separator + cdDataFolder +
App.separator + cdDataFile

Where App.separator is a : or a \ depending on Mac/Pc target. Also
cdDataFolder is a constant = "Data" and cdDataFolder is a constant =
"MICDdata.txt"

Anyhow this works well on the Macintosh, it finds the volume that contains
MICD in the title of the volume, and is able to access the data file on the
CD-ROM perfectly when it is copied to the computer, and even when it is
directly on the CD-ROM.

I wish there was a way to use the de{*filter*} on the PC, then I could set a
break point and see what that variables are and figure out what is
happening. Anyhow, I am going to play around with it today and will post
what I come up with :-) I imagine my problem may be with the Volume name?
Also, given this scenario, I don't see how I could use the Parent or Child
methods?

Cheers,
Scott



Quote:

>> Hi Guys,

>> When I try to access a file inside the same folder as my application using
>> the following it works on my Macintosh builds, but no my PC builds, and I am
>> not sure why?

>> f = GetFolderItem ( ":Data:MICDdata.txt" )

> f=getfolderitem("")
> if f<>nil then
> f=f.child("data")
> if f<>nil and f.exists then
> f=f.child("MICDdata.txt")
> else
> msgbox "Data Folder missing!"
> end if
> end if



Thu, 18 Dec 2003 03:28:40 GMT  
 Cross Platform File Paths
I think I am making some progress. I can actually make it work when I hard
code the path as

D:\MICD\Data\MICDdata.txt

In addition it appears that Volume.Name returns the name of the volume as
the drive letter, for example Volume( 0 ).Name = "C:" even though it is
really "GX110 (C:)" on my computer. So my routing of looking for the volume
whos name contains "MICD" doesn't work, even though in Windows it appears as
"MICD (D:)", Volume.Name only reports the driver letter. So that is why the
path isn't valid, and becomes \Data\MICDdata.txt which of course doesn't
work.



Quote:
> Thanks,

> I would do that, but actually I am trying to make it so the application can
> find the file on a CD-ROM (even when the application is copied to the
> computer). See my application is meant to be able to play videos and read
> data from files on a CD-ROM. I want to make it so the application can be
> burned on the CD-ROM and run from it, as well as being able to run it from
> the desktop (or any location on the users machine) so I can put out updates
> without having to re-make CD's, so...I am doing this:

> Dim i As Integer
> Dim n As Integer

> n = ( VolumeCount - 1 )
> // search for the MICD CD-ROM by name
> // use the volume with the lowest index if multiples are found
> For i = n DownTo 0
>   If InStr( Volume( i ).Name, "MICD" ) <> 0 Then
>     cdVolumeName = Volume( i ).Name
>   End If
> Next

> // create path to data file on the MICD CD-ROM
> cdDataFilePath = cdVolumeName + App.separator + cdDataFolder +
> App.separator + cdDataFile

> Where App.separator is a : or a \ depending on Mac/Pc target. Also
> cdDataFolder is a constant = "Data" and cdDataFolder is a constant =
> "MICDdata.txt"

> Anyhow this works well on the Macintosh, it finds the volume that contains
> MICD in the title of the volume, and is able to access the data file on the
> CD-ROM perfectly when it is copied to the computer, and even when it is
> directly on the CD-ROM.

> I wish there was a way to use the de{*filter*} on the PC, then I could set a
> break point and see what that variables are and figure out what is
> happening. Anyhow, I am going to play around with it today and will post
> what I come up with :-) I imagine my problem may be with the Volume name?
> Also, given this scenario, I don't see how I could use the Parent or Child
> methods?

> Cheers,
> Scott




>>> Hi Guys,

>>> When I try to access a file inside the same folder as my application using
>>> the following it works on my Macintosh builds, but no my PC builds, and I am
>>> not sure why?

>>> f = GetFolderItem ( ":Data:MICDdata.txt" )

>> f=getfolderitem("")
>> if f<>nil then
>> f=f.child("data")
>> if f<>nil and f.exists then
>> f=f.child("MICDdata.txt")
>> else
>> msgbox "Data Folder missing!"
>> end if
>> end if



Thu, 18 Dec 2003 04:11:48 GMT  
 Cross Platform File Paths

What about:

dim v as folderitem
'for the volume

Quote:
>   n = ( VolumeCount - 1 )
>   // search for the MICD CD-ROM by name
>   // use the volume with the lowest index if multiples are found
>   For i = n DownTo 0

    v = Volume( i )

v=v.child(cdDataFolder)
if v<>Nil and v.exists then
v=v.child(cdDataFile)
if v<>Nil and v.exists then
exit
'you have it!
else
v=nil 'not found
end if
else
v=nil 'not found
end if

Quote:
>   Next

Mfg
Christian

--
Firewalls auf dem Mac lohnen sich IMHO nur zur statistischen
Datenerhebung, wieviele Deppen im Netz unterwegs sind.
  (Irina Rosenthal in dcsmi)
http://www.christians-software.de (Free Mac/Win software)



Thu, 18 Dec 2003 06:21:02 GMT  
 Cross Platform File Paths

Quote:
> I wish there was a way to use the de{*filter*} on the PC, then I could set a
> break point and see what that variables are and figure out what is
> happening.

use:

"For the WIN32 platform you can download the DebugView/EE for Windows
NT/9x Version 3.24, dbgv98 folder, by Mark Russinovich. It has lots of
possibilities to dump, intervene etc., and to do remote debugging
through the internet, that's cool! The address is:
http://www.*-*-*.com/ "

in conjuction with the plugin "MongoToDCon":

make in a module a globale variable:

console as MongoToDcon

in class app open:

console=new MongoToDcon//varialble globlale pour console Mac et window

so you can have anytime  and anyplace under win32 your wich perfect:

console.str="MyNiceInformation"+str(figure)
or
console.str="MyNiceInformation"+anyString

allway indicat a string ("MyfineINformation"), if figure=nil in
console.str=str(figure) you obtain a very bad reaction of the PC under
Win32  :-( crash freez objectNil ect. )

Quote:
> Anyhow, I am going to play around with it today and will post
> what I come up with :-) I imagine my problem may be with the Volume name?
> Also, given this scenario, I don't see how I could use the Parent or Child
> methods?

--
jpB, trs amicalement;
Babel Translator X 1.0      Fran?ais <=> Anglais
Conserve le sens implicite du texte et le style du Traducteur
www.chez.com/babeltranslator


Thu, 18 Dec 2003 17:34:16 GMT  
 Cross Platform File Paths

Quote:

> In addition it appears that Volume.Name returns the name of the volume as
> the drive letter, for example Volume( 0 ).Name = "C:" even though it is
> really "GX110 (C:)" on my computer. So my routing of looking for the volume
> whos name contains "MICD" doesn't work, even though in Windows it appears as
> "MICD (D:)", Volume.Name only reports the driver letter. So that is why the
> path isn't valid, and becomes \Data\MICDdata.txt which of course doesn't
> work.

You can put  a file in the rootfolder of your cdrom, and loop through
the volumes and check for the existance of this file.

Stephan



Thu, 18 Dec 2003 18:16:08 GMT  
 Cross Platform File Paths

Quote:

> burned on the CD-ROM and run from it, as well as being able to run it from
> the desktop (or any location on the users machine) so I can put out updates
> without having to re-make CD's, so...I am doing this:
>   ...
>   // create path to data file on the MICD CD-ROM
>   cdDataFilePath = cdVolumeName + App.separator + cdDataFolder +
> App.separator + cdDataFile

Please please please stop doing this.  You're fighting the system,
which is why you're finding it so difficult.  You should not use paths;
you should not try to figure out what the separator is; you should not
use GetFolderItem with anything except a file name (relative to the
application's directory).

Instead, use the .Child method.

Quote:
> Also, given this scenario, I don't see how I could use the Parent or Child
> methods?

I don't see how thish scenario changes it.  Instead of the dangerous
code above, you'd do:

  cdDataFile = cdVolume.Child(cdDataFolderName).Child(cdDataFileName)

Of course you first have to find cdVolume, but that's another issue (as
someone else suggested, the worst-case answer here is to look for a
special child of each volume).

If you do it this way, and stop trying to construct paths, your life
will suddenly become much easier -- your code will work cross-platform,
you won't run into 255-chararcter limits, your stock portfolio will
increase in value, your teeth will become brighter, etc.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Sat, 20 Dec 2003 00:57:06 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Cross platform, or platform independent fortran 90 compilers?

2. cross-platform mechanism for opening data files

3. Cross Platform File Errors

4. Copy files in cross-platform manner

5. cross platform file lock

6. ANNOUNCE: TOXFile 0.1 - cross-platform file manager

7. reading text file, cross-platform

8. How to do a file listing (cross platform) ?

9. cross platform application configuration files

10. portalocker 1.0b - Simple cross-platform (nt/posix) advisory file locking

11. Making file path control only select directory paths not file names

12. parser API style - methods take path or file vs sep methods for path and file

 

 
Powered by phpBB® Forum Software