// character inside a string (for directory names)

I tried to use a '' inside a string but when I write e.g.

str = "D:\\Info\\battery_status.txt" 

then the result is

"D:Infobattery_status.txt"

How can I use directory characters (or backslashes) inside a string?

Problem solved: it seems a ‘/’ (forward slash) also works (with Windows using GPScript).

(leaving the question/answer for others running into the same issue).

The forward slash works inside the underlying Windows OS as a path separator.
It is really only in the user interface, I,e, those explorer windows, where they use a backslash.

And it’s all due to a design problem going back to the original DOS before directories we’re available.

The forward slash was used to separate options from other parameters. So when file folders were added, they couldn’t use a forward slash in DOS and so they used a backslash and screwed everybody!

1 Like

Nice background story. I didn’t know about it.
At work I’m using Linux mostly and in windows it’s barely needed to type paths, so I’m more used to forward slashes than backward slashes.

It’s also the case that the syntax you use in a programming language to represent a path can be arbitrary.
In C, for example, if you want to use Windows backslashes for paths (and you don’t have to has forward slashes will work there too) you have to use two backslashes because C uses the backslash as an escape character.

But there would have been nothing to stop me from defining a completely different character for path separators in GPScript, e.g.

!a!b!c

as long as the GPScript runtime system converted those exclamation points back to forward slashes.

1 Like

Yes, I’m used for two backslaches (and in the documentation for getting the quotation mark (") it is mentioned a backslash is needed, that’s why I first tried the double backslash).

Where in the documentation?

Introduction to GPScript for Gig Performer 4

Like many languages, a string constant is simply a sequence of characters bracketed with the double-quote character ("). If you need to include a double-quote inside your string, you can use the backslash character to escape the quote.

“This is a string containing an embedded " double-quote”

Ah yes, that’s correct — however that backslash is only for escaping the double quote character, it’s not a general escape character.

(GP Script is not C :slight_smile: )

I noticed, but I like the ‘/’ directly even better :slight_smile:

I still found an issue with the ‘/’ … When using as file path argument for other application (like I want to play an MP3), the forward slashes are not recognized by e.g. VLC Media Player, and I really need a backward slash.

However, I found a tricky way to get one :slight_smile:
I need to clean up the code (to store the BACKSLASH character in a generic place) and make a sort of File Join function, but as proof of concept it works. I extract the backslash from the function GigPerformerDocumentsFolder(). Now when I hit key 25 (controller key), the MP3 is played.

On WidgetValueChanged(newValue : double) from C25Button
    var BACKSLASH : string
		documentsFolder : string = GigPerformerDocumentsFolder()
		length : integer = Length(documentsFolder)
		argument : string
		
	Debug(DEBUG_LEVEL_HEADER, "> on C25Button()")
	
	BACKSLASH = CopySubstring(documentsFolder, length - 1, 1)
	
	argument = "D:" + BACKSLASH + "Info" + BACKSLASH + 
	  "MP3" + BACKSLASH + "Intwine - Cruel Man Alt.mp3"
	 Print(argument)
	EA_AddArgument(VlcMediaPlayer, argument)
	EA_Start(VlcMediaPlayer)

	Debug(DEBUG_LEVEL_HEADER, "< on C25Button()")
End

The argument is now:

D:\Info\P3\Intwine - Cruel Man Alt.mp3

Please submit that one to bug tracking….we do need to be able to work with shelling out proper

1 Like

I will do next week, during weekends no access to a computer.

Created: http://bugs.gigperformer.com:29846/issue/GP4Beta-1472/Backslash-for-directories-unavailable-inside-GPScript

Is there a reason you didn’t just use a heredoc?
For example,

Initialization
var
   filename : String = <<<D:\Info\MP3\Intwine - Cruel Man Alt.mp3>>>      
   Print(filename)   
End

screenshot_6610

1 Like

Thanks, this is much cleaner, I thought the heredoc was for multi line strings.

A multi-line string is allowed to have 1 line :slight_smile:

1 Like

I see that now. I will change my script accordingly :slight_smile:

OK - except for those specific features where shelling out to an application requires backslashes, you should still use forward slash for directory paths — that makes it easier to be cross-platform compatible.

1 Like

I completely agree to that … the example I used (the mp3) is meant as argument for VLC which cannot handle forward slashes.