Jump to content

How Do I Get the Input File's Name


amullen

Recommended Posts

I'm writing a rule in which I want the output file's name to be the input file's name with a ".pdf" extension instead of ".csv."

 

I've tried using

FusionPro.Composition.inputFileName 

in several ways, but it only returns a null string. I also tried using

GetFileName(FusionPro.Compsition.inputFileName)

but that didn't work either. I haven't been able to find any other way to access the input file's name. I need to load the input file's name into a string variable so it can be utilized in specific ways.

 

I already know how to create a new, rules-based output file. In past rules, those output files have had names that aren't based on the input file, and they work perfectly. The only sticking point is getting the output file to be named the same as the input file, but with a different extension.

 

Can anyone help with this?

Link to comment
Share on other sites

inFile = ToUpper(FusionPro.Composition.inputFileName);

 

You need to set it in the OnJobStartRule section. This will set a global variable called inFile to the value the string of the entire input file name...path and all. You can then manipulate it as you would like.

 

Our files come in with a job number then an underscore then the file name and extension. I parse it out thusly...

 

inFile = ToUpper(FusionPro.Composition.inputFileName);
var i = inFile.lastIndexOf("\\");
jobnbr_out = Mid(inFile, i+2, 5);
input_file = Mid(inFile, i+2, (inFile.length - i));
file_type = Mid(inFile, i+8, 2);

I'm not quite sure about the structure of paths on a mac or using is across different networks but the basic structure of the assignment should be the same.

Link to comment
Share on other sites

It should be as simple as putting this in the OnNewOutputFile callback rule:

if (!FusionPro.Composition.isPreview)
{
FusionPro.Composition.outputFileName = ReplaceFileExtension(GetFileName(FusionPro.Composition.inputFileName),"pdf");
}

 

However, I don't think you'll be able to access the input file name until the job is actually being composed.

Link to comment
Share on other sites

It should be as simple as putting this in the OnNewOutputFile callback rule:

if (!FusionPro.Composition.isPreview)
{
FusionPro.Composition.outputFileName = ReplaceFileExtension(GetFileName(FusionPro.Composition.inputFileName),"pdf");
}

However, I don't think you'll be able to access the input file name until the job is actually being composed.

Right, you don't see the file name when you're validating the rule in the editor. Like most of the properties of the FusionPro.Composition object, it's valid only at composition time.

 

FusionPro 9.2 will introduce some additional properties that you can access at rule validation time, including the original input file name, its format, and the delimiter, and will also make it easier to deal with Previews.

 

If you're running FusionPro 8.0 or later, I would suggest a minor change to Step's rule:

if (!FusionPro.Composition.isPreview)
{
    FusionPro.Composition.outputFileName = ReplaceFileExtension(GetFileName(FusionPro.Composition.inputFileName),
       FusionPro.Composition.outputFormatExtension);
}

Link to comment
Share on other sites

Dan,

 

I don't know if it is relative to this thread or not, but is there anyway to pad the zero's of the output batch? We have a number of jobs that batch well into the 100's and a few that go into the 1000's of batches. Some of our printer operators are getting confused when the files are listed in the job folders by default using numerical sortation where file "batch 2" would be listed in between "batch 19" and "batch 200" and "batch 100" could be listed before "batch 11". Not very savy.

 

Is there a way of forcing a number of padded zero's infront of the batch number?

 

Would that be an OnNewOutputFile javascript rule?

.

Link to comment
Share on other sites

Dan,

 

I don't know if it is relative to this thread or not, but is there anyway to pad the zero's of the output batch? We have a number of jobs that batch well into the 100's and a few that go into the 1000's of batches. Some of our printer operators are getting confused when the files are listed in the job folders by default using numerical sortation where file "batch 2" would be listed in between "batch 19" and "batch 200" and "batch 100" could be listed before "batch 11". Not very savy.

 

Is there a way of forcing a number of padded zero's infront of the batch number?

 

Would that be an OnNewOutputFile javascript rule?

.

Sure, you can use the FormatNumber function for this

 

You can do this in OnNewOutputFile (if you have static chunking set by checking the "Output to multiple files" box on the Output tab of the Composition Settings):

