Highlighted

To move files and folders

Community Beginner ,
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

Adobe Community Professional
Correct answer by Kukurykus | Adobe Community Professional

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 http://stackoverflow.com/questions/4743094/how-can-i-move-all-the-files-from-one-folder-to-another-using-the-command-line

Topics

Actions and scripting

Views

2.5K

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

To move files and folders

Community Beginner ,
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

Adobe Community Professional
Correct answer by Kukurykus | Adobe Community Professional

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 http://stackoverflow.com/questions/4743094/how-can-i-move-all-the-files-from-one-folder-to-another-using-the-command-line

Topics

Actions and scripting

Views

2.5K

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
Most Valuable Participant ,
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

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
Reply
Loading...
Adobe Community Professional ,
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 http://stackoverflow.com/questions/4743094/how-can-i-move-all-the-files-from-one-folder-to-another-u...

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
Reply
Loading...
Engaged ,
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.

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
Reply
Loading...
Adobe Community Professional ,
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)

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
Reply
Loading...
Engaged ,
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.

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
Reply
Loading...
Adobe Community Professional ,
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)

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
Reply
Loading...
Engaged ,
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

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
Reply
Loading...
Adobe Community Professional ,
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.

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
Reply
Loading...
Engaged ,
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.

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
Reply
Loading...
Adobe Community Professional ,
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!')

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
Reply
Loading...
Engaged ,
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!

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
Reply
Loading...
Adobe Community Professional ,
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

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
Reply
Loading...
Engaged ,
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 ...

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
Reply
Loading...
Adobe Community Professional ,
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...

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
Reply
Loading...
Engaged ,
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

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
Reply
Loading...
Adobe Community Professional ,
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()

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
Reply
Loading...
Engaged ,
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.

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
Reply
Loading...
Explorer ,
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.

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
Reply
Loading...
Adobe Community Professional ,
Aug 25, 2020

Copy link to clipboard

Copied

Which one from above snippets you exactly used?

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
Reply
Loading...
Explorer ,
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)

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
Reply
Loading...
Adobe Community Professional ,
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.

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
Reply
Loading...
Explorer ,
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

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
Reply
Loading...
Explorer ,
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

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
Reply
Loading...
Adobe Community Professional ,
Aug 25, 2020

Copy link to clipboard

Copied

Maybe by default you have set lower quality for jpgs. Change:

 

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

 

to:

 

;(jpg = new JPEGSaveOptions()).quality = 12;
aD.saveAs(File(fnp + aD.name), jpg),

 

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
Reply
Loading...
Adobe Community Professional ,
Aug 25, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Explorer ,
Sep 08, 2020

Copy link to clipboard

Copied

Thank you so much its work 🙂

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
Reply
Loading...
Community Beginner ,
Jan 26, 2017

Copy link to clipboard

Copied

Hi Kurkurykus! Thank you for your help to get this scripts. It's quite useful

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
Reply
Loading...
Adobe Community Professional ,
Jan 26, 2017

Copy link to clipboard

Copied

@sarshan why did you marked @mauricior6328708​​ post as an correct 'answer' to your question if that was post he made for me to show me what he means and there is no any solution you needed . I mean you marked wrong answer by mistake?

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
Reply
Loading...
Community Beginner ,
Jan 26, 2017

Copy link to clipboard

Copied

Yes, I marked it mistakenly. I am sorry

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
Reply
Loading...
Adobe Community Professional ,
Jan 26, 2017

Copy link to clipboard

Copied

So now is correct although the most important for me is that I learnt how to do that you needed by few ways. I had to make some tests before those codes started working. All because so far I never used system() for moving files while only once JavaScript loop. This time I had to write it from beggining because I completely forgot how I did it in past

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
Reply
Loading...
Community Beginner ,
Apr 15, 2017

Copy link to clipboard

Copied

Hello Kukurykus,

I am here for another help from you.

I would like to move an active document to a specific folder in photoshop.

I am sure there is a javascript for this task but I don't know how to do it.

Here is the script I have tried but it doesn't work.

app.activedocument.move("/X/qa/Team/Saravanan/mergefiles/guna/Simple/")

Cheers

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
Reply
Loading...
Explorer ,
Mar 04, 2018

