File operations.

Version :
16.10.2024, 11:40 Uhr

FTP-Upload einer Datei.

File operations. Files are always described by means of their paths. If not otherwise stated, this always implies complete system paths or URLs. Under Windows the paths known as UNC paths (\\paul\paul\develop) are enabled.
Following substitutions are carried out automatically :

In order to define system-independent paths, the UNC paths should always be used on Windows. The path delimiters in these paths are user-defined but take care to escape the \ in char*-String by \\.

In strings, \ must be escaped by an additional \, e.g. \\

strcpy (path, "\\\\paul\\paul\\develop\\");

Restrictions on Mac

For historical reasons paths must not contain ":".

File functions do not support Unicode characters greater than 0xFFFF (for instance 𝄞 with the Unicode 0x1D11E) in paths.

static int size(char* path, int fork = 1)

Get the size of file or folder.

Name Type Default Description
Return int   Size of given file or folder in bytes

0 : not found or error
path String or char* - Complete path
fork int 1 Requested fork of file (used under Mac OS only)

0 : all forks
1 : Data fork only
2 : Resource fork only

In case of folders all forks (0) is always used automatically.


priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int open(
  char* path,
  char* permission,
  char* type = "TEXT",
  char* creator = "CWIE")

Open a file to read or write. Opened files must in every instance be closed again.

Name Type Default Description
Return int   Reference to the opened files. This reference must be used in the other file requests.
-1 error during opening
path String or char* - Complete file path of the file to be opened
permission String or char* - Mode in which the file should be openedl. The string can contain the following specifications (in user-defined sequence)

r read
w write
a attach. The write mode "w" is automatically set.
type String or char* "TEXT" If the file for writing must be set up again, the file type can be specified here. The specification must be exactly 4 characters long, e.g. "TEXT".
creator String or char* "CWIE" If the file for writing must be set up again, the default application can be specified here, with which the file is to be opened. The specification must be exactly 4 characters long, e.g. "CWIE".

Opening a file, read its entire contents and insert the contents into the document.

int main ()
{
    int    		fi 		= file::open ("/Users/paul/Desktop/CLOB Kopie.txt", "r");
    char	*	str 	= alloc (1000000);
    char 	   	buf		[512];
    int			len;
*str = 0; while ((len = file::read (fi, buf, 511)) > 0) { buf[len] = 0; strcat (str, buf); } file::close (fi);
textmodel::insert (str, 0, -1); release (str); }

Version 3.2.2 R2370, 31.03.2011

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int create(
  char* path,
  int createPath = 0,
  int folderOnly = 0)

Create a file or folder in the file system.

Name Type Default Description
Return int   0 or ErrorCode
createPath int - Create the folder path too?

0 : No, don't create folders. If a part of the folder path does not exist, the function raises an error.

1 : Automaticalle create missing folders.
folderOnly int - Is the given path a folder path?

0 : No, the last part of the path is a file

1 : The given path is a folder path. Create the complete folder structure (regardless of the value of createPath).

Version 4.1.6 R25346, 25. June 2019

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int write(
  int refNum,
  char* buffer,
  int buflen = 0)

Write in a file.

Tipp: A nice trick for writing text files is also the use of wlog with a non-empty path parameter.

Name Type Default Description
Return int   0 Write error
>0 Number of written characters
refNum int - File reference. The reference is delivered as the result from open.
buffer String or char* - Insert this text into the file
buflen int 0 Number of written characters
<=0 Use string lengths of buffer. When buffer is of type char*, the passed buffer must be a valid C-string, i.e. 0-terminated!

Write several text parts to a file. The file is opened each time for viewing purposes. For easier readability the example does not include error trapping. In a proper applications a check should be made if the file could be opened and if the writing was successful in each case.

int main ()
{
    int    		fi;
    int			len;
fi = file::open ("$DESKTOP/ttt.txt", "wa", "TEXT", "CWIE"); len = file::write (fi, "aaa\n"); file::close (fi);
fi = file::open ("$DESKTOP/ttt.txt", "wa", "TEXT", "CWIE"); len = file::write (fi, "bbb\n"); file::close (fi);
fi = file::open ("$DESKTOP/ttt.txt", "wa", "TEXT", "CWIE"); len = file::write( fi, "ccc\n"); file::close (fi);
return 0; }

Write the content of the current textmodel base64 encoded to a file. After reading and decoding this file boths strings must be equal. Take care to use a big enoug buffer while reading or read and decoded using a loop.

int main ()
{
    String			str			= string::alloc ();
    char		*	enc			= 0;
    char		*	dec			= 0;
    char			buf			[3001];
    int				fi			= 0;
    int				bytesRead 	= 0;
textmodel::gettext (str);
// Encode to file enc = encode_base64 (string::get (str));
fi = file::open ("$DESKTOP/txt.txt", "w"); file::write (fi, enc); file::close (fi);
// Decode from file fi = file::open ("$DESKTOP/txt.txt", "r"); bytesRead = file::read (fi, buf, 3000); file::close (fi); strch (buf, bytesRead, 0, 1); dec = decode_base64 (buf);
showmessage ("%s\n\n%s\n\n%d", enc, dec, strcmp (string::get (str), dec));
release (enc); release (dec);
return 0; }

Read a binary file and write the result to another file. (Please note: The script is for demonstration only, normally you would use file::duplicate here.)

int main ()
{
    String		str		= string::alloc ();
    int 		fileRef;
    int			fileSize;
// Read file fileRef = file::open("$DESKTOP/b1.jpg", "r"); fileSize = file::read_str (fileRef, str, 4); file::close (fileRef);
// Write read data to another file fileRef = file::open("$DESKTOP/b2.jpg", "w"); file::write (fileRef, string::data (str), fileSize); file::close (fileRef);
return 0; }

Version 3.2.2 R2370, 31.03.2011

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int read(
  int refNum,
  char* buffer,
  int maxlen)

Reading from a file. The result is written to a char*-buffer.

If you want to use the result buffer as a string, do not forget to append the terminating 0 by using strch.

Name Type Default Description
Return int   0 Reading error or file end
>0 Number of characters read
refNum int - File reference. The reference is delivered as a result from open.
buffer char* - Reserved memory for the read file content
maxlen int - Length of the buffer. To allow binary data to be read as well no concluding 0 is written in the buffer.

Write the content of the current textmodel base64 encoded to a file. After reading and decoding this files boths strings must be equal. Take care to use a big enoug buffer while reading or read and decoded using a loop.

int main ()
{
    String			str			= string::alloc ();
    char		*	enc			= 0;
    char		*	dec			= 0;
    char			buf			[3001];
    int				fi			= 0;
    int				bytesRead 	= 0;
textmodel::gettext (str);
// Encode to file enc = encode_base64 (string::get (str));
fi = file::open ("$DESKTOP/txt.txt", "w"); file::write (fi, enc); file::close (fi);
// Decode from file fi = file::open ("$DESKTOP/txt.txt", "r"); bytesRead = file::read (fi, buf, 3000); file::close (fi); strch (buf, bytesRead, 0, 1); dec = decode_base64 (buf);
showmessage ("%s\n\n%s\n\n%d", enc, dec, strcmp (string::get (str), dec));
release (enc); release (dec);
return 0; }

Read and insert the content of a text file into the current text model.

