Copy link to clipboard
Copied
Hi
I need a script that move files to a folder with the same name as the first 8 characters of the file name, that has to be moved. If the folder doesn't exist, it has to be created. I'm new in Javascript! Can anybody help me??
thanx
...function createFolder(file) {
var parentFolder = file.parent;
var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
if( !saveFolder.exists ) saveFolder.create();
var saveFile = new File( saveFolder + '/' + file.name);
if( file.copy( saveFile ) ) file.remove();
}function main() {
var folder = new Folder("~/Desktop/images");
var files = folder.getFiles();
for (var i = 0; i < files.length; i++) {
var f = files;
if (f instanceof File) {
createFolder(
Copy link to clipboard
Copied
Need more details. Where are the files now? Where do you want the new folder? etc
Copy link to clipboard
Copied
The files are placed in a folder by a workflow. The new folder can be a subfolder to the workflow output folder, where the files where picked up. But that's not the major issue, I can change the path, if it is needed.
Copy link to clipboard
Copied
var file = new File( '/c/temp4/SLIP762011.jpg' );
var parentFolder = file.parent;
var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
if( !saveFolder.exists ) saveFolder.create();
var saveFile = new File( saveFolder + '/' + file.name);
if( file.copy( saveFile ) ) file.remove();
Copy link to clipboard
Copied
Hi Michael
This is very close, but I need to pick up every file in a specific folder (hotfolder), not just one file. Is this posible?
Copy link to clipboard
Copied
function createFolder(file) {
var parentFolder = file.parent;
var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
if( !saveFolder.exists ) saveFolder.create();
var saveFile = new File( saveFolder + '/' + file.name);
if( file.copy( saveFile ) ) file.remove();
}function main() {
var folder = new Folder("~/Desktop/images");
var files = folder.getFiles();
for (var i = 0; i < files.length; i++) {
var f = files;
if (f instanceof File) {
createFolder(f);
}
}
};
main();
Something like that should work.
Copy link to clipboard
Copied
This couldn't been any better, a lot of thanks from here.