Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

File Handling

For general discussion related FlowStone

File Handling

Postby S1User » Wed Mar 09, 2016 5:01 am

Is there a way ti parse the existance of a file with the built in primatives?

Using the text prims to read and write files, I feel the simplicity of it is great but it doesn't seem to return anything. Am I to assume that if it doesn't trigger that keans the file doesn't exist? Would be nice if they returned some useful info.

Any help appreciated.
S1User
 
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Postby RJHollins » Wed Mar 09, 2016 9:11 am

Did you try the FIND primitive ?
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Postby S1User » Thu Mar 10, 2016 4:24 am

Not sure if that would work or not. I need to look to see if a file exists to know if to create it first, without potentially overwriting it. In other languages trying to load a file that doesn't exist returns an error so you can act on it.

I don't see a way to do that here.
S1User
 
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Postby RJHollins » Thu Mar 10, 2016 5:19 am

I think it would ...

The INPUT STRING is a PATH, there is a TRIGGER to start it.

The OUTPUT is an ARRAY [which you probably don't need]

The 'I' output can have a BOOLEAN attached to yield True/False if file exists.
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Postby Tronic » Thu Mar 10, 2016 5:45 am

Can Ruby help?

Code: Select all
if File.exist?("log.txt")
        watch 'error', "Sorry - I would be overwriting a file"
else
        file = File.open("log.txt","w")
        file.write "your text"
        file.close
end
Tronic
 
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: File Handling

Postby S1User » Thu Mar 10, 2016 6:40 pm

@ RJ: Thanks, I'll give that a try to see if it returns a 0 if the file doesn't exist.

@Tronc: That looks exactly like what I need. I haven't done much Ruby coding but I suppose I'll have to dig in using your example above. Thanks.

FWIW, I'm porting a standalone app to a VST Plugin. So far so good. Screen shot below...

http://i.imgur.com/4al6Yfo.png
S1User
 
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Postby RJHollins » Thu Mar 10, 2016 6:50 pm

@ RJ: Thanks, I'll give that a try to see if it returns a 0 if the file doesn't exist.

That's exactly what it should do.

Thanks to Tronic for the RUBY version. 8-)
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: File Handling

Postby S1User » Thu Mar 10, 2016 7:01 pm

Excellent. It works. Thanks a lot RJ.
S1User
 
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Postby S1User » Thu Mar 10, 2016 7:35 pm

Question: Is there any way to set a 'default' button for message boxes? Typically when I code I do that on messages like this, maybe set the default button as "No" (button 2 in this case with Yes/No) so the user doesn't hit ENTER on the keyboard and accidentally overwrite a file.

Here the message box appears to always default to the first button, YES in this case.

Thanks again for helping. You guys are great.
S1User
 
Posts: 58
Joined: Thu Sep 17, 2015 4:05 pm

Re: File Handling

Postby Nubeat7 » Thu Mar 10, 2016 8:57 pm

maybe this could be of interest for you

Code: Select all
File.exists?(file_path)  # returns true/false whether a path exists or not.
File.file?(file_path)  # Return true if the path exists AND is a file.
File.directory?(file_path)  # Returns true if the path exists AND is a folder.
File.delete(file_path1, file_path2, file_path3...)  #  delete files
File.join(string1, string2, string3...)  # Join strings, inserting the backslashes to make a path.
File.size(file_path) #returns filesize
File.extname(file_path) #returns the fileextension
File.rename("old_name", "new_name") #Renames the given file to the new name. Raises a SystemCallError if the file cannot be renamed.
Dir.mkdir(folder_path)  #  Create a new folder
Dir.entries(folder_path)  # Gets an array of all the file names in a given folder
Dir.delete(folder_path)  #  Delete a folder (but only if it is empty!)
Dir.exists?(folder_path) # returns true if directory exists, otherwise false
Last edited by Nubeat7 on Thu Mar 10, 2016 9:10 pm, edited 2 times in total.
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Next

Return to General

Who is online

Users browsing this forum: No registered users and 32 guests