swftools-common
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swftools-common] outputting multiple files


From: Daichi Shinozaki
Subject: Re: [Swftools-common] outputting multiple files
Date: Tue, 01 Feb 2005 22:59:05 +0900
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040616

Hi,

Kurzius, Brian wrote:
> This is a great tool but I have a pretty simple question that can save 
> me a LOT of time.
>  
> I have a couple of hundred .pdf files which need to be converted to 
> .swf. I've tried using this command: pdf2swf *.pdf, but this doesm't 
> accept wildcards. In windows is there another way that I can go through 
> the contents of a directory and convert all of the files to 
> .swf--without creating a batch file with a line for each conversion?

A while ago I had same problem, so I wrote a script
that scan the current directory and convert all pdf files found to swfs.

Tested with Windows XP SP1 / swftools v0.6.2.

Quick usage:
1) Save the script as pdfs2swfs.js
2) Copy it to c:\swftools\
3) Open the command prompt.
   (To open command prompt, click Start, point to All Programs,
   point to Accessories, and then click Command Prompt.)
4) In the command prompt, cd to target directory using cd command.
   example: cd c:\pdf
5) In the command prompt, type:
   cscript c:\swftools\pdfs2swfs.js

         O        [pdfs2swfs.js]
_________\/______ Please snip and save _____________________
         /\
         O

// $Id: pdfs2swfs.js,v 0.1 2005-02-01 19:27:00+09 dseg Exp $
// Title: pdfs2swfs.js
// Author: Daichi Shinozaki <address@hidden>
// Usage:
//   1) Copy this script to c:\swftools\ .
//   2) Open the command prompt,
//      change to target directory using 'cd' command.
//      example: cd c:\pdf
//   3) type:
//      cscript c:\swftools\pdfs2swfs.js
//      All pdfs under the directory will be converted to swfs.

//
// parameteres
//
var opts = '';    // additional commandline option
var ext = '.pdf'; // extension of target files
//var exe = 'pdf2swf.exe';
var exe = 'c:\\swftools\\pdf2swf.exe';
var dir = "";     // target directory to scan.
                  // if empty, scan the current directory

// =====================================================================
// Main

var WshShell = WScript.CreateObject('WScript.Shell');
if(dir == "")
    dir = WshShell.CurrentDirectory;
var gTargetFiles = [];
var fso = new ActiveXObject("Scripting.FileSystemObject");
var processed = 0;

scandir(dir, ext);

for(var i=0; i<gTargetFiles.length; i++) {
    var swf = removeExt(gTargetFiles[i]) + ".swf";
    var cmd = exe;
    if(opts != undefined && opts != '')
        cmd += ' ' + opts;
    cmd += ' ' + gTargetFiles[i] + ' -o ' + swf;

    if(WshShell.Run(cmd, 10, true) == 0)
        ++processed;
}
if(processed > 0)
    WScript.echo('Sucessfully converted ' + processed + ' files.');

// ---------------------------------------------------------------------
// Functions

// scandir() originally written by Daren Thiel.
// ** http://www.winscripter.com/WSH/FileIO/75.aspx

function scandir(dir, extension) {
    // Get Current Folder
    var srcFolder = fso.GetFolder(dir);

    //msg += "Folder: " + srcFolder.Name + "\n";

    // Get Files in current directory
    var files = new Enumerator( srcFolder.files );
    var re = new RegExp('\\' + extension + '$', 'i'); // <= /\.pdf$/i

    // Loop through files
    for(; !files.atEnd(); files.moveNext()) {
        if(re.test(files.item().Name))
            gTargetFiles.push(dir + "\\" + files.item().Name);
    }

    // Display the data get gathered. (Folder Name and Files)
    //WScript.Echo(msg);

    // Clear the variable for the next directory
    //msg = "";

    // Get any sub folders to current directory
    var esub = new Enumerator(srcFolder.SubFolders);

    // Loop through sub folder list and scan
    // through a recursive call to this function
    for(; !esub.atEnd(); esub.moveNext()) {
        var f = fso.GetFolder(esub.item());
        scandir(f, ext);
    }
}

function removeExt(s) {
    s.match(/(.*)\..*/i);

    return RegExp.$1 ? RegExp.$1 : undefined;
}

____________________________________________________________

Hope this helps,

--
Daichi Shinozaki
SHIELD.JP Admin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]