Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* ************************************************************************
 #
 #  DivConq
 #
 #  http://divconq.com/
 #
 #  Copyright:
 #    Copyright 2014 eTimeline, LLC. All rights reserved.
 #
#  License:
#    See the license.txt file in the project's top-level directory for details.
#  Authors:
#    * Andy White
************************************************************************ */
package divconq.script.inst.file;
There is an implicit temp folder available to any script, it is only created on demand and is a global variable _TempFolder

Author(s):
andy
public class TempFile extends With {
	public void prepTarget(StackEntry stack) {
        String name = stack.stringFromSource("Name");
        
        if (StringUtil.isEmpty(name))
        	name = "TempFile_" + stack.getActivity().tempVarName();
        
        String vname = name;
        
        String tpath = stack.stringFromSource("Path");
        String text = stack.stringFromSource("Ext");
        
        if (StringUtil.isEmpty(tpath))
        	tpath = "/" + (StringUtil.isNotEmpty(text) ? FileUtil.randomFilename(text) : FileUtil.randomFilename());
        
        CommonPath path = null;
        
        try {
            path = new CommonPath(tpath);
        }
        catch (Exception x) {
			stack.log().errorTr(539);
			this.nextOpResume(stack);
			return;
        }
        Struct tf = stack.getActivity().queryVariable("_TempFolder");
        FileSystemDriver drv = null;
        
        if (tf instanceof FileSystemDriver) {
        	drv = (FileSystemDriver)tf;
        }
        else {
            Path tfpath = FileUtil.allocateTempFolder2();
            drv = new FileSystemDriver(tfpath);
            drv.isTemp(true);
            
            stack.getActivity().addVariable("_TempFolder"drv);
        }
        
        FileSystemFile fh = new FileSystemFile(drvpathfalse);
        
        stack.addVariable(vnamefh);
        this.setTarget(stackfh);
		this.nextOpResume(stack);
	}
New to GrepCode? Check out our FAQ X