importOptions is foxing me

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

Hi all,
I'm being stumped by the correct implimentation of importOptions.

All I'd like to do is to import a single file sequence. Can someone demonstrate the correct syntax!?

Thanks,
Dave
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Here's a function from one of my scripts that should help, it also includes a couple of workarounds, one to get past the Mac's hidden ".DS_store" file, and another for a bug which means you have to use force alphabetical if importing long filenames.

I think there may also be another bug to watch out for when using importFile more than once, where the importFile function won't always return the correct file (i.e. although it will import the correct file, the function might return the previous file you imported), making it tricky if you're creating an array of imported files at the same time, not 100% sure about this though.

Paul T

Code: Select all

	function importFromFolder(theFolder) {
		//alert("checking " + theFolder.name);
		var filesInFolder = theFolder.getFiles();

		// if there are files in the folder
		if (filesInFolder.length > 0) { 
			//alert("checking 0 " + filesInFolder[0].name);
			// if the first file is a file, but isn't a DSstore file, import sequence
			if (filesInFolder[0] instanceof File && filesInFolder[0].name != ".DS_Store") {

						//alert("trying to import " + theFolder.name + " " + filesInFolder[0].name);
						//alert("filename has " + filesInFolder[0].name.toString().length);
				fileString = filesInFolder[0].name.toString();
				my_io = new ImportOptions(filesInFolder[0]);
				my_io.sequence = true;

				if (fileString.length > 31) {
					my_io.forceAlphabetical = true;
				}

				currentLength = importedFiles.length;
				if (currentLength > 0) {
					app.project.item(1).selected = false;
					app.project.item(currentLength).selected = false;
				}	

				try { importedFiles[currentLength] = app.project.importFile(my_io);
				} catch(e) { }

				if (importedFiles.length == (currentLength + 1)) {
					importedFilenames[currentLength] = fileString;
					//theFolder = app.project.items.folder("folder").create();
							//alert("added " + importedFilenames[currentLength]);
				}
			} else {
				//  if first file is a DS store and there's another file in the folder and the second file is a file.
				if (filesInFolder[0].name == ".DS_Store" && filesInFolder.length > 1 && filesInFolder[1] instanceof File) {
						//alert("checking 1 " + filesInFolder[1].name);

								//alert("trying to import " + theFolder.name + " " + filesInFolder[1].name);
								//alert("filename has " + filesInFolder[1].name.toString().length);
						fileString = filesInFolder[1].name.toString();
						my_io = new ImportOptions(filesInFolder[1]);
						my_io.sequence = true;

						if (fileString.length > 31) {
							my_io.forceAlphabetical = true;
						}

						currentLength = importedFiles.length;

						if (currentLength > 0) {
							app.project.item(1).selected = false;
							app.project.item(currentLength).selected = false;
						}

						try { importedFiles[importedFiles.length] = app.project.importFile(my_io);
						} catch(e) { }

						if (importedFiles.length == (currentLength + 1)) {
							importedFilenames[currentLength] = fileString;
									//alert("added " + importedFilenames[currentLength]);
						}
				} else {
					for (var f = 0; f < filesInFolder.length; f++) {
						//alert("checking is folder " + filesInFolder[f].name);
						if (filesInFolder[f] instanceof Folder) {
							importFromFolder(filesInFolder[f]);
						}
					}
				}
			}
		}
	}	
		
davestewart
Posts: 114
Joined: March 10th, 2005, 5:50 am
Location: London, UK
Contact:

Jesus! Thanks Paul, that looks remarkably thorough. Hopefully I'll just need the io bit, but I appreciate it.

Cheers!
Dave
Post Reply