Copy link to clipboard

Copied

Thanks for this Kukurykus.  Helped me out.

I'd like to offer a VERY small correction to one of the options in the "Correct Answer" section (see the quote below).  I believe there is a missing closing parenthesis after "execute("  in line 9.

After the correction, this worked perfectly me.  Your amazing coding has taught me very much over the last few years.  Thank you!

Kukurykus  wrote

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(

)

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
Reply
Loading...
Adobe Community Professional ,
Mar 04, 2018

Copy link to clipboard

Copied

Thank you for posting it. I didn't notice it, but now I can't correct as editing operation is blocked after somone answered to that post. That's little mistake, but for beginners that may be not possible to find it. Funny I visited this topic yestarday after long time and had to answer to someone who posted here when I was few months inactive Now I shouldn't forget it

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
Reply
Loading...
Contributor ,
Mar 05, 2018

Copy link to clipboard

Copied

Hi Kukurykus. Very useful your script, I could see here that it perfectly moves the file to the referring subfolder but only in the format "JPG". Could you make a slight modification in it so it can move with the original extension? If for example in PSD and move as JPG, I can no longer do edits in the layers.

Thanks for the Script.

Script:

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

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
Reply
Loading...
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

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

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

That modified code save files as .psd (I think any kind of them). To move file with their original extension there is needed other method of moving. I will see later maybe r-bin​ code will be somehow accurate. Now I'm too tired to do anything.

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
Reply
Loading...
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

The function move_folder (src_path, dst_path) moves the entire contents of the src_path folder including all subfolders to the dst_path folder even if the folders are on different disks.

Works under windows. Verified!

alert(move_folder("C:\\A1", "C:\\A2\\X1\\X2"))

//alert(move_folder("C:\\A1", "D:\\A2\\X1\\X2"))

////////////////////////////////////////////////////////////////////////////////////////////

function move_folder(src_path, dst_path)

    {

    try {

        var folder = new Folder(src_path);

        var files = folder.getFiles();

        var ret = "";

        for (var i = 0; i < files.length; i++)

            {

            var ret = move_file(files.fsName, dst_path);           

            if (ret) return ret;

            }

        return ret;

        }

    catch(e) { alert(e); throw(e); }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function move_file(full_path, new_path)

    {

    try {

        var file = new File(full_path);

   

        var folder = new File(new_path);

   

        var move = false;

   

        if (file.fsName.charAt(0).toLowerCase() == folder.fsName.charAt(0).toLowerCase() && file.fsName.charAt(1) == ":" && folder.fsName.charAt(1) == ":")

            move = true;

   

        if (move)

            {

            var ret = create_path(new_path);

            if (ret) return ret;

            file.rename(new_path + "\\" + file.name);

            return file.error;

            }

        else

            {

            if (file.length < 0)

                {

                var ret = create_path(new_path + "\\" + file.name);

                if (ret) return ret;

                ret = move_folder(full_path, new_path + "\\" + file.name);

                if (ret) return ret;

                file.remove();

                return file.error;

                }

            else

                {

                var ret = create_path(new_path);

                if (ret) return ret;

                file.copy(new_path + "\\" + file.name);

                file.remove();

                return file.error;

                }

            }

   

        return "The Bug!";

   

        function create_path(path)

            {

            var folder = new Folder(path);

   

            if (!folder.exists)

                {

                var f = new Folder(folder.path);

                if (!f.exists) create_path(folder.path)

           

                folder.create();

                }

   

            return folder.error;

            }

        }

    catch(e) { alert(e); throw(e); }

    }

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
Reply
Loading...
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

I did not read the whole topic (it's hard for me)).

But it seems to me that no one uses this function if the folders are located on the same disk.

move_file("C:\\A1\\TEST.JPG", "C:\\A2\\X1\\X2\\X3")

function move_file(full_path, new_path)

    {

    var file = new File(full_path);

    create_path(new_path);

    file.rename(new_path + "\\" + file.name);

    return file.error;

    }

function create_path(path)

    {

    var folder = new Folder(path);

    if (!folder.exists)

        {

        var f = new Folder(folder.path);

        if (!f.exists) create_path(folder.path)

       

        folder.create();

        }

    return folder.error;

    }

P.S.was edited

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
Reply
Loading...
Contributor ,
Mar 05, 2018

Copy link to clipboard

Copied

Hi r-bin Once you open a file, this beautiful script creates a subfolder called "Roland Prints" then moves that original file to that subfolder "inside the main directory.

The problem is that it only moves in JPG and does not preserve the original format

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
Reply
Loading...
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

I do not understand what you mean. My script does not care about the file format. And it does not open the file.

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
Reply
Loading...
Contributor ,
Mar 05, 2018

Copy link to clipboard

Copied

There is no need to create a fixed path:

Follow these steps:

1: Open a photo of some folder on your computer:

2: Run this script:

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

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

Obs!

You will notice that inside the main directory, you created a subfolder called "Roland-Prints" you will also notice that the file has been moved to this subfolder.

The problem is that if you run this script on files that contain multiple layers type PSD it will not serve because when being moved the file is converted to JPG.

I think that's why: new JPEGSaveOptions ()),

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
Reply
Loading...
Adobe Community Professional ,
Mar 05, 2018

Copy link to clipboard

Copied

It does so, as written in the script. And what do you need? I do not understand )

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
Reply
Loading...
Contributor ,
Mar 05, 2018

Copy link to clipboard

Copied

r-bin  escreveu

It does so, as written in the script. And what do you need? I do not understand )

