[Gambas-user] Files inside project folder

Tobias Boege taboege at ...626...
Thu Jul 24 16:46:23 CEST 2014


On Thu, 24 Jul 2014, Antonio S??nchez wrote:
> Hi
> 
> Is there any way to exec scripts inside project folder without copy it to
> another place?
> 

There are multiple ways. First, you can just execute the script from an
absolute path using Application.Path &/ "myscript".

This method, however, will fail when your project is compiled into an
executable archive (.gambas) because then there is no file actually. Since
there is no concept of a CWD in Gambas, relative paths are used to address
this issue: they identify files in your project directory, even if your
Gambas process runs from an executable archive. This is the reason why you
mostly see code that first copies project files to temporary locations
before they're passed to external processes.

If it's a script, or any data you can *pipe* into some process to have it
handled, you can also read the project file into a String and pipe it to the
process. No need to copy the file then. But IMHO, this is a little
cumbersome as you have to open your interpreter as a pipe'd Process:

  Dim hProc As Process

  hProc = Exec ["sh"] For Read
  Write #hProc, File.Load("myscript")

I don't know if this code works by copy and paste but the working pendant
should be at least very similar.

> Is there any way to copy a lot of files, or even, a folder with a lot of
> files located inside your project folder to any path in your home?
> 

As said above, you can use relative paths to address your project files.
This works transparently in Gambas, i.e. you can use this feature in any
filesystem-related function and it will work (I hope I'm not making too
strong promises here). So to list all project files recursively, try:

  Dim sRel As String

  For Each sRel In RDir(".")
    Print sRel
  Next

It's analog for specific folders. Of course you would use Copy to copy
these relative paths to somewhere.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list