FusionPro.Composition.outputFileName = "batch-" +
   FormatNumber("000000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension;

Or you can do this in OnRecordStart if you're using arbitrary chunking:

FusionPro.Composition.OpenNewOutputFile("batch-" +
   FormatNumber("000000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension);

Link to comment
Share on other sites

I new there had to be a way to do it, thanks. However one last thought.

 

Since we process these larger jobs via FP Server, I assign the output file name as part of the command line. It would normally contains a six digit job number, a short description and lastly the extension. Something like "12345_outputName_.pdf", and then FP Server takes that base name and appends the batch numbers to it "12345_outputName_1.pdf", "12345_outputName_2.pdf", "12345_outputName_3.pdf", and so forth. If I use this javascript rule in the OnNewOutputFile rule

FusionPro.Composition.outputFileName = FusionPro.Composition.currentOutputFileName + "_" +
   FormatNumber("000000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension;

would that give me the resulting output on FP Server of "12345_outputName_000001.pdf", "12345_outputName_000002.pdf", "12345_outputName_000003.pdf", and so forth?

 

Additional note (09/23 am): I have tried the above command and - although I do not get an error or a warning from FusionPro - the resulting filename that I get using the FP Desktop version is named "undefined_000001.pdf"? Is the reason because Desktop does not work on a command line and just Server functionality would be able to comprehend such a object name? I do notice that Server and Desktop work slightly different than one another.

.

Edited by DSweet
Link to comment
Share on other sites

I new there had to be a way to do it, thanks. However one last thought.

 

Since we process these larger jobs via FP Server, I assign the output file name as part of the command line. It would normally contains a six digit job number, a short description and lastly the extension. Something like "12345_outputName_.pdf", and then FP Server takes that base name and appends the batch numbers to it "12345_outputName_1.pdf", "12345_outputName_2.pdf", "12345_outputName_3.pdf", and so forth. If I use this javascript rule in the OnNewOutputFile rule

FusionPro.Composition.outputFileName = FusionPro.Composition.currentOutputFileName + "_" +
   FormatNumber("000000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension;

would that give me the resulting output on FP Server of "12345_outputName_000001.pdf", "12345_outputName_000002.pdf", "12345_outputName_000003.pdf", and so forth?

 

Additional note (09/23 am): I have tried the above command and - although I do not get an error or a warning from FusionPro - the resulting filename that I get using the FP Desktop version is named "undefined_000001.pdf"? Is the reason because Desktop does not work on a command line and just Server functionality would be able to comprehend such a object name? I do notice that Server and Desktop work slightly different than one another.

.

Okay, we've kind of split this thread off into two threads now.

 

Anyway, there is no such property "FusionPro.Composition.currentOutputFileName". I'm not sure where you got that from; my example referenced "FusionPro.Composition.currentOutputFileNumber". You can use the Building Blocks dialog to browse through all the available valid properties, on the Objects tab.

 

The property I think you want is "FusionPro.Composition.outputFileName", which is what you're assigning to. However, that already has the chunk number appended to it. So you need to strip that off. I think this will do what you want:

var oldEnding = FusionPro.Composition.currentOutputFileNumber +
   "." + FusionPro.Composition.outputFormatExtension
var originalNameNoExt = FusionPro.Composition.outputFileName.replace(oldEnding, "");
FusionPro.Composition.outputFileName = originalNameNoExt + 
   FormatNumber("000000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension;

Link to comment
Share on other sites

I tried using the code as first described by DSweet. After several unsuccessful attempts, I was able to find what I believe to be the underlying issue.

 

When I load the input file name into a variable, then display a rule that merely returns that variable's value, I don't get the actual input file's name & path. I get a temporary file's name & path. It looks like this:

 

C:\DOCUME~1\FLOORT~1.PRE\LOCALS~1\TEMP\47650832_IN.TXT

 

I thought this occurred because I was accessing the input file from a network volume. I copied the file to the local machine's desktop, but the result is the same. I need to be able to access the actual input file's name.

 

Any suggestions?

This is because you're testing in Preview mode. For Preview, a single-record input data file is generated in the TEMP folder. If you do a regular composition (not a Preview), you'll see your actual data file path and name.

 

You could code around this in your rule, by testing the FusionPro.Composition.isPreview property, as in Step's post:

if (!FusionPro.Composition.isPreview)
{
FusionPro.Composition.outputFileName = ReplaceFileExtension(GetFileName(FusionPro.Composition.inputFileName),"pdf");
}

 

However, you say that the whole point of what you're trying to do is to change the output file name, which doesn't really make any sense for Preview anyway. So I wouldn't worry about testing something that's meant for non-Preview compositions in Preview mode.

 

Also, as I said before, FusionPro 9.2 will introduce some new properties that make it easier to access information about the input data source, even in Preview mode.

Link to comment
Share on other sites

Sorry about the confusion with sort of going off into left field with the original thread topic.

I'm not sure where you got that from; my example referenced "FusionPro.Composition.currentOutputFileNumber ". You can use the Building Blocks dialog to browse through all the available valid properties, on the Objects tab.

BTW I sort of came up with the name currentOutputFileName on my own, I just sort of follow some basic logic using ".currentOutputFileNumber" as being the batch numbers that FusionPro generates and ".outputFormatExtension" as the extension of the file and just came up with what I would think FusionPro might call the base name of the file iteslf from the command line call.

 

Thank you for your help. Your suggested coding worked...as it usually does.

.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...