It moves the file and does not preserve the original format. this script is limited to JPG format only. If you run into a .PSD file it also converts to: .JPG file.

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
Reply
Loading...
Contributor ,
Aug 26, 2020

Copy link to clipboard

Copied

How I move files in script.
Auto determines what OS is running and uses either VB or Applescript.
This way preserves all file attributes (date modified, etc.)
which otherwise are lost if writing new copy then deleting old.
Windows also moves any Mac dotbar files that might exist on Windows/Linux servers.

Create a File object of the file you want to move.
Create a Folder object of the destination.
Pass these two to the function.

NOTE: Windows InDesign I've gotten error about Unable to Load Adobe Type Library when calling VB on new OS installs. Run ID as Administrator, then launch script, to fix (Administrator has permission to install the needed files). Only have to run as Admin the one time.

 

function moveFile(file, folder) {
    // file = File object of the file to move.
    // folder = Folder object of destination folder.
    var AppleScript;
    var dotbar;
    var movedFile;
    var VBScript;
    if (file instanceof File && file.exists && folder instanceof Folder && folder.exists) {
        movedFile = new File(folder.fullName + "/" + file.name);
        if (!movedFile.exists) {
            if (File.fs == "Windows") {
                VBScript =
                    "Set fs = CreateObject(\"Scripting.FileSystemObject\")\r" +
                    "fs.MoveFile \"" +
                    file.fsName +
                    "\", \"" +
                    folder.fsName +
                    "\\\"";
                app.doScript(VBScript, ScriptLanguage.visualBasic);
                // Check for and move matching dotbar file if exists.
                dotbar = new File(file.path + "\\._" + file.name);
                if (dotbar.exists) {
                    VBScript =
                        "Set fs = CreateObject(\"Scripting.FileSystemObject\")\r" +
                        "fs.MoveFile \"" +
                        dotbar.fsName +
                        "\", \"" +
                        folder.fsName +
                        "\\\"";
                    app.doScript(VBScript, ScriptLanguage.VISUAL_BASIC);
                }
            } else if (File.fs == "Macintosh") {
                if (/%(?!20)/.test(File.encode(file.fsName))) {
                    // Unicode characters detected in filename. Move will fail because
                    // ExtendScript cannot pass Unicode text to AppleScript via a string variable.
                    return false;
                }
                AppleScript =
                    "tell application \"Finder\"\r" +
                    "move POSIX file \"" +
                    file.fsName +
                    "\" to POSIX file \"" +
                    folder.fsName +
                    "\" with replacing\r" +
                    "end tell\r";
                app.doScript(AppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE);
            }
            if (movedFile.exists) {
                return true;
            }
        }
    }
    // Failed to move.
    return false;
}
William Campbell
Mars Premedia

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
Reply
Loading...