Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: zpaolo11x on May 28, 2020, 07:44:30 AM

Title: Squirrel language: how to create a directory?
Post by: zpaolo11x on May 28, 2020, 07:44:30 AM
Is it even possible? I need to create a subdirectory to manage tags my way, I can open a file for writing using the file.nut module or directly using squirrel libraries, and the file will be created from scratch if it's not there already, but if the folder is not there, then an error is thrown.
Is there some way from a layout to create a folder?
Title: Re: Squirrel language: how to create a directory?
Post by: keilmillerjr on May 28, 2020, 09:41:52 AM
Use system command mkdir.
Title: Re: Squirrel language: how to create a directory?
Post by: zpaolo11x on May 28, 2020, 09:50:13 AM
Use system command mkdir.

I'm using

Code: [Select]
fe.plugin_command("mkdir","folderpath")

It seems to work fine on macOS, gonna check if it's cross platform compatible
Title: Re: Squirrel language: how to create a directory?
Post by: keilmillerjr on May 28, 2020, 09:55:35 AM
Use system command mkdir.

I'm using

Code: [Select]
fe.plugin_command("mkdir","folderpath")

It seems to work fine on macOS, gonna check if it's cross platform compatible

Yep. Even works in OS/2...

https://en.m.wikipedia.org/wiki/Mkdir
Title: Re: Squirrel language: how to create a directory?
Post by: zpaolo11x on May 28, 2020, 09:56:33 AM
Yep. Even works in OS/2...

https://en.m.wikipedia.org/wiki/Mkdir

Fantastic! Is that the right way to run the command?
Title: Re: Squirrel language: how to create a directory?
Post by: keilmillerjr on May 28, 2020, 11:40:35 AM
Yep. Even works in OS/2...

https://en.m.wikipedia.org/wiki/Mkdir

Fantastic! Is that the right way to run the command?

If it works, it works. However, squirrel has this feature built in with a function called system(cmd).

http://squirrel-lang.org/doc/sqstdlib3.html#d0e1931
Title: Re: Squirrel language: how to create a directory?
Post by: zpaolo11x on June 02, 2020, 01:55:23 AM
If it works, it works. However, squirrel has this feature built in with a function called system(cmd).

http://squirrel-lang.org/doc/sqstdlib3.html#d0e1931

Switched to the system(cmd) syntax and it works much better. I have a further question though: is there a way to set the value of a variable to the output of the system(cmd) command? Like
Code: [Select]
local varname = system (command)
Otherwise I'll have to make do with some output to file :D
Title: Re: Squirrel language: how to create a directory?
Post by: keilmillerjr on June 02, 2020, 02:53:00 AM
According to docs, there is no return on the system command. You can direct output to file. However, will attract wait for process to finish? Will you have to keep checking if file created?