int main ()
{
    char	*	path		= "$DESKTOP/Tabelle_Platzhalter.txt";
    int			fsize;
    int			fi			= 0;
    char	*	txt			= 0;
    char	*	buf			= 0;
    int			bytes		= 0;
fsize = file::size (path); if (fsize > 0) { txt = alloc (fsize+1); buf = txt; fi = file::open (path, "r"); while (1) { bytes = file::read (fi, buf, 3000); if (!bytes) { strch (buf, 0, 0); // set the end of the string break; } buf += bytes; } file::close (fi); } else { txt = alloc (4096); sprintf (txt, "File not found '%s'", path); }
wlog ("", "### %d ###\n", strlen (txt, 1)); textmodel::replace (txt); release (txt);
return 0; }

Version 3.2.2 R2370, 31.03.2011

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

strch

static int read_str(int refNum, String result)

Read the contents of a file as a String. The result is written to an allocated String.

read_str is always reading file contents as Strings. When trying to read binary data, the result is cut off at the first 0.

Name Type Default Description
Return int   0 Reading error or file end
>0 Number of characters read
Depending on the encoding used and 0-bytes in the result this can be different than the length of buffer. To use results with 0-bytes from binary files you may use the function string::data.
refNum int - File reference. The reference is delivered as a result from open.
buffer String - Reserved memory for the read file content
encoding int 0 What is the encoding of the source file?
0: Utf8
1: Systemzeichensatz
2: CP1252
3: Mac Roman

4: Binary data. The result is not 0 terminated in this case

Read a JavaScript file as a String and execute the script afterwards

int main()
{
    String 		script 		= string::alloc();
    String 		pathStr 	= string::alloc("C:/Temp/HelloWorld.jsx");
    int 		exists 		= 0;
    int 		fileRef 	= 0;
exists = file::exists(pathStr);
if (exists != 0) { fileRef = file::open(pathStr, "r"); file::read_str(fileRef, script); file::close(fileRef); run_javascript(script); }
string::release(script); string::release(pathStr);
return 0; }

Read a binary file and write the result to another file. (Please note: The script is for demonstration only, normally you would use file::duplicate here.)

int main ()
{
    String		str		= string::alloc ();
    int 		fileRef;
    int			fileSize;
// Read file fileRef = file::open("$DESKTOP/b1.jpg", "r"); fileSize = file::read_str (fileRef, str, 4); file::close (fileRef);
// Write read data to another file fileRef = file::open("$DESKTOP/b2.jpg", "w"); file::write (fileRef, string::data (str), fileSize); file::close (fileRef);
return 0; }

Version 4.1 R17030

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

Parameter fileSize since v4.1 R22123, 28. Mar 2018
file::read

static int close(int refNum)

Close a file

Name Type Default Description
Return int   0 or ErrorCode
refNum int - File reference. The reference is delivered as the result from open.

Version 3.2.2 R2370, 31.03.2011

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int download(
  char* url,
  char* path,
  int replace_existing = 0,
  ...)

Load a file defined by an URL. The new file or folder will get name which is specified in the target path. Functions of the respective operating system are used for the download.

From the fourth function parameter on you can add a key-value list of any length with additional download options. If the list is not empty, the download is made using curl. The following table contains all supported curl options and the expected data types. The keys are case insensitive. Wrong data types can cause the program to crash. The data type Path is also a String or char* but with the extension that $ALIASSES at the beginning of the path are automatically replaced.Global and Database tags like <folder> or <sessionId> in String and Path values are automatically replaced by their current values. The entries marked with ✗ in the column List Value are added to previous settings, all other multiple definitions will overwrite the previous definitions. A description of the curl parameters can be found here

Key Type Default List Value
Used default settings
"POSTREDIR"int7 (CURL_REDIR_POST_ALL)
"FOLLOWLOCATION"int1
"FAILONERROR"int1
"USERAGENT"Path" " (blank)
"REDIR_PROTOCOLS"int-1 (CURLPROTO_ALL)
"AUTOREFERER"int1
"CONNECTTIMEOUT"int3
"SSL_VERIFYHOST"int0
"SSL_VERIFYPEER"int0
"SSL_SSLCERTTYPE"String or char*"PEM"
"SSL_CAINFO"String or char*NULL
Abbreviations
"-" or "INSECURE" int

This parameter is useful to enable the curl download with the default settings (see above).

The option must be the first on the list. The value specification is ignored and should be specified as 0 (..., "-", 0, ...). Further options may follow.

"+" or "SECURE" int

Download with activated certificate check:

"SSL_VERIFYPEER", 1

The option must be the first on the list. The value specification is ignored and should be specified as 0 (..., "+", 0, ...). Further options may follow.

Please note that the current user certificates be loaded only once at the first use for performance reasons! Subsequent changes to the certificates are only registered when the programme is restarted.

"NOP" intSet this value if you do not need a single CURL option, but want to force the use of CURL for the download.
Additional Settings
"POSTREDIR" int
"ABSTRACT_UNIX_SOCKET" String or char*
"ACCEPTTIMEOUT_MS" int
"ACCEPT_ENCODING" String or char*
"ADDRESS_SCOPE" int
"APPEND" int
"AUTOREFERER" int
"CAINFO"Path

Path of a valid PEM file. The certificate contained in the file is appended to the user's current certificate list and the "SSL_VERIFYPEER" option is automatically enabled.

If the file does not exist, the option is ignored.

Please note that the current user certificates are loaded only once for performance reasons. Any subsequent changes to the certificate files will only be registered when the program is restarted.

"CERTINFO" int
"CONNECTTIMEOUT" int
"CONNECTTIMEOUT_MS" int
"COOKIE" String or char*
"COOKIEFILE" Path
"COPYPOSTFIELDS" String or char*
"CRLF" int
"CRLFILE" Path
"CUSTOMREQUEST" String or char*
"DEFAULT_PROTOCOL" String or char*
"DIRLISTONLY" int
"DNS_CACHE_TIMEOUT" int
"DNS_INTERFACE" String or char*
"DNS_LOCAL_IP4" String or char*
"DNS_LOCAL_IP6" String or char*
"DNS_SERVERS" String or char*
"DNS_USE_GLOBAL_CACHE" int
"EGDSOCKET" String or char*
"FILETIME" int
"FTPPORT" String or char*
"FTPSSLAUTH" int
"FTP_ACCOUNT" String or char*
"FTP_ALTERNATIVE_TO_USER" String or char*
"FTP_CREATE_MISSING_DIRS" int
"FTP_FILEMETHOD" int
"FTP_RESPONSE_TIMEOUT" int
"FTP_SKIP_PASV_IP" int
"FTP_SSL_CCC" int
"FTP_USE_EPRT" int
"FTP_USE_EPSV" int
"FTP_USE_PRET" int
"GSSAPI_DELEGATION" int
"HEADER"Path
"HEADEROPT" int
"HTTP200ALIASES" String or char*
"HTTPAUTH" int
"HTTPGET" int
"HTTPHEADER" String or char*
"HTTPPROXYTUNNEL" int
"HTTP_CONTENT_DECODING" int
"HTTP_TRANSFER_DECODING" int
"HTTP_VERSION" int
"IGNORE_CONTENT_LENGTH" int
"INTERFACE" String or char*
"IPRESOLVE" int
"ISSUERCERT" Path
"KEEP_SENDING_ON_ERROR" int
"KEYPASSWD" String or char*
"KRBLEVEL" String or char*
"LOCALPORT" int
"LOCALPORTRANGE" int
"LOGIN_OPTIONS" String or char*
"LOW_SPEED_LIMIT" int
"LOW_SPEED_TIME" int
"MAIL_AUTH" String or char*
"MAIL_FROM" String or char*
"MAIL_RCPT" String or char*
"MAXCONNECTS" int
"MAXFILESIZE" int
"MAXFILESIZE_LARGE" int
"MAXREDIRS" int
"MAX_RECV_SPEED_LARGE" int
"MAX_SEND_SPEED_LARGE" int
"NEW_DIRECTORY_PERMS" int
"NEW_FILE_PERMS" int
"NOBODY" int
"NOPROXY" String or char*
"PASSWORD" String or char*
"PATH_AS_IS" int
"PINNEDPUBLICKEY" String or char*
"PIPEWAIT" int
"PORT" int
"PREQUOTE" String or char*
"PRE_PROXY" String or char*
"PROTOCOLS" int
"PROXY" String or char*
"PROXYAUTH" int
"PROXYHEADER" String or char*
"PROXYPASSWORD" String or char*
"PROXYPORT" int
"PROXYTYPE" int
"PROXYUSERNAME" String or char*
"PROXYUSERPWD" String or char*
"PROXY_CAINFO" Path
"PROXY_CAPATH" Path
"PROXY_CRLFILE" Path
"PROXY_KEYPASSWD" String or char*
"PROXY_SERVICE_NAME" String or char*
"PROXY_SSLCERT" String or char*
"PROXY_SSLCERTTYPE" String or char*
"PROXY_SSLKEY" Path
"PROXY_SSLKEYTYPE" String or char*
"PROXY_SSLVERSION" int
"PROXY_SSL_CIPHER_LIST" String or char*
"PROXY_SSL_OPTIONS" int
"PROXY_TLSAUTH_PASSWORD" String or char*
"PROXY_TLSAUTH_TYPE" String or char*
"PROXY_TLSAUTH_USERNAME" String or char*
"PROXY_TRANSFER_MODE" int
"PUT" int
"QUOTE" String or char*
"RANDOM_FILE" Path
"REDIR_PROTOCOLS" int
"REFERER" String or char*
"RESOLVE" String or char*
"RESUME_FROM" int
"RESUME_FROM_LARGE" int
"RTSP_CLIENT_CSEQ" int
"RTSP_REQUEST" int
"RTSP_SERVER_CSEQ" int
"RTSP_SESSION_ID" String or char*
"RTSP_STREAM_URI" String or char*
"RTSP_TRANSPORT" String or char*
"SERVICE_NAME" String or char*
"SSH_AUTH_TYPES" int
"SSH_HOST_PUBLIC_KEY_MD5" String or char*
"SSH_KNOWNHOSTS" Path
"SSH_PRIVATE_KEYFILE" Path
"SSH_PUBLIC_KEYFILE" Path
"SSLCERT" String or char*
"SSLCERTTYPE" String or char*
"SSLENGINE" String or char*
"SSLENGINE_DEFAULT" int
"SSLKEY" Path
"SSLKEYTYPE" String or char*
"SSLVERSION" int
"SSL_CIPHER_LIST" String or char*
"SSL_ENABLE_ALPN" int
"SSL_ENABLE_NPN" int
"SSL_FALSESTART" int
"SSL_OPTIONS" int
"SSL_SESSIONID_CACHE" int
"SSL_VERIFYHOST" int
"SSL_VERIFYSTATUS" int
"SSL_VERIFYPEER" int
"SUPPRESS_CONNECT_HEADERS" INT
"TCP_FASTOPEN" int
"TCP_KEEPALIVE" int
"TCP_KEEPIDLE" int
"TCP_KEEPINTVL" int
"TCP_NODELAY" int
"TELNETOPTIONS" String or char*
"TFTP_BLKSIZE" int
"TFTP_NO_OPTIONS" int
"TIMECONDITION" int
"TIMEOUT" int
"TIMEOUT_MS" int
"TIMEVALUE" int
"TLSAUTH_PASSWORD" String or char*
"TLSAUTH_TYPE" String or char*
"TLSAUTH_USERNAME" String or char*
"TRANSFERTEXT" int
"TRANSFER_ENCODING" int
"UNIX_SOCKET_PATH" String or char*
"UNRESTRICTED_AUTH" int
"USERNAME" String or char*
"USERPWD" String or char*
"USE_SSL" int
"WILDCARDMATCH" int
"XOAUTH2_BEARER" String or char*

Name Type Default Description
Return int   0 or ErrorCode
url String or char* - URL or complete path to the original
path String or char* - Target path including name
replace_existing int 0 Should the original be over-written?
... see above leer Key-Value pairs of curl options

Download index.html from www.hi13.de.

err_code = file::download ("http://www.hi13.de/index.htm",
 	"your_path",
 	1);

Download index.html from www.hi13.de using curl.

err_code = file::download ("http://www.hi13.de/index.htm",
 	"your_path",
 	1,
 	"-");

Download index.html from www.hi13.de using curl with self-signing certificate and cookie.

err_code = file::download ("http://www.hi13.de/index.htm",
 	"your_path",
 	1,
 	"SSL_VERIFYPEER", 1,
 	"CAINFO", "$DESKTOP/my_certificat.pem",
 	"COOKIE", "PubServSessID=<Unquoted_sessionId>");

Using system::cmd you can also call curl by yourself. But please note that the program curl must be installed on the target computer in this case. Here you find downloads of curl.

int main ()
{
    char    url [1024];
    char    fi  [1024];
    char    cmd [2048];
strcpy (url, "https://enterprise.celum.net/cora/download?ticket=7d328316-1515-4595-8ff1-47311b6ca24b"); strcpy (fi, "\\Users\\paul\\Desktop\\aaa.txt");
strcpy (cmd, "C:\\Users\\paul\\AppData\\Local\\Apps\\cURL\\bin\\curl.exe --url "); strcat (cmd, url); strcat (cmd, " --output "); strcat (cmd, fi);
system::cmd (cmd , 1); return 0; }

Version 3.2.2 R2370, 31.03.2011

curl-Optionen since v4.1.8 R27723, 16. Nov 2020

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

comet.file.download

static int download_webimages(
  ItemRef docRef,
  char* destpath,
  StringList urls,
  int flags = 0,
  IDTypeList results = 0)

Parallel download of a list of Web Images. Parallel processing vastly speeds up the download process compared to loading the images individually. In the test, 60 images were loaded in just 0.6 seconds instead of 30 seconds. So if, for example, you can determine which images are required for a product build-up before it is executes, you may be able to speed up the creation of your products considerably.

The images are stored in the same file that is used for the Web Images of a document. The ////// URL markers supported in Web Images are supported here too.

Alternatively, the images can also be stored in a specified folder. If the /////-definition contains a complete path, the common folder is ignored and the image is stored in the location defined in the URL.

If the URLs contain passwords, the option 'kNoHash' should be used, as the encryption of the passwords produces different results with each call and accordingly the hash code generated from the encrypted URL produces different file names with each call, even if the URL does not change.

If this function is used, it makes sense to make subsequent calls to frame::image with the value 16 (suppress checking header) in the Parameter updateFlags.

Name Type Default Description
Return int   0 or Error Code

-1199 : Download canceld by user
1294 : New unsaved document without file path
-43 : At least one file could not be loaded
otherwise : HTML error code
docRef ItemRef - Valid document reference

0 : Current document
destPath String oder char* - Download folder

0 or "" : Use docRef
otherwise : Full path of the download folder. If the folder does not exist, it will be created. The path may begin with a defined $-Alias.
urls StringList - List of image URLs. The URLs may have the usual /////-specifications for Web Images.
flags int 0 Additional information for download

0 : none
1 : Show progress bar (InDesign® only)
results IDTypeList 0 Results of the individual downloads

0 : Ignore results

otherwise : Allocated list for the individual results. After executing the function function, the list has the same length as the input list urls. idtype::id of the entries contains the error code of the download, idtype::stringid of the entries contains the complete path of the download file. The list remains empty for errors -1199 (abort) and 1294 (no document path).
int main ()
{
    StringList 		urls	= stringlist::alloc ();
    IDTypeList 		results	= idtypelist::alloc ();
    IDType 			res;
    int				result;
stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w0MDAzfGltYWdlL2pwZWd8YUdFNEwyZzJaUzh4TXprNU56VTBOVFl4T1RRNE5nfDk1NWMyNDA4YTc1YmQxZTA5YmRiOGU1ZjNjMjMzNDhiZTJlYzFmODYwNDVlN2VlNGYwNTkwMTJmN2YzNDczMGY////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w0NzMxMHxpbWFnZS9qcGVnfGFERmxMMmhrTkM4eE1qSTJOVE13TkRNNU1UY3hNQXwyOGFjYmM2MGZlOTJhZDIyMDBmMzkxZDg5Nzc0OWQ0OWUxYmQ1ZmM5MTUzNDdkYjIzY2QwNzIwZTJjZDQ1MWY5////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w1MDA0NHxpbWFnZS9qcGVnfGFEbGpMMmhqWkM4eE16STJOakUzTVRrMU16RTRNZ3xlOWZiYzM1NDAyYWQ0ZDVlOTMzMDMwZjY3ZDRmNDA2YTBlZmRlNjFkYWY5NWZlOGIyNzZmZjA1NTA1OWI3YTll////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w1MDA0NHxpbWFnZS9qcGVnfGFHVTBMMmhsWmk4eE16STJOak14TXpnek9EWXlNZ3w3ZjJmY2QwN2JlMmRiNzkyYTU0YmY0MDdhNGI4ZjRiYjM3OWYzZjg1ZDY0YTdmYmQxZThmZmYyNWVlZWFhYjA0////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w1MDk5OXxpbWFnZS9qcGVnfGFHSmxMMmcxWkM4eE16azVOemc0T0RRd05UVXpOQXw3MmQ0ZDY5YWJiMzBkNjQ0NWVhNmYzODVkZTllYzI4OTcyYTNhNjg2YWZhYTBhNjA2MTM5MDAyZTYxNDc1NTUx////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w1MjUxMnxpbWFnZS9qcGVnfGFHUXpMMmhsWXk4eE16STJOak14TXprd05ERTFPQXwyNzMyZmMyNTBiMzQ1ZjI3MDM3M2E5NDU1MWYzOTkxODY3ZTc5YTliMGQ1ZTZiNjZmMjNlNmRjNmRkNDFjNGJj////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w1NjEyfGltYWdlL2pwZWd8YUdWbUwyZzBNQzh4TXprNU9EQTJORFV6TXpVek5BfDgxYjcwYjBiZmZhMGM5YjRiNmYzMTY2NTE1NjdjMWVjZWNjOTg5MTgxNjUwN2VlNGRiNmFkOTNkZmRhYWZmNzA////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2NDcwN3xpbWFnZS9qcGVnfGFEQTFMMmhoWmk4eE16STJOakUzTVRBMk9EUTBOZ3xkYjk2NjdiMzhmZDIyMDlhZTVmZmMwYzE3YTRhZTVmODU4MjI5NzI0YzM5MGMzMjhjMDk2ZWVkMmZkNTk1MmU0////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2NDcwN3xpbWFnZS9qcGVnfGFEZGpMMmhsWXk4eE16STJOak14TXprek5qa3lOZ3w1MzBiNDZmYzQwMzZhZDlkZjBkNTUzMmI3YTIzMjBiZjhmMTU1OTA5ZDg1NmMxMTg0N2QxYjQxODdkMzMwNmY5////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2ODg0fGltYWdlL2pwZWd8YVcxaFoyVnpMMmhtT0M5b016a3ZPVGczTkRReE1qRXdPVGcxTkM1cWNHY3w1ZmQxYTQwNGI5YzJiZjYzZDVjMzk1MDFhYWVjODU4OWQ2YWUwN2I0MzEwNjgxYjAxNmI0NDBmYmY5YWRlMzM1////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2OTE5OXxpbWFnZS9qcGVnfGFEWXdMMmhqTkM4eE16STJOakUyT1RRNU5UVTRNZ3xlOTQ4NTZhOGY4NzQwNjk1MmVkOGYzMTMxYWEzYjgzYjZjMGQ2NmM4MTZiYzZiMjFmYzllOWI0MmY1ZWRkYzY2////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2OTI3NHxpbWFnZS9qcGVnfGFHRmtMMmhqWmk4eE16Z3dNVGc0TlRjMk1UVTJOZ3xhMTkxMzVhZDI4YmMwN2ExNjM0NGIzOGFiNmUxZmYyMzNhNjhjNDNlMDFlYjBjYzZiYjdkNjgwMjI4YWU2Zjk4////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w2OTYyfGltYWdlL2pwZWd8YURJNUwyZ3lZeTh4TXpnd01qYzBNelE1Tmpjek5BfDRjNTA4NDJkMmRhY2QxMTk0NTAwZjQ5NzdmMTI1ZGFiODMxYTNhM2NiM2ZmNmM1NTYxMjgyZmEzMTFkNWIyOTY////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w3MjM1fGltYWdlL2pwZWd8YURreUwyaGhOQzh4TXpjNU56azJOek0yTkRFeU5nfDU1MzJiYzRjYjg5Yzg0ZjljMjI5ODcyMDI4ZjdlMjQyMWRkMzZjZDJmOTVhM2Q5MzMyYTM3NGY1NTliZWM3ZTk////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3w4OTg4fGltYWdlL2pwZWd8YURrekwyZ3daQzh4TXprNU9EUXlNVGt6TkRFeE1BfGNmOWE1NjQ0ZWU5MjIzNzQ3OGQ3ZWI4MTZkNGRmOTQ4MTE3MTZmYjFkMGZlZTI1MGJkYWYwZDI3ZmJiZTVlNDQ////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3wxMDUyMnxpbWFnZS9qcGVnfGFEbG1MMmhrTnk4eE16azVPVEEzTlRJNU5USTJNZ3wzNWVjMGNlZTZkN2I3N2E4YTc1OGM4ZTZkNjk1NjU3NmNhYWQyMTM2NzM3MGUyY2VlZmY3MzUzMmZkNmZjOTE3////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3wxMDY2NHxpbWFnZS9qcGVnfGFHUTJMMmd3TUM4eE16azVOemczT1RZMU5qUTNPQXxjZDY3ZTc4NmUxYmE4ZDdlMWZiY2IwMDkzNjI3MmUyYTQyNWYyZWNkYWJjZDAzMjY0YmY4NDQxZTljOGFiYjQ4////kOnlyHash"); stringlist::append (urls, "https://www.your_company.com/medias/?context=bWFzdGVyfGltYWdlc3wxMjA3NHxpbWFnZS9qcGVnfGFEY3hMMmczWXk4eE16azVPRGN6T1RjMU1EazBNZ3wzMzk1MWEzODA5NzAxZjY4ODIyMmQ5NjFiYjIwODcyOWI4OWFkMmNhZjdjM2RhYjE4NjE0YzU4OTI4MDNkNzAx////kOnlyHash");
result = file::download_webimages (0, 0, urls, 1, results);
wlog ("", "download_webimages result %d %d\n", result, idtypelist::length (results)); for (res = idtypelist::first (results); res; res = idtypelist::next (results)) { wlog ("", "%d : '%s'\n", idtype::id (res), idtype::stringid (res)); } return 0; }

v4.3 R33910, 23. Nov 2024

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

comet.file.downloadWebImages

FTP-Upload einer Datei.

[ab Version 3.2.2 R2370] Verschicke eine lokale Datei zu einer angegebenen URL. Wenn der Server eine Benutzkennung fordert, müssen Benutzername und Passwort in der URL angegeben werden. Name und Passwort werden in der Form benutzer:passwort@ direkt hinter ftp:// angegeben.

Hinweise

Beachten Sie bitte die folgenden Hinweise:

Name Type Default Description
Return int   0 oder Fehlercode
path String oder char* - vollständiger Pfad der Datei, die versendet werden soll.
url String oder char* - URL oder vollständiger Pfad zum Original inklusive Namen. Beachten Sie bitte die oben angegebenen Hinweise!
replace_existing int 0 Wird nicht ausgewertet. Existierende Dateien im Zielsystem werden immer ersetzt.

Lade die Datei index.html auf die Webseite www.hi13.de.

err_code = file::upload ("$DESKTOP/index.html",
 	"ftp://benutzer:passwort@www.hi13.de/index.html");

Version 3.2.2 R2370, 31.03.2011

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

file::download

static int launch(char* path)

Opening a file in your standard program. The command operates as a double-click of the file in finder/explorer. If you provide a URL, the given URL will be opened in your default browser (Mac only). URLs must not contain keys like $DESKTOP.

Name Type Default Description
Return int   0 or ErrorCode
path String or char* - Complete path to the file or folder to be opened or URL (Mac only)

Open an URL to the current online documentation.

int main ()
{
    char		url[512];
strcpy (url, "file://"); strcat (url, file::uncurtain ("$COMET")); strcat (url, "/Doku_"); strcat (url, translate (0, "$LOCALE", 0)); strcat (url, "/InDesign/Plugins/w2plugins.html#Aktivierung");
file::launch (url);
return 0; }

URLs supported since version 2.1 R1830, 31.03.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int exists(char* path)

Does the file/folder exist?

The instruction can also be used to check whether an image of a CC Library still exists or has been deleted. Please note that the downloaded image files of CC Libraries images can still exist on your computer, even if the corresponding entry has already been deleted from the library. The function therefore checks the status of the CC Libraries image, not the existence of the loaded image file!

The CC Libraries are constantly being developed by Adobe. Unfortunately there is no interface for Javascript or C++ for it. Our implementation is the result of deep diving into the XMLs and JSONs of CCLib and may be based on assumptions that have changed since it was introduced in November 2020. Please understand that we will not continue to develop the feature until Adobe introduces a CCLib interface.

Name Type Default Description
Return int   0 No
1 Yes
path String or char* - Complete path to a file or a folder. The path may begin with one of the defined aliases.

"CC Libraries: lib_name/image_name" : Check if the given CC Libraries image is (still) valid

Version 1.1.6

Support of CC Libraries since v4.1.8 R27691, 2. Nov 2020

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

isfile
isfolder
frame::image_getpath
frame::image

static int isfile(char* path)

Does the specified path point to a file?

Name Type Default Description
Return int   0 No
1 Yes
path String or char* - Complete path to a file or a folder

Version 1.1.6

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

exists
isfolder

static int isfolder(char* path)

Does the specified path point to a folder?

Name Type Default Description
Return int   0 No
1 Yes
path String or char* - Complete path to a file or a folder

Version 1.1.6

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

exists
isfile

static int select_file(
  char* outpath,
  char* title = 0,
  int askForNew = 0,
  char* suggestion = 0)

File selection by means of a file dialog.

Name Type Default Description
Return int   0 oder ErrorCode
outpath String or char* - Complete path to a selected file
title String or char* 0 Labeling of the file dialog
askForNew int 0 1 : Request an existing file
0 : Get the path of a new file or folder
suggestion String oder char* 0 Suggested name or empty

Version 1.2 (21. Juni 2005)
v4.1.7 R27311, 20. Jul 2020

priint:comet InDesign® Plug-Ins, Illustrator

select_file
comet.dialog.selectFile

static int select_folder(char* outpath, char* title = 0)

Folder selection by means of a file dialog.

Name Type Default Description
Return int   0 oder Error cide
outpath String or char* - Complete path to a selected folder
title String or char* 0 Labeling of the file dialoge

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, Illustrator

select_file
comet.dialog.selectFolder

static char* name(char* result, char* path)

The function ascertains the system-dependant last part of the passed path. With Mac OS X the path delimiter is a "/", with Windows a "\"

Name Type Default Description
Return String or char* (Depends on parameter result)   The parameter result is returned as the result.
result String or char* - Name of the file. When the variable type is char*, sufficient memory must be allocated for the result.
path String or char* - File path. The file must not be in existance.
char		name[256];
char		path[4096];
if (file::select_folder (path, "Test") != 0) return 0; showmessage (file::name (name, path));

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static char* shortname(char* result, char* path)

Ascertain the name of a file without file extension. The function ascertains the system-dependant last part of the passed path and remove the file extension from the result. With Mac OS X the path delimiter is a "/", with Windows a "\"

Name Type Default Description
Return String or char* (Depends on parameter result)   The parameter result will be returned as the result.
result String or char* - Basis name of the file. When the variable type is char*, sufficient memory must be allocated for the result.
path String or char* - File path. The file does not have to exist.
char		name[256];
char		path[4096];
if (file::select_folder (path, "Test") != 0) return 0; showmessage (file::shortname (name, path));

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static char* extender(char* result, char* path)

The function ascertains the system-dependent last part of the passed path taking from it the file extension. With Mac OS X the path delimiter is a "/", with Windows a "\"

Name Type Default Description
Return String or char* (Depends on parameter result)   The parameter result is returned as the result.
result String or char* - File extension. When the variable type is char*, sufficient memory must be allocated for the result.
path String or char* - File path. The file does not have to exist.
char		name[256];
char		path[4096];
if (file::select_folder (path, "Test") != 0) return 0; showmessage (file::extender (name, path));

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static char* path(char* result, char* path)

Ascertain the path of a file. The function ascertains the system-dependent initial part of the system-dependent path. With Mac OS X the path delimiter is a "/", with Windows a "\"

Name Type Default Description
Return String or char* (Depends on parameter result)   The parameter result is returned as the result.
result String oder char* - File path. When the variable type is char*, sufficient memory must be allocated for the result.
path String oder char* - File path input. The file does not have to exist.
char		name[256];
char		path[4096];
if (file::select_folder (path, "Test") != 0) return 0; showmessage (file::path (name, path));

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static char* volume(char* result, char* path)

Ascertain the drive part of a file path.

Name Type Default Description
Return String or char* (Depends on parameter result)   The parameter result is returned as the result.
result String or char* - File extension. When the variable type is char*, sufficient memory must be allocated for the result.
path String or char* - File path. The file does not have to exist.
char		name[256];
char		path[4096];
if (file::select_folder (path, "Test") != 0) return 0; showmessage (file::volume (name, path));

Version 1.2 (21. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int duplicate(
  char* source,
  char* destPath,
  char* newName = 0,
  int createPath = 1,
  int overrideExisting = 0)

Duplicate a folder or a file. A new name can optionally be specified for the target. Target paths can be generated. The target path may not end with a path delimiter. Source and target drives must be mounted.

Name Type Default Description
Return int   0 or ErrorCode
source String or char* - Complete path to a file or a folder.
destPath String or char* - Target folder. The path may not end with a path delimiter.
newName String or char* 0 New name for the copy. If the name is empty, the copy is given the name of the original.
createPath int 1 Should the target path be automatically generated?
0 : Do not generate target path
otherwise : Define target path where required
overrideExisting int 0 If the destination file exists, is it okay to override it?

0 : No, do not override
1 : Yes. If the destination is a folder, the parameter is ignored.

Version 1.2 (30. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int move(
  char* source,
  char* destPath,
  int createPath = 1,
  int overrideExisting = 0)

Move a folder or a file. When moving to another drive, the command automatically creates a copy. A new name can optionally be specified for the target. Target paths can be generated. The target path may not end with a path delimiter. Source and target drive must be mounted.

Name Type Default Description
Return int   0 or ErrorCode
source String or char* - Complete path to a file or a folder.
destPath String or char* - Target folder. The path may not end with a path delimiter.
createPath int 1 Should the target path be automatically generated?
0 : Do not generate target path
otherwise : Define target path where required
overrideExisting int 0 If the destination file exists, is it okay to override it?

0 : No, do not override
1 : Yes. If the destination is a folder, the parameter is ignored.

Version 1.2 (30. Juni 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int remove(char* source)

Removes a file or folder. The folder does not have to be empty, be carefully. You cannot undo this action!

Name Type Default Description
Return int   0 oder ErrorCode
source String or char* - Complete path to a file or a folder.

Version 1.2 (30. June 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int rename(char* source, char* newName)

Rename a folder or a file.

Name Type Default Description
Return int   0 or ErrorCode
source String or char* - Complete path to a file or a folder.
newName String or char* - New name

Version 1.2 (30. June 2005)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int setdatafile(
  char* newPath,
  int id,
  char* name = "",
  int stage = 0,
  int activeOnly = 0)

Change the path definition of a presettings classification. If the entry is shown in the panel list presettings, this entry will also be changed. File paths are automatically relativised, if the file is to be found in the following folders:

If the path is empty, it is requested via a file selection.

The command requires the plugin data files.

Name Type Default Description
Return int   0 or ErrorCode
newPath String or char* - New file path/file name, which is to be assigned to the entry. Incomplete path specifications always refer to the currently active data folder.
id int - ID of the entry which is to be changed
0 : Ignore the ID and use the name to identify the entry. The alias names of the classification need not be unique.
name String or char* 0 Name of the entry
If id has a value >0, the specification will be ignored.
stage int 0 At which level should the path definition be changed??

0 : Global. The definition is changed for all users in the data pool. The change is effective immediately. This option is not supported in PubServer connections!

1 : Locally. The definition is changed locally and displayed in red in the 'Settings' panel. In the data pool, the entry remains unchanged. In PubServer connections this option has no effect!

2 : Temporary : Defined in batch jobs only! Create or change a temporary definition of the given alias name. The specification of an ID is not supported here! Entries are not shown in panel Settings! In contrast to local changes, this definition is also effective in PubServer connections.
The definition covers definitions of the same name in the datapool. It is removed when the data connection is disconnected. The definitions $DESKTOP, ... are not allowed to be changed by this function!
Ignored by Illustrator

Reserved names

Do not use the following reserved variable names:
  • gBatchMachine : The target machine of the currently running batch job (xmlget targetmachine node config.batch in sererver respectively the name given in the field 'Machine' of panel Comet++).
activeOnly int 0 Change entry only if it is active? This specification is particularly important if there are several entries with the same alias name.

0 : The found entry must not be active. If you specify a name, the first matching entry is changed.

1 : The found entry must be activated so that it can be changed.

Parameter stage since v4.1.6 R25445, 8. Jul 2019
Parameter activeOnly since v4.1.67 R27145, 8. Jul 2020
Version 1.2.2, 11 October 2005

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

comet.file.setDataFile

static char* getdatafile(
  int id,
  char* name = "",
  int enabledOnly = 1,
  int autoResolve = 1)

Get the (relative) path of a data file classification.

Name Type Default Description
Return char*   (Relative) path of the data file aliases.

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

id int - ID of the entry
0 : Ignore the ID and use the name for the identification of the entry. The alias names of the classification must not be unique.
name String or char* 0 Name of the entry
If id has a value >0 the specification will be ignored.
enabledOnly int 1 Only search for the activated entries

1 - The found entry must be activated. If no active entry is found for the provided ID or alias name, the result is an empty string.
0 - The path of the first found entry is returned. No test is made if this entry is activated.
autoResolve int 1 Define complete path for the result

0 - The found path of the ID of the alias name will be returned unchanged.
1 - Complete result paths are calculated relative to the current XML data folder.

Version 1.2.2, 11. October 2005.
The parameter enabled is implemented since Version 1.2.2, 7 November 2005.

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

resolve_alias
comet.file.getDataFile

static int enable_datafile(
  int state,
  int id,
  char* name = "")

Get the path of a data file classification.

Name Type Default Description
Return int   0 or ErrorCode
state int - New status of the classification. If a classification is activated all classifications are automatically deactivated with the same alias name.
0 deactivate
> 0 activate
id int - ID of the entry
0 : Ignore the ID and use the name for the identification of the entry. The alias names for the classification must not be unique.
name String or char* 0 Name of the entry
If id has a value >0 the specification will be ignored.

Version 1.3.4 (P/R 107)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int count(char* path)

Number of elements in a folder

Name Type Default Description
Return int   Number of sub object of a folder
0 : Path not found or not a a folder
path String or char* - full folder path optionally beginning with $DESKTOP, ...

Version 1.3.4 (P/R 107)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

get_nth

static char* get_nth(char* path, int n)

Get the nth element of a folder

Name Type Default Description
Return char*   full path to the nth element

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

path String oder char* - full folder path optionally beginning with $DESKTOP, ...
n int - 0-based element index

write all elements of a folder (recursively) to the log file

int dofile (char * path)
{
    // Do anything with the file
    return 0;
}
int wpath (char * path, int depth, int isfile) { int i; char name[256];
strcpy (name, file::name (name, path));
for (i = 0; i< depth; i++) wlog ("", "\t", depth); if (!isfile) wlog ("", "> "); wlog ("", "%s\n", name);
return 0; }
int isvisible (char * path) { char name [256];
strcpy (name, file::name (name, path)); return (name[0] != '.'); }
int dofolder (char* path, int depth) { int c = file::count (path); int n;
for (n = 0; n < c; n++) { char sub[4069]; strcpy (sub, file::get_nth (path, n)); if (isvisible (sub)) { wpath (sub, depth, !file::isfolder (sub)); if (file::isfile (sub)) dofile (sub); else dofolder (sub, depth+1); } }
return 0; }
int main () { dofolder ("$DESKTOP/test/Bächli Platzierung/Costa Rica", 0); return 0; }

Version 1.3.4 (P/R 107)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

count

static int wait(
  char* path,
  int time_ms,
  int intervall = 10)

Test whether a file exist.

Name Type Default Description
Return bool   1 : file exists
0 : otherwise
path String oder char* - complete path to file, may begin with $DESKTOP, ... ..
time_ms int - time to wait in milliseconds
intervall int 10 Polling intervall in milliseconds

Wait a maximum of 10 minutes for a file.

int main ()
{
    int 	exists;
// Wait maximum 10 minutes for the file "printout.pdf", test every second // exists = file::wait ("$DESKTOP/printout.pdf", 600000, 1000); showmessage ("Printing %s", (exists ? "successful" : "failed");
return 0; }

Version 1.4.2 / 2.0 (R603)

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static char* uncurtain(char* path)

Uncurtain all available $-keys in the given string. $-keys are not only the standards $HOME, $DESKTOP, $DOCUMENTS, $PREFS, $PLUGINS, $COMET, $CACHE and $COMETDATA, but also all activated aliasses defined in the Settings panel.

Name Type Default Description
Return char*   All available $-keys are replaced in a copy of path.

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

path String or char* - Any path. The string remains unchanged.

Version 2.0 R634, 21. Mar 2008

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

getdatafile
setdatafile
comet.uncurtain

static int zip(
  char* srcPath,
  char* zipPath = "",
  int keepRsrc = 1,
  int level = 9)

Create a ZIP archive from of a file or folder.

Name Type Default Description
Return int   0 or ErrorCode
srcPath String or char* - Complete path and name of the object to archive
zipPath String or char* "" Archive path. If the path does not exist, it will be created. An existing archive will oberriden by the call.

0 or "" : Same folder and name like the source but with .zip appended to the name
ends with / : use the given folder as destination and the source name appended with .zip as name
otherwise : complete destination path and name of archive (should end with .zip)
keepRsrc int 1 Keep resource fork? The parameter is ignored under Windows.

As of v4.1.7 R27138 the parameter is no longer evaluated and always the setting 0 (--norsrc) is used. The background is that archives packed with resource data can be reliably unpacked only if the original file is located on a hard disk partition formated with Mac OS Extended or Mac OS Journaled. For all other formatting (e.g. Mac OS AFS+, Mac OS AFPS, Windows, Linux), the option --rsrc may cause problems when unpacking.

0 : Resource fork not included in the archive (--norsrc)
1 : Resource fork included in the archive ( (--rsrc)
level int 9 Compression level? Ignored on Windows.

0 : No compression
9 : optimal (but slowest) compression

Create some archives

int main ()
{
    // File zip
    wlog ("", "zip 1 : %d\n", file::zip ("$DESKTOP/zipit/P 1.rtfd", 	"$DESKTOP/zipit/P 1.zip"));
    wlog ("", "zip 2 : %d\n", file::zip ("$DESKTOP/zipit/P 1.rtfd",	"$DESKTOP/zipit/P 1/aaa/bbb/P 1.zip"));
wlog ("", "zip 3 : %d\n", file::zip ("$DESKTOP/zipit/P 2.rtfd", "")); wlog ("", "zip 4 : %d\n", file::zip ("$DESKTOP/zipit/P 2.rtfd", "$DESKTOP/zipit/P 2/aaa/bbb/"));
// Mac resources wlog ("", "zip 3 : %d\n", file::zip ("$DESKTOP/zipit/Resfile.rsrc", ""));
// Ordner-ZIP wlog ("", "zip 5 : %d\n", file::zip ("$DESKTOP/zipit/aaaäö 2", ""));
return 0; }

Version 3.1 R1784, 3.3.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

unzip

static int unzip(
  char* zipPath,
  char* destPath = "",
  int keepRsrc = 1,
  StringList resultList = 0,
  int action = 2)

Extract from out from an archive.

Name Type Default Description
Return int   0 or ErrorCode
zipPath String or char* - Complete path of an ZIP archive
destPath String or char* "" Folder to decompress. If the folder does not exist, it is created. Unzip overwrites existing objects in the destination folder.

0 or "" : Decompressing is done in the archives folder
otherwise : Decompress here
keepRsrc int 1 Keep resource fork? The parameter is ignored under Windows.

As of v4.1.7 R27138 the parameter is no longer evaluated and always the setting 0 (--norsrc) is used. The background is that archives packed with resource data can be reliably unpacked only if the original file is located on a hard disk partition formated with Mac OS Extended or Mac OS Journaled. For all other formatting (e.g. Mac OS AFS+, Mac OS AFPS, Windows, Linux), the option --rsrc may cause problems when unpacking.
resultList StringList 0 allcoted StringList for the results
action int 2 What to do?

0 : No decompressing is done, but resultList is filled with the top level entries of the archive. Objects starting with a dot or with __MACOSX are not taken to the list.

1 : No decompressing is done, but resultList is filled with the entries of the archive. Objects starting with a dot or with __MACOSX are not taken to the list.

2 : Decompress archive. resultList contains the top level entries of the archive.
int main ()
{
    StringList			archi	= stringlist::alloc ();
    char			*	str;
wlog ("", "Top level entries of Archive 2.zip\n"); file::unzip ("$DESKTOP/zipit/Archiv 2.zip", "", 1, archi, 0); for (str = stringlist::first (archi); str; str = stringlist::next (archi)) { wlog ("", "\t'%s'\n", str); }
wlog ("", "Entries of Archive 2.zip\n"); file::unzip ("$DESKTOP/zipit/Archiv 2.zip", "$DESKTOP/aaa", 1, archi, 1); for (str = stringlist::first (archi); str; str = stringlist::next (archi)) { wlog ("", "\t'%s'\n", str); }
file::unzip ("$DESKTOP/zipit/Archiv 2.zip", ""); file::unzip ("$DESKTOP/zipit/aaaäöääßäääß.zip", ""); file::unzip ("$DESKTOP/zipit/P 1.zip", "");
file::unzip ("$DESKTOP/zipit/Bild.jpg.zip", "", 1, archi); file::rename (stringlist::first (archi), "Bild 2 mit Resourcefork.jpg");
file::unzip ("$DESKTOP/zipit/Bild.jpg.zip", "", 0, archi); file::rename (stringlist::first (archi), "Bild 2 ohne Resourcefork.jpg");
return 0; }

Version 3.1 R1784, 3.3.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

zip

static int get_date(
  char* fullpath,
  int whatDate,
  int dt_type,
  char* result = 0)

Get datetime of file.

Name Type Default Description
Return int   0 or ErrorCode
fullpath String or char* - Complete path to file or folder
whatDate int - Which information should be fetched?

kDateCreated
kDateModified
kDateAttributes
kDateAccess
kDateBackup

Not every platform/operating system supports all of the information types.
dt_type int - kShortDateTime Format specification

system depended
kShortDate (= 0)
kLongDate (= 1)
kAbbrevDate (= 2)
kShortTime (= 20)
kLongTime (= 36)
kShortDateTime (= 16)
kLongDateTime (= 17)
kAbbrevDateTime (= 18)
kShortDateLongTime (= 32)
kLongDateLongTime (= 33)
kAbbrevDateLongTime (= 34)
system undependend
ddmmyyyy (= 96)
ddmmyyyy_hhmm (= 97)
ddmmyyyy_hhmmss (= 98)
dmyy (= 99)
hhmm (= 100)
hhmmss (= 101)
hmm (= 102)
hmmss (= 103)
result String or char* - Reserved memory for the result
#include "internal/types.h"
#include "internal/types.h"
int get_date (char * fi, char * mess) { char created [512]; char modified [512];
file::get_date (fi, kDateCreated, kShortDateTime, created); file::get_date (fi, kDateModified, kShortDateTime, modified);
wlog ("", "# %s\n", fi); wlog ("", "# %s\n", mess); wlog ("", "# created : %s\n", created); wlog ("", "# modified : %s\n", modified);
return 0; }
int main () { char fi [512];
strcpy (fi, "$DESKTOP/2076.indd");
get_date (fi, "Before");
file::set_date (fi, kDateCreated, "17.02.1975 16:08:56"); file::set_date (fi, kDateModified, 26, 11, 2008, 19, 10, 34);
get_date (fi, "After");
return 0; }

Version 3.1 R2114, 9.9.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

set_date
system::now

static int set_date(
  char* fullpath,
  int whatDate,
  char* dt = 0)

Change a files date and time.

Name Type Default Description
Return int   0 or ErrorCode
fullpath String or char* - Complete path to file or folder
whatDate int - Which information should be set?

kDateCreated
kDateModified
kDateAttributes
kDateAccess
kDateBackup

Not every platform/operating system supports every of the information types.
~ System depended date-time string
dt String or char* - valid date-time string
~ System undependend date and time
day, month, year int, int, int - Date
hour, minutes, seconds int, int, int - Time
#include "internal/types.h"

Version 3.1 R2114, 9.9.2010

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

get_date
system::now

static char* md5hash(char* fullpath, int doUpper = 0)

Get the md5hash of a file.

Name Type Default Description
Return char*   32 hex digits long md5hash of the file.

The return value is read only, do NOT CHANGE. The result will be overridden on following calls to the function. See here to learn more about functions returning r/o char* values.

fullpath String or char* - Complete path to a file
doUpper int 0 Use capital letters for hex numbers?

0 : no
1 : yes

Get the md5hash of the current script documents file.

int main ()
{
    char		path [2000];
document::path (path, 0); wlog ("", "MD5Hash '%s' : '%s'\n", path, file::md5hash (path));
return 0; }

Version 3.2.2 R2366, 2803.2011
doUpper since v4.0.4 R7230, 8. Jan 2015

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

static int pdf_count_pages(char* path, int usePDFlib = 0)

Get the number of pages in a PDF document.

Name Type Default Description
Return int   >0 : Number of pages in the PDF
Otherwise : error
path String or char* - Complete path to the PDF. The name must have the (case insensitive) extension "pdf".
usePDFlib int 0 Use PDFlib for querying?

0 : No

1 : Use PDFlib (InDesign® and comet_pdf only). The use of PDFlib is subject to licensing. You will need a PDFlib+PDI license for PDFlib 10. Licenses can be purchased here. The license file must have the name licensekeys.txt and be located in the Plug-Ins folder of your InDesign resp. in the program folder of comet_pdf.

Currently (Jan. 2023) the PDFlib+PDI license costs $2,780 for server systems, $1,050 for desktop applications. So it is definitely worth testing the direct query with usePDFlib = 0 beforehand.

Use the following script to test file::pdf_count_pages. In a text frame you write the following text "number /path/to/your/PDF.pdf" where number is the correct number of pages of the PDF. Then run the script and see the log file.

int main ()
{
    String		str			= string::alloc ();
    int			pg;
    int			expected	= -12;
    char		chk			[256];
    char		path		[1024];
    char		name		[512];
frame::gettext (gFrame, str); expected = string::to_int (string::get_token (str, " ", 0)); strcpy (path, strsubstring (string::get (str), string::length (string::get_token (str, " ", 0)) + 1, -1));
pg = file::pdf_count_pages (path);
if (expected == pg) strcpy (chk, "okay"); else strcpy (chk, "ERROR"); wlog ("", "# Pages :\t%d\t%s\t'%s'\n", pg, chk, file::name (name, path));
return 0; }

Parameter usePDFlib v4.2 R32230, 31. Jan 2023 v3.4 R5322, 22. Mai 2014

priint:comet InDesign® Plug-Ins, comet_pdf, Illustrator

comet.file.PDFCountPages

static int aem_put_asset(
  char* url,
  char* user,
  char* password,
  char* assetpath,
  char* sourcepath = 0,
  char* mimetype = 0)

EXPERIMENTAL! Create and update assets and folders of an AEM® (Adobe Experience Manager®). Folder paths are automatically created in the AEM® if they do not already exist. Existing folders remain unchanged.

Name Type Default Description
Return int   0 or ErrorCode
url String oder char* - URL of AEM®
user String oder char* - User name to login into AEM®
password String oder char* - Paasword of user
assetpath String oder char* - Complete path of asset in the asset component of the AEM®. Non-existent folders are created automatically. Existing folders remain unchanged.

0 or empty : root folder ("/")
sourcepath String oder char* 0 Complete path to file of asset

"" or 0 : Create asset folder assetpath only
mimetype String oder char* 0 Mime type of asset, e.g. image/jpeg

"" or 0 : Try to get the mime type from the file extension itself
// Connection data
char	stHost []	= "http://192.168.0.208:4502";
char 	stUser []	= "admin";
char 	stPwd []	= "*****";
int main () { int result; int recbytes = -1;
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg", //Folder is created, if needed   "$DESKTOP/schnipp Kopie.jpg"); wlog ("", "Create/Update asset 1 : %d\n", result);
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg", //Folder is created, if needed   "$DESKTOP/rot.JPG"); wlog ("", "Create/Update asset 2 : %d\n", result);
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/qwertzu/Paul Seidel",   ""); // Create folder only wlog ("", "Create folder : %d\n", result);
result = file::aem_get_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg/schnipp Kopie.jpg",   "$DESKTOP/qwertzu_bild.jpg"   &recbytes); wlog ("", "Download asset : %d, %d bytes received\n", result, recbytes);
return 0; }

v4.1 R22145, 28. Mar 2018

priint:comet InDesign® Plug-Ins, comet_pdf

aem_get_asset
datapool::aem_get_list

static int aem_get_asset(
  char* url,
  char* user,
  char* password,
  char* assetpath,
  char* destpath,
  char* deststr = 0,
  int* maxlen = 0)

EXPERIMENTAL! Download an AEM® (Adobe Experience Manager®) asset. You may download the asset into a file or into a string.

Name Type Default Description
Return int   0 or ErrorCode
url String oder char* - URL of AEM®

@aem at the beginning : String contain the complete URL incl. username, password and asset path. The values of user, password and assetpath are ignored in this case.
user String oder char* - User name to login into AEM®
password String oder char* - Paasword of user
assetpath String oder char* - Complete path of asset in the asset component of the AEM®. Non-existent folders are created automatically. Existing folders remain unchanged.

0 or empty : root folder ("/")
destpath String oder char* - Complete path of destination file. Existing files are overridden!

"" or 0 : Write result into deststr.
deststr String oder char* 0 Result string, used only if destpath is 0 or empty.

Please note that the string may contain 0 bytes in case of binary files! To get the full data in this case, please use string::data.
maxlen int* 0 Attention : The variable is a pointer!

On input the variable is used only if destpath is 0 or empty and if deststr is of type char* (and not String). In this case, the content of the variable is used as the maximum length for deststr. The rest of the result is cut off. Attention:Truncated results can lead to serious problems in case of binary data or incomplete UTF-8 letters:

    0 or content < 0 : any length
    otherwiese : maximum length, see above

After successful execution the variable contains the number of bytes received from the AEM®. If deststr is of type String, you may use string::data in case of binary data.

    0 : ignore
    otherwise : number of received bytes
// Connection data
char	stHost []	= "http://192.168.0.208:4502";
char 	stUser []	= "admin";
char 	stPwd []	= "*****";
int main () { int result; int recbytes = -1;
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg", //Folder is created, if needed   "$DESKTOP/schnipp Kopie.jpg"); wlog ("", "Create/Update asset 1 : %d\n", result);
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg", //Folder is created, if needed   "$DESKTOP/rot.JPG"); wlog ("", "Create/Update asset 2 : %d\n", result);
result = file::aem_put_asset (   stHost, stUser, stPwd,   "/qwertzu/Paul Seidel",   ""); // Create folder only wlog ("", "Create folder : %d\n", result);
result = file::aem_get_asset (   stHost, stUser, stPwd,   "/aaa/bbb/ccc 12/ddded-fgg/schnipp Kopie.jpg",   "$DESKTOP/qwertzu_bild.jpg"   &recbytes); wlog ("", "Download asset : %d, %d bytes received\n", result, recbytes);
return 0; }

v4.1 R22145, 28. Mar 2018

priint:comet InDesign® Plug-Ins, comet_pdf

aem_put_asset
datapool::aem_get_list

Author
Paul Seidel
Version
16.10.2024, 11:40 Uhr
Since
Plugin Version 1.0.18

Alphabetic index HTML hierarchy of classes or Java