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

To move files and folders

Community Beginner ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Hello,

I would like to move files and folders to different locations. I am a novice to this scripting. It would be much appreciated if someone could help me exploring how to move files to different locations.

For example

Existing location: This is where files to be picked

X:\qa\Team\Saravanan\Reports

New location: This is where files to be placed

X:\qa\Team\Saravanan\mergefiles\Temp

TOPICS
Actions and scripting

Views

6.8K

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 2 Correct answers

LEGEND , Jan 18, 2017 Jan 18, 2017

If you want to move content of Reports folder (incl. all subfoldrs with their content and deeper):

(txt = File('~/Desktop/move.txt')).open('w')

txt.write('move ' + (src=(src='X:\\qa\\team\\Saravanan' )

+ '\\Reports ')  + src + '\\mergefiles\\temp')

txt.close(), txt.rename('move.bat');

(txt = File(txt.fullName.replace(/txt/, 'bat'))).execute()

bol = false; while (!bol) {

  if (bol = !Folder(SRC).exists) txt.remove(), Folder(SRC).create()

}

 

Or you may use shorter version:

system('move ' + (src=(

...

Votes

Translate

Translate
Enthusiast , Nov 01, 2023 Nov 01, 2023

Yup just had to sleep on it. Photoshop has the app method "system". Sends Terminal commands on Mac, Command Prompt on Windows. So a few tweaks. One thing different is you don't pass file objects. Instead just String objects of the full paths. And now the destination includes the file name, not just the folder. An added benefit of this difference is that the file can be renamed when moved. If not just have the same name in the "to" argument, as my example call at top shows. Also this won't deal w

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

Please search before asking you will get answere faster that way.

https://forums.adobe.com/search.jspa?place=%2Fplaces%2F1383833&q=Move+Files&sort=updatedDesc

It is also more a thing you would do using a utility in Windows or Apple OSX perhaps with Adobe Bridge.

JJMack

Votes

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
LEGEND ,
Jan 18, 2017 Jan 18, 2017

Copy link to clipboard

Copied

If you want to move content of Reports folder (incl. all subfoldrs with their content and deeper):

(txt = File('~/Desktop/move.txt')).open('w')

txt.write('move ' + (src=(src='X:\\qa\\team\\Saravanan' )

+ '\\Reports ')  + src + '\\mergefiles\\temp')

txt.close(), txt.rename('move.bat');

(txt = File(txt.fullName.replace(/txt/, 'bat'))).execute()

bol = false; while (!bol) {

  if (bol = !Folder(SRC).exists) txt.remove(), Folder(SRC).create()

}

 

Or you may use shorter version:

system('move ' + (src=(src='X:\\qa\\team\\Saravanan' ) + '\\Reports ')  + src + '\\mergefiles\\temp'), Folder(SRC).create()

 

 

If you want to move only files of Reports folder (while subfolders stay untouched):

(txt = File('~/Desktop/move.txt')).open('w')

txt.write('move ' + (src=(src='X:\\qa\\team\\Saravanan' )

+ '\\Reports') + '\\* '  + src + '\\mergefiles\\temp')

txt.close(), txt.rename('move.bat');

(txt = File(txt.fullName.replace(/txt/, 'bat'))).execute()

bol = false; while (!bol) {

  if (bol = !File(SRC).getFiles(/\./)[0].exists) txt.remove()

}

 

Or you may use shorter version:

system('move ' + (src='X:\\qa\\team\\Saravanan' ) + '\\Reports' + '\\* '  + src + '\\mergefiles\\temp')

 

 

If you want to move content of Repports folder (without recreating it, and removing .bat file by JavaScript):

(txt = File('~/Desktop/move.txt')).open('w')

 

cde = "SET src_folder=x:\\qa\\team\\Saravanan\\Reports\n"

cde += "SET tar_folder=x:\\qa\\team\\Saravanan\\mergefiles\\temp\n"

cde += "for /f %%a IN ('dir \"%src_folder%\" /b') do move %src_folder%\\%%a %tar_folder%\n"

cde += "del %HOMEPATH%\\desktop\\move.bat"

 

txt.write(cde), txt.close(), txt.rename('move.bat');

(txt = File(txt.fullName.replace(/txt/, 'bat'))).execute(

 

 

If you wnt to move content or Repports folder (strictly by JavaScript):

for(cnt = [(dst = '/X/qa/team/Saravanan') + '/Reports'], i = 0; i < cnt.length; i++) {

  nxt = Folder(cnt).getFiles()

  for(j = 0; j < nxt.length; j++) {

    if (nxt instanceof Folder) {

       Folder((dst = dst + '/mergefiles/temp/') + nxt.fullName.match(/Reports\/(.*)/)[1]).create()

       cnt.push(nxt)

    }

    if (nxt instanceof File) File(nxt).copy(dst + nxt.name), File(nxt).remove()

  }

}

 

for(i = cnt.length - 1; i > 0; i--) File(cnt).remove()

 

 

 

Read more at How can I move all the files from one folder to another using the command line?

Votes

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
Engaged ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Kukurykus this is a very interesting and very useful script.

I'm looking for a script like this, in my case I need a script that just moves the file into a subfolder called "Final" within that same directory. It would be possible?

It would work as follows:

1º - I edit an image (iso made by me)

2º - Save and close this file "It can be in JPG."

3º - This file is saved and moved a subfolder called "Final" in the same directory.

Votes

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
LEGEND ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

I don't have time right now as I'm at work, but you don't need to move saved file to other folder. You can save edited .jpg file directly to a 'Final' subfolder and then remove original file from parent of that 'Final" folder. Both things will be made by a script. So:

1) manually: you open previously saved file and edit it

2) by a script: you save a file in 'Final' subfolder, and remove original one from its parent

or if you really want:

1) manually: you open previously saved file and edit it

2) by a script: you save a file in original location, and move it to 'Final' subfolder

