Post Reply 

Is it possible to create folders through script-fu?

Feb 25, 2014, 06:55
Post: #1
Is it possible to create folders through script-fu?
Basically what I was wondering is if I have to manually create folders for where frames of animation for my script is to be wrote to, or if I can set up some way to do it in the script-fu. I've got my UI making script that I've been working on done, and when I tried to set up the save path to where I'd like it to save and create a new folder, I quickly found that it doesn't.
Find all posts by this user
Quote this message in a reply
Feb 25, 2014, 08:03
Post: #2
RE: Is it possible to create folders through script-fu?
If it isn't possible, is there a plug-in that I can get to install that will allow me to do the following from the examples:

;path I want to save to but doesn't have a folder or folders existing so would fail by script-fu file
;save type functions

;folder FrameNum and LayerName would not be created before hand which is required for saving
;via script-fu
(filename "test")
(set! path (string-append "C:\\Documents and Settings\\Thomas Morse\\My Documents\\Script Made Stuff\\" LayerName "\\" FrameNum "\\" LayerName ".png") ; or whatever file I'm saving as
;then do file saving stuff
Find all posts by this user
Quote this message in a reply
Feb 25, 2014, 18:46
Post: #3
RE: Is it possible to create folders through script-fu?
Well as far as with Python-fu, I had already started to learn how to do scheme a while back, and not sure how hard it would be to relearn another scripting language. : S
Find all posts by this user
Quote this message in a reply
Feb 25, 2014, 19:33
Post: #4
RE: Is it possible to create folders through script-fu?
Ok after trying to use the make-directory function it doesn't work. : (

Is there a plug--in that I can get that would allow me to create a directory, that or the code to create a directory in python so I can make a small plugin to do it for me?
Find all posts by this user
Quote this message in a reply
Feb 26, 2014, 00:40 (This post was last modified: Feb 26, 2014 01:03 by oconzer.)
Post: #5
RE: Is it possible to create folders through script-fu?
Ok I was wondering if this would be what I'd need to do to test if the directory exists or not and then creates it:

#!/usr/bin/env python

#create a directory to save to

from gimpfu import *

import os
#import errno

def make_directory(path):
d = os.path.dirname(path)
if not os.path.exists(d):
os.makedirs(d)

register(
"python-fu-make-directory",
"Makes a directory.",
"Creates a directory based on the passed path if it doesn't exist already.",
"2014, Thomas Morse",
"February, 25 2014",
"make_directory",
"",
"*",
[
(PF_STRING, "dirname", ".")
],
[],
make_directory)

main()

Also how do you put code like you did above in the forums?
Find all posts by this user
Quote this message in a reply
Feb 26, 2014, 02:08
Post: #6
RE: Is it possible to create folders through script-fu?
I've tried running it without testing for if the directory is made, and the script I have is supposed to write multiple frames of an animation. It writes the first frame of animation just fine, then it goes to the directory creation code and breaks.

The way its set up was like the following:

loop until all layers are output
create file path
create directory <--was breaking at this step after first run
save layer as a frame

so I had to fix up the make directory code with it changed as follows:

def makedirectory(path):
try:
os.makedirs(path)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise

It works now due to the fix above. Thanks for the help, its much appreciated.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Run script on action rchav 2 1,221 Aug 13, 2018 14:57
Last Post: rchav
  Script Fu Errors Gimp 2.10.4 lightsaber jd3481 1 794 Aug 2, 2018 05:13
Last Post: paynekj
  Script-fu script to conversion pdf to image 4ever 12 14,018 Jul 17, 2018 16:01
Last Post: paynekj
  Problems with a bat script :( ThaUnknown_ 1 613 Mar 26, 2018 21:14
Last Post: paynekj
  Script-fu ordered file list vnicent 1 419 Mar 19, 2018 17:33
Last Post: paynekj

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS