Skip to main content
Participant
June 14, 2006
Question

Save Text into a File

  • June 14, 2006
  • 4 replies
  • 1286 views
Hello,

I created a little script which extracts metadata from a selection and stores it in a string. Now I just would like to save the string in a text-file in the current foldert, but ...
any hint would be very kind.

// test string
myText = "save this";

// create new File
myFile = new File("test.txt");

// write into the file
myFile.write(myText);

and close it
myFile.close(myText);

thanks pepe
This topic has been closed for replies.

4 replies

_pjuerg_Author
Participant
June 19, 2006
Fine. I think this is discussed.
Thanks and best.
Pepe
_pjuerg_Author
Participant
June 16, 2006
hi,

thanks for your help. There was no mistake. Then I tried to save the file to a different place and it worked. So the mistake was the relative path.

myFile = new File("~/Desktop/test.txt");
This works fine.

Do you think I have to determine a current root folder if I do:
myFile = new File("test.txt");

Best pp
Participant
June 16, 2006
>Do you think I have to determine a current root folder if I do:
>myFile = new File("test.txt");

Try:

myFile = new File("./test.txt");

--
John Bean
Known Participant
June 16, 2006
John_Bean_UK@adobeforums.com wrote:
>>Do you think I have to determine a current root folder if I do:
>>myFile = new File("test.txt");
>
>
> Try:
>
> myFile = new File("./test.txt");
>

Those two constuctors _should_ be identical. If you run in to a situation where
they behave differently, let us know; it may be a bug.

-X

--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
_pjuerg_Author
Participant
June 15, 2006
hello,

unfortunately that wasn't the solution. There happens nothing. Below is the code as I use. Maybe the failure is in another part?

best pepe

fileInfo.run = function( )
{
// test string
var myText = "save this";

// create new File
myFile = new File("test.txt");

myFile.open("w");

// write into the file
myFile.write(myText);
//and close it
myFile.close(myText);
}
Known Participant
June 15, 2006
pjuerg@adobeforums.com wrote:
> hello,
>
> unfortunately that wasn't the solution. There happens nothing. Below is the code as I use. Maybe the failure is in another part?
>
> best pepe
>
> fileInfo.run = function( )
> {
alert("Testing file.write");
> // test string
> var myText = "save this";
>
> // create new File
> myFile = new File("test.txt");
>
if (!myFile.open("w")) {
alert("open failed: " + myFile.error);
return;
}
>
> // write into the file
if (!myFile.write(myText)) {
alert("write failed: " + myFile.error);
return;
}
> //and close it
if (!myFile.close(myText)) {
alert("close failed: " + myFile.error);
return;
}
alert("Testing file.write complete");
> }

Check for errors along the way.

-X

--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
Known Participant
June 14, 2006
pjuerg@adobeforums.com wrote:
> Hello,
>
> I created a little script which extracts metadata from a selection and stores it in a string. Now I just would like to save the string in a text-file in the current foldert, but ...
> any hint would be very kind.
>
> // test string
> myText = "save this";
>
> // create new File
> myFile = new File("test.txt");

myFile.open("w");

>
> // write into the file
> myFile.write(myText);
>
> and close it
> myFile.close(myText);
>
> thanks pepe


--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com