In my opnion the first metod in this case is more appriopate, becasue sometimes original file you open before saving may be in other format, ie .psd (when I have time i'll write it by these 2 methods)

Votes

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
Engaged ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Kukurykus,.Both methods will work perfectly well for me! Glad you understood my idea. For these issues I will do, all the original images will be and can be saved in JPG! The idea is to separate the images that have already been edited by a subfolder in the same directory ... If you try and be able to write both methods, the better still it will be for me! Thanks for the great help.

Votes

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
LEGEND ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Method ONE (copying):

jpg = new JPEGSaveOptions(); jpg.quality = 12;

(aD = activeDocument).saveAs(File(aD.path + '/Final/' +  aD.name), jpg)

aD.close(SaveOptions.DONOTSAVECHANGES)

Method TWO (moving):

function PTH(v) {

  return eval('aD.fullName' + v + '.fsName.replace(/\\\\/g, "\\\\\\\\")')

}

(aD = activeDocument).save()

system('move "' + PTH('') + '" "' + PTH('.parent') + '"\\Final"')

aD.close(SaveOptions.DONOTSAVECHANGES)

Votes

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
Engaged ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

Hello Kukurykus I did some tests here with both methods:

Method ONE (copying):

executed. It only worked here when I had to create the folder "Final"

Method TWO (moving):

I executed and nothing happened, even I created the folder "Final"

The sub-sub folder "Final" will be created automatically when the script is executed.

Understood? When the "Final" sub folder is created, you move the file into this folder and you delete the parent file

Votes

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
LEGEND ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

I thought to make it that 'Final' subfolder is created by the script, but then I looked to the post and didn't see anything you wanted it. No problem then, Tomorrow I'll write that one line more to make it working.

I don't know why Method 2 (moving) didn't work for you. I'll think about it, however here's (on Windows) worked.

Maybe it's because of something unexpected in your path? Write me full path to that folder where 'Final| folder has to be placed with files in and I'll see this path works on my computer (after I cretae all (sub)folders and run the script)

For example I tested it with this path: /d/Praca/ZLECENIA CD/PASSE-PARTOUT/07097 PASSE/get/Final

Files I used were opened from 'get' folder of course.

Votes

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
Engaged ,
Jan 20, 2017 Jan 20, 2017

Copy link to clipboard

Copied

The path will always be the folder that contains the files to be edited. Automatically create a sub folder called "final" then move the file to that sub folder when running the script. You can be in a hurry, only when it is available, you are a great programmer and it has helped a lot. Thank you so much.

Votes

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
LEGEND ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

You didn't understand me. I wanted only you show me a path you tried to use with my moving script. I'm trying to find a reason why the script didin't work for you. And one of them could be some strange path. Anyway you still may post that path and meanitme try to use something simple, just to check it will work in the easiest case. for example save your file at d:\ disk and run my script (if you don't have D disc then try any other hard disc beside C).

Copying:

if (documents.length) {

  if (!(crt = Folder((doc = (aD = activeDocument).path) + '/Final/')).exists) crt.create()

  aD.saveAs(File(aD.path + '/Final/' +  nme = aD.name), new JPEGSaveOptions())

  aD.close(SaveOptions.DONOTSAVECHANGES), File(doc + '/' + nme).remove()

}

