Create folders with files names

hi everyone,
i tried to make a script for make folders with the names of files contains in a specific folder in a selected destination.
after that i want in every folder a nuke files (nuke is a vfx program, the files are text readable) will be create with an auto setup for every shot
But that don’t work at the first step

this is my script


set sourceFolder to (choose folder with prompt "Files Folder")
set destinationFolder to (choose folder with prompt "Files Destination folder")

tell application "Finder" to set theFiles to files of sourceFolder
repeat with aFile in theFiles
	set Nom to name of aFile
	set {Nom_clr, text item delimiters} to {text item delimiters, "."}
	set customer to text item 1 of Nom
	set text item delimiters to Nom_clr
	make new folder at destinationFolder with properties {name:Nom}
end repeat
display dialog "Your folders are succefully created." buttons {"Thanks"}

can you help me please ?

Hi,

the Finder tell block must wrap the whole repeat loop, only the Finder can create a folder.
This is a version without text item delimiters


set sourceFolder to (choose folder with prompt "Files Folder")
set destinationFolder to (choose folder with prompt "Files Destination folder")

tell application "Finder"
	set theFiles to files of sourceFolder
	repeat with aFile in theFiles
		set {name:Nm, name extension:Ex} to aFile
		set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
		make new folder at destinationFolder with properties {name:Nom}
	end repeat
end tell
display dialog "Your folders are succefully created." buttons {"Thanks"}


Hi StefanK
thanks for your really fast answer, i understand why my script don’t work :wink:
Now i try to integrate the creation of a text file in every folder wih a spécific text
for the moment i only write the date in it.
this is my script

tell application "TextEdit"
	activate
	make new document
	set Nuke to current date
	set text of document 1 to Nuke as text
	set nameNuke to (aFile as string) & ".txt"
	save document 1 in nameNuke
end tell

Does it exist a way to create text files with a custom text inside without opening text editor please ?
thanks for your help

try this


property myText : "myText"
property destinationFolder : missing value

set sourceFolder to (choose folder with prompt "Files Folder")
set destinationFolder to (choose folder with prompt "Files Destination folder")

tell application "Finder"
	set theFiles to files of sourceFolder
	repeat with aFile in theFiles
		set {name:Nm, name extension:Ex} to aFile
		set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
		make new folder at destinationFolder with properties {name:Nom}
		my createTextFile(Nom)
	end repeat
end tell
display dialog "Your folders are succefully created." buttons {"Thanks"}

on createTextFile(fileName)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".txt")
		set dataStream to open for access file destinationFile with write permission
		write myText to dataStream
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile


yes you can
theFile : is a string containing the macintosh path
theContents : is a string to store in the file


try
	set fd to open for access file theFile with write permission
	set eof of fd to 0
	write theContents to fd as string
	close access fd
on error
	close access file theFile
end try

sorry I up the post, I don’t find how to do that.
I explain again my problem
I want create a text file for make a custom nuke files but the problem is applescript see the text like a code (because it’s a code) how is possible to force applescript to interpret it like a text and keep the possibility to put applescript variable inside ?
Thanks

property myText : "#! /Applications/Nuke6.1v2-32/Nuke6.1v2.app/Contents/MacOS/Nuke6.1v2 -nx
version 6.1 v2
define_window_layout_xml {<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0">
    <window x="0" y="22" w="1440" h="874" screen="0">
        <splitter orientation="1">
            <split size="910"></split>
            <splitter orientation="1">
                <split size="40"></split>
                <dock id="" hideTitles="1" activePageId="Toolbar.1">
                    <page id="Toolbar.1"></page>
                </dock>
                <split size="866"></split>
                <splitter orientation="2">
                    <split size="424"></split>
                    <dock id="" activePageId="Viewer.1">
                        <page id="Viewer.1"></page>
                    </dock>
                    <split size="424"></split>
                    <dock id="" activePageId="DAG.1">
                        <page id="DAG.1"></page>
                        <page id="Curve Editor.1"></page>
                    </dock>
                </splitter>
            </splitter>
            <split size="526"></split>
            <dock id="" activePageId="Properties.1">
                <page id="Properties.1"></page>
            </dock>
        </splitter>
    </window>
</layout>
}
Root {
 inputs 0
 name "/Users/ThOr/Desktop/nuke base.nk"
 first_frame 0
 last_frame 6200
 lock_range true
 format "2048 1556 0 0 2048 1556 1 2K_Super_35(full-ap)"
 proxy_type scale
 proxy_format "1024 778 0 0 1024 778 1 1K_Super_35(full-ap)"
}
Read {
 inputs 0
 file "/Users/ThOr/Desktop/GOT MILK/MASTER_GOTMILK_TGA/Got_Milk_MASTER_DEF-prores-25p_%05d.tga"
 format "4096 3112 0 0 4096 3112 1 4K_Super_35(full-ap)"
 first 0
 last 6200
 name Read1
 xpos 32
 ypos -174
}
Write {
 file /Users/ThOr/Desktop/render_%d05.tga
 file_type targa
 checkHashOnRead false
 name Write1
 xpos 32
 ypos -60
}
Viewer {
 input_process false
 name Viewer1
 xpos -40
 ypos -9
}"

on createTextFile(fileName)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".nk")
		set dataStream to open for access file destinationFile with write permission
		write myText to dataStream
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile

to treat the text as literal string you have to quote the double quotes with a backslash for example

→ <split size="910">

Hi again
i’ve find a solution with a huge simplification of nuke files
but I still have a problem…
in the text value, I can’t put a variable (aFile and Format)
how i can do it please ?
thanks again

property myText : "#! /Applications/Nuke6.0v7-32/Nuke6.0v7.app/Contents/MacOS/Nuke6.0v7 -nx
version 6.0 v7
Root {
 format "Format"
}
Viewer {
input_process false
 name Viewer1
}
Read {
 inputs 0
 file "aFile"
 name Read1
}
Write {
 name Write1
}"
property destinationFolder : missing value

--project files creation
on createTextFile(fileName)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".nk")
		set dataStream to open for access file destinationFile with write permission
		write myText to dataStream
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile

Split the text property into 3 parts.
The variables myFormat and myFiile must be defined as globals or local within the createTextFile() handler


property myText1 : "#! /Applications/Nuke6.0v7-32/Nuke6.0v7.app/Contents/MacOS/Nuke6.0v7 -nx
version 6.0 v7
Root {
 format "

property myText2 : "
}
Viewer {
input_process false
 name Viewer1
}
Read {
 inputs 0
 file "

property myText3 : "
 name Read1
}
Write {
 name Write1
}"

property destinationFolder : missing value

--project files creation
on createTextFile(fileName)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".nk")
		set dataStream to open for access file destinationFile with write permission
		set textToWrite to myText1 & myFormat & myText2 & myFile & myText3
		write textToWrite to dataStream
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile


A last question…
my files are empty !
the logic sounds good but nothing was written in files for a unknow reason…

An error occurred within the try block. I guess the variables myFormat and myFile aren’t properly defined

I’m sorry i don’t understand why that don’t work :confused:

i’ve read but I don’t see where the problem is (i’m a noob on applescript)
this is a part of my script

property myText1 : "#! /Applications/Nuke6.0v7-32/Nuke6.0v7.app/Contents/MacOS/Nuke6.0v7 -nx
version 6.0 v7
Root {
 format "

property myText2 : "
}
Viewer {
input_process false
 name Viewer1
}
Read {
 inputs 0
 file "

property myText3 : "
 name Read1
}
Write {
 name Write1
}"

property destinationFolder : missing value

--project files creation
on createTextFile(fileName, myFormat, myFile)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".nk")
		set dataStream to open for access file destinationFile with write permission
		set textToWrite to myText1 & myFormat & myText2 & myFile & myText3
		write textToWrite to dataStream
		tell application "Finder" to set file type of dataStream to "Nuke Project"
		tell application "Finder" to set creator type of each_file to "Kaiz'r - menthor-skillz.com © 2010"
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile

in the handler each_file is not defined and datastream is simply a pointer, not a file

the number of parameters in the handler call must match the number of parameters in the handler definition.
You have to pass also the contents of myFormat, aFile and renderFile.
Note that in this case all parameters must be strings otherwise you’ll get the next error

ok but the problem is renderFile is create later so script editor identify renderFile as not define

-- the AppleScript's name
property mytitle : "Nuke Them !"

--Nuke files format setup
set Formatsetup to choose from list {"HD", "2K_Super_35", "4K_Super_35"} with prompt "Choose your full size format :" with title mytitle
if Formatsetup is false then return
set Formatsetup to item 1 of Formatsetup
if (Formatsetup = "HD") then
	set myFormat to "1920 1080 0 0 1920 1080 1 HD"
else if (Formatsetup = "2K_Super_35") then
	set myFormat to "2048 1556 0 0 2048 1556 1 2K_Super_35(full-ap)"
else if (Formatsetup = "4K_Super_35") then
	set myFormat to "4096 3112 0 0 4096 3112 1 4K_Super_35(full-ap)"
end if

--double click operation
set sourceFolder to (choose folder with prompt "Source files Folder")
set destinationFolder to (choose folder with prompt "Nuke Project Destination Folder")
set renderFolder to (choose folder with prompt "Render Destination Folder")

--Folders creation
tell application "Finder"
	set theFiles to files of sourceFolder
	repeat with aFile in theFiles
		set {name:Nm, name extension:Ex} to aFile
		set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
		make new folder at destinationFolder with properties {name:Nom}
		make new folder at renderFolder with properties {name:Nom}
		my createTextFile(Nom, myFormat, aFile, renderFile)
	end repeat
end tell

property myText1 : "#! /Applications/Nuke6.0v7-32/Nuke6.0v7.app/Contents/MacOS/Nuke6.0v7 -nx
version 6.0 v7
Root {
 format " as string

property myText2 : "
}
Viewer {
input_process false
 name Viewer1
}
Read {
 inputs 0
 file " as string

property myText3 : "
 name Read1
}
Write {
file " as string

property myText4 : "
 name Write1
}" as string

property destinationFolder : missing value

--project files creation
on createTextFile(fileName, myFormat, aFile, renderFile)
	try
		set destinationFile to ((destinationFolder as text) & fileName & ":" & fileName & ".nk")
		set renderFile to ((renderFolder as text) & fileName & "/")
		set dataStream to open for access file destinationFile with write permission
		set textToWrite to myText1 & myFormat & myText2 & aFile & myText3 & renderFile & fileName & "_comp_%05d.tga" & myText4
		write textToWrite to dataStream
		tell application "Finder" to set file type of destinationFile to "Nuke Project"
		tell application "Finder" to set creator type of destinationFile to "Kaiz'r - menthor-skillz.com © 2010"
		close access dataStream
	on error
		try
			close access file destinationFile
		end try
	end try
end createTextFile

As renderfile is defined within the handler omit it in both the handler call and definition parameter list

I’ve test it too, the script work without bug
folders are created but no text files inside…

renderFolder isn’t defined in the handler.
Note that the scope of variables is always limited to the current handler (the main script is actually within the implicit run handler).

To make variables visible from everywhere, declare them as global or property or pass them as parameters