Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Writing directory names to a text file

Contributor ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

I am working on a Photoshop script that writes data to txt file.

In the following folder structure example:

 

Summer Collection

 June

  Peaches 

 

 var pName = outputFolder.name writes Peaches to the txt file.

 var mName = outputFolder.parent.name writes June to the txt file.

 

How can I define a variable that writes Summer Collection to the txt file and excludes the empty space %20 symbol?

Hope the question is clear. Let me know if you need additional details to clarify the question.

 

TOPICS
Actions and scripting

Views

1.6K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 3 Correct answers

Adobe Community Professional , Jun 21, 2021 Jun 21, 2021
pName = path.name, mName = name; (txt = File(Folder.desktop + '/txt.txt')).open('w') txt.write(decodeURI(pName) + '/' + decodeURI(mName)), txt.close()

Likes

Translate

Translate
Contributor , Jun 21, 2021 Jun 21, 2021
This works well when the directory name is WIP. Is it possible to make the WIP variable so that independently from the name the code can get the name of the folder two levels up?

Likes

Translate

Translate
Adobe Community Professional , Jun 22, 2021 Jun 22, 2021
activeDocument.path.parent.parent.name

Likes

Translate

Translate
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

 

pName = path.name, mName = name;
(txt = File(Folder.desktop + '/txt.txt')).open('w')
txt.write(decodeURI(pName) + '/' + decodeURI(mName)), txt.close()

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

The code writes Adobe Photoshop 2021/Adobe Photoshop to the tx.txt file on the desktop.

While the open psd doc is locatedUser/Desktop/stack test/photoshopdoc.psd

Not sure why the name is automatically crossed over.

Should the script write User/Desktop to the txt.txt file on the desktop?

 

Screen Shot 2021-06-21 at 12.34.22 PM.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Each time you launch Photoshop, its name is automatically beeing assigned to variable, for example it is same for path). txt.txt is saved to desktop as seen in the code as I'm not mind-reader to know where you'd like it to be saved 😉 There is nothing about it in your original post so txt should be saved on desktop 🙂 path and name are used instead of outputFolder.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

Thank you for clarifying. I am trying to write the directory WK22 only to a txt file when the script runs on a file that is located in the WIP directory. Is that possible and does it make sense?

/Users/Shared/PHOTO/WIN/POST/2021/06 JUNE/WK22/GNO/WIP

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

 

Which bit are you having issues with?

 

Triggering the write if the file is located in the WIP directory?

 

Or manipulating the text string to only write WK22?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

In the folder path sample, I can write the directory WIP and GNO to the txt file. I am having difficulty writing the directory WK22 to the file.  The text file should look like this:

WK22,  GNO,  WIP

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

 

if ((nme = (pth = activeDocument.path).name) == 'WIP')
	alert([(prnt = pth.parent).parent.name, prnt.name, nme])

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

 

if ((pth = activeDocument.path).name == 'WIP') alert(pth.parent.parent.name)

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

This works well when the directory name is WIP. Is it possible to make the WIP variable so that independently from the name the code can get the name of the folder two levels up?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

activeDocument.path.parent.parent.name

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

probably because

path == app.path

name == app.name

and cannot be changed

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

 

delete name; name = 'I\'m changed', alert(name), name = app.name, alert(name)

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

well, wow

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

LATEST

Thank you that works for me!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

As I learnt regular expressions before scripting, my go to would be:

 

yourVariable.name.replace(/%20/g, ' ');

 

I'll try to keep the decodeURI in mind as I have seen this elsewhere, thanks Kukurykus!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 21, 2021 Jun 21, 2021

Copy link to clipboard

Copied

File.decode('/%20/')

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

this gr8

<a href="https://www.e5dmny.com/%D8%AA%D9%86%D8%B8%D9%8A%D9%81-%D9%85%D9%86%D8%A7%D8%B2%D9%84-%D8%A8%D8%AD%D9%81%D8%B1-%D8%A7%D9%84%D8%A8%D8%A7%D8%B7%D9%86">شركة تنظيف منازل بحفر الباطن</a>

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines