Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Writing directory names to a text file

Engaged ,
Jun 21, 2021 Jun 21, 2021

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
3.9K
Translate
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

LEGEND , 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()

 

Translate
Engaged , 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?

Translate
LEGEND , Jun 22, 2021 Jun 22, 2021
activeDocument.path.parent.parent.name
Translate
Adobe
LEGEND ,
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()

 

Translate
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
Engaged ,
Jun 21, 2021 Jun 21, 2021

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

 

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

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.

Translate
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
Engaged ,
Jun 21, 2021 Jun 21, 2021

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

Translate
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
Community Expert ,
Jun 21, 2021 Jun 21, 2021

 

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?

 

Translate
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
Engaged ,
Jun 21, 2021 Jun 21, 2021

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

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

 

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

 

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

 

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

 

Translate
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
Engaged ,
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?

Translate
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
LEGEND ,
Jun 22, 2021 Jun 22, 2021
activeDocument.path.parent.parent.name
Translate
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
People's Champ ,
Jun 21, 2021 Jun 21, 2021

probably because

path == app.path

name == app.name

and cannot be changed

 

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021

 

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

 

Translate
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
People's Champ ,
Jun 21, 2021 Jun 21, 2021

well, wow

Translate
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
Engaged ,
Jun 22, 2021 Jun 22, 2021
LATEST

Thank you that works for me!

Translate
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
Community Expert ,
Jun 21, 2021 Jun 21, 2021

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!

Translate
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
LEGEND ,
Jun 21, 2021 Jun 21, 2021
File.decode('/%20/')
Translate
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

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>
Translate
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