else alert('Open at least one document!')

Moving:

function PTH(v) {

  return eval('aD.fullName' + v + '.fsName.replace(/\\\\/g, "\\\\\\\\")')

}

if (documents.length) {

  (aD = activeDocument).save(), system('md' + (pth = ' "' + PTH('.parent') + '\\Final"'))

  system('move "' + PTH('') + '"' + pth), aD.close(SaveOptions.DONOTSAVECHANGES)

}

else alert('Open at least one document!')

Votes

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
Engaged ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

KukurykusI have a little script that can help us! I'm leaving work ... From here, when I arrive at my house I will look for the script that can help .... Thanks for the great help!

It was you who wrote it ... You will understand and it will be easier for you! See you later!

Votes

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
LEGEND ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

I checked both paths (you posted and removed before you edited your post), so

/d/Library/images on your pc

/z/Digital Photos/05.01.17/Images/ on server in your work

and I didn't have any problem with them. They both worked. So I can't help about 'moving' version. I have no idea why it doesn't work for you

Votes

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
Engaged ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

//Script de Kukurykus.

Folder((fnp = (aD = activeDocument).fullName.parent + '/Roland-Prints/')).create() 

aD.saveAs(File(fnp + aD.name), new TiffSaveOptions()), aD.close(SaveOptions.DONOTSAVECHANGES) 

Kukurykus.It was you who wrote this script and I found it right here this week:

It does 90% of what I need, you only have to make two modifications.

Are they:

If you look, it creates a subfolder called "Roland" and saves a copy of the file in tiff. What you need is to just change from tiff to jpeg and delete the original file. ONLY THAT!

-------------------------------------------------- -----

Do only this:

Change to Jpeg instead of fiff and delete the parent file (original) It's all I need and nothing more ...

Votes

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
LEGEND ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

Folder((fnp = (fle = (aD = activeDocument).fullName).parent + '/Final/')).create(), File(fle).remove()

aD.saveAs(File(fnp + aD.name), new JPEGSaveOptions()), aD.close(SaveOptions.DONOTSAVECHANGES)

It would be nice you checked again that simplest path like /d/ to see that new version of moving script works for you...

Votes

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
Engaged ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

Do the following: Open file from any folder there on your computer, run the script: You will see that you create a folder called "Roland-Prints" and inside it a copy of the file. You just have to delete the original file!

0001.png

Votes

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
LEGEND ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

Are you saying that script in my previous post doesn't delete original file? Or you are saying about moving script?

I checked both of them once again, and both last one, and that 'Moving' one I wrote before do their job. So both of them delete original file. Anyway please be more precise, are you talking now about last script of me? hmmm, maybe it will be working after I change the order of some commands to this:

Folder((fnp = (fle = (aD = activeDocument).fullName).parent + '/Roland-Prints/')).create()

aD.saveAs(File(fnp + aD.name), new JPEGSaveOptions()), aD.close(SaveOptions.DONOTSAVECHANGES), File(fle).remove()

Votes

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
Engaged ,
Jan 21, 2017 Jan 21, 2017

Copy link to clipboard

Copied

Great! Now it worked perfectly. Thank you so much! You do not know how much it will help me. Kukurykus you are one besides a great programmer, he is a very attentive, kind and patient young man. I will be eternally grateful to you.

Votes

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
Explorer ,
Aug 24, 2020 Aug 24, 2020

Copy link to clipboard

Copied

its working for me. But when the photo is moved, the size of the photo decreases. E.g. 5.8 mb photo is converted to 500 kb. What to do to stay the same size.

Votes

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
LEGEND ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

Which one from above snippets you exactly used?

Votes

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
Explorer ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

Folder((fnp = (fle = (aD = activeDocument).fullName).parent + '/Used Photo/')).create(), File(fle).remove()
aD.saveAs(File(fnp + aD.name), new JPEGSaveOptions()), aD.close(SaveOptions.DONOTSAVECHANGES)

Votes

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
LEGEND ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

It doesn't move file, but creates 'Used Photo' folder, remove original file, and save new JPG.

Votes

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
Explorer ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

ok.  after save. the size of the photo decreases. E.g. 5.8 mb photo is converted to 500 kb. want to kept original size

Votes

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
Explorer ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

two problems i m facing now.

1. saved low size but i want to save same size

2. after this script. next time when i click on open then i want to redirect old recent folder but it is redirected to somewhere else

Votes

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
LEGEND ,
Aug 25, 2020 Aug 25, 2020

Copy link to clipboard

Copied

I don't understand what you mean in second point in your another post.

Votes

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