Author Topic: Squirrel language: how to create a directory?  (Read 4999 times)

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1245
    • View Profile
    • My deviantart page
Squirrel language: how to create a directory?
« 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?


zpaolo11x

  • Hero Member
  • *****
  • Posts: 1245
    • View Profile
    • My deviantart page
Re: Squirrel language: how to create a directory?
« Reply #2 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

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Squirrel language: how to create a directory?
« Reply #3 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

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1245
    • View Profile
    • My deviantart page
Re: Squirrel language: how to create a directory?
« Reply #4 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?

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Squirrel language: how to create a directory?
« Reply #5 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

zpaolo11x

  • Hero Member
  • *****
  • Posts: 1245
    • View Profile
    • My deviantart page
Re: Squirrel language: how to create a directory?
« Reply #6 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

keilmillerjr

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1167
    • View Profile
Re: Squirrel language: how to create a directory?
« Reply #7 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?