• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export to subfolder by removing the original extension.

Contributor ,
Nov 08, 2018 Nov 08, 2018

Copy link to clipboard

Copied

Hello!

I'm trying to edit a script that creates a JPEG copy of the document in a subfolder but I could not fix this problem:

Screenshot_1.jpg

How to save only the document name?

Script:

var subfolder = "BackupFolder";     

        if (app.documents.length > 0) {       

            var thedoc = app.activeDocument;       

                          

            var docName = thedoc.name;       

            var basename = docName;       

            if (docName.indexOf(".") != -1)       

             basename = docName.match(/(.*)\.[^\.]+$/)[1]       

  

            var docPath = "~/Desktop";       

            try {       

                docPath = thedoc.path;       

            } catch (e) {}       

                 

           var jpegOptions = new JPEGSaveOptions();     

            jpegOptions.quality = 9;     

            jpegOptions.embedColorProfile = true;     

            jpegOptions.matte = MatteType.NONE;       

        

            //save tif as a copy:         

            if (!Folder(docPath + "/" + subfolder).exists) Folder(docPath + "/" + subfolder).create();     

            var saveFile = docPath + '/' + subfolder + '/' + thedoc.name +'.jpg';         

            if (File(saveFile).exists)         

                saveFile = incrementFile(saveFile);         

                    

            thedoc.saveAs(new File(saveFile), jpegOptions, true);        

        };       

       

        function incrementFile(pathToFile) {       

            var saveSufixLength = 2,       

                suffix = zeroPad(0, saveSufixLength),       

                newPathToFile = pathToFile,       

                suffixInteger, folder, fileName, extension;       

       

            while (File(newPathToFile).exists) {       

                suffixInteger = parseInt(suffix, 10);       

                suffixInteger += 1;       

                suffix = zeroPad(suffixInteger, saveSufixLength);       

                folder = File(pathToFile).path;       

                fileName = File(pathToFile).name.substring(0, File(pathToFile).name.lastIndexOf("."));       

                extension = File(pathToFile).name.substring(File(pathToFile).name.lastIndexOf(".") + 1, File(pathToFile).name.length);       

       

                newPathToFile = folder + "/" + fileName + "_" + suffix + "." + extension;       

            }       

            return newPathToFile;       

      

               function zeroPad(num, digit) {       

                var tmp = num.toString();       

                while (tmp.length < digit) {       

                    tmp = "0" + tmp;       

                }       

                return tmp;       

            }       

        }       

TOPICS
Actions and scripting

Views

608

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
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 08, 2018 Nov 08, 2018

(untestet) but it seems

var saveFile = docPath + '/' + subfolder + '/' + thedoc.name +'.jpg';

should be:

var saveFile = docPath + '/' + subfolder + '/' + basename +'.jpg';

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 08, 2018 Nov 08, 2018

Copy link to clipboard

Copied

(untestet) but it seems

var saveFile = docPath + '/' + subfolder + '/' + thedoc.name +'.jpg';

should be:

var saveFile = docPath + '/' + subfolder + '/' + basename +'.jpg';

Votes

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
community guidelines
Contributor ,
Nov 08, 2018 Nov 08, 2018

Copy link to clipboard

Copied

LATEST

Perfect! Thank you pixxxel schubser.

Votes

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
community guidelines