Copy link to clipboard
Copied
All Experts,
I am new to indesign and javascripting. i need to copy the folder with files (structured folder) from one location to another location with the same folder name. i tried the file copy file.copy(), this is copying only particular file, i need to copy the folder with structured format. ie folder, if any sub folder...
Thanks,
sag
Copy link to clipboard
Copied
You're not going to find a canned solution to do this in InDesign's scripting classes. So your choices are:
What scripting language and operating system are you using?
Copy link to clipboard
Copied
i am using Windows and Javascripting (indesign cs4(sdk))
Copy link to clipboard
Copied
OK. I don't use InDesign under Windows so this is untested. It looks like to run windows commands with arguments, you need to use VBscript. So this function takes a source and destination Folder object, and then calls VBscript to call XCOPY to do the copy:
function copyFolder(source, destination) {
var cmd="XCOPY.EXE /S/E/K/H/X "+
source.path+" "+destination.path;
var vbscript='\
Set Command = WScript.CreateObject("WScript.Shell")\
cmd="'+cmd+'\
Command.Run(cmd)\
';
app.doScript(vbscript, ScriptLanguage.visualBasic);
}
copyFolder(new Folder("C:\Documents and Settings\User\Desktop\Source"),
new Folder ("D:\Destination"));
At the end is a sample invokation. Note that it expects Folder objects, rather than raw paths (because it converts them back to raw paths, with source.path and destination.path). It might make more sense to use raw paths in your application...
XCOPY copies file trees. /S tells it to copy subdirectors, /E even when empty, /K retains read-only attributes, /H copies hidden files, /X preserves SACLS and DACLS.
Copy link to clipboard
Copied
Thanks John, for your quick responce but could you please elobrate about XCOPY.exe and one more clarification that could we call perl exe using ESTK javascript.
Many Thanks in advance
Copy link to clipboard
Copied
Can you please ask a more specific question, sagkrish?
XCOPY is a Windows program for recursively copying directory trees. The script fragment I offered uses it. We didn't say anything about perl. We call XCOPY from VBScript. And we call VBScript from Javascript. It's all in the example. Does it not work? (As I said, I don't run InDesign under Windows, so I'm not in a good position to test it.)
If your question is whether you could call perl from ESTK Javascript, the answer is yes. You'll have to do it through VBScript, I think, if you want to pass any parameters (which is probably a practical requirement). But it's not very painful.
(Under MacOS, you can't write a script file from the File class, because the file would need to be made executable and you can't do that from the File class. But since Windows doesn't have that limitation, you could probably write a .BAT file using the File class and skip the VBScript. I don't think there is any real advantage to doing so...)
Copy link to clipboard
Copied
John, thanks for your good effort now i get to know what is xcopy and we tried the same using dos cmd and it's working fine but when we execute your code it's showing error "cannot compile the script". any idea about this.
Thanks
sagkrish
Copy link to clipboard
Copied
Thanks John Your code is help us very much but i have one more concern, how to overwrite the already existing folder through XCOPY command.
![]()
thanks,
Sag
Copy link to clipboard
Copied
Copy link to clipboard
Copied
ofcourse, i have used the option /y, even though its not working, showing error as Access denied.
Thanks,
Mac
Copy link to clipboard
Copied
Sorry for the delay in response.
I assume both sagkrish and Mac_06 are either the same person or working together?
When you said:
when we execute your code it's showing error "cannot compile the script".
were you trying after fixing the missing double-quote (my post of 1:42am)?
If not, maybe one of the Windows folks could better advise. The official Microsoft help for XCOPY is http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true that might be differently helpful than Jongware's link, which is good, too.
I can't quite tell if you're having a problem if you run the XCOPY command from the CMD.EXE Windows Command Prompt. If you are, well, it's not really an InDesign scripting question, but maybe we can help you anyhow. But you'll need to give us a lot more specifics on what is breaking. Does it work with other directories? Are there network filesystems involved? Are the source and destination directories outside of the running user's home folder?
If you're having problems overwriting files, you might try adding /R.
(Does anybody else want to test it?)
Copy link to clipboard
Copied
Thanks John,
I got the syntax to overwrite the files by using \r.
After adding the missing quotes in the code, it showing "Wscript object" error. Any way we have tried in other way and got the solution. By using command XCOPY.
Then Mac_06 and sagkrish are different persons, but working with the same project.
Thanks
Sag
Copy link to clipboard
Copied
Hi! sagkrish...
I have a same problem.
please!
show me the your code for copy folder!
Thanks
Kim
Copy link to clipboard
Copied
var vbscript='\ Set Command = WScript.CreateObject("WScript.Shell")\ cmd="'+cmd+'\ Command.Run(cmd)\ ';
Whoops, there's a typo. There should be another double-quote on the cmd= lines:
cmd="'+cmd+'"\
Sorry about that.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more