MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   The JavaScript Library (http://forums.pti.com/forumdisplay.php?f=23)
-   -   Output Files to Specific Directory with OnJobStart (http://forums.pti.com/showthread.php?t=4861)

ReminderVDP April 18th, 2017 08:22 AM

Output Files to Specific Directory with OnJobStart
 
I'm working on a rule to output files to a specific directory based on the letter designation on a data file. And I'm getting some odd errors that I have never got before and I'm not certain my regex is correct for what I need to do.

Our data files are named as the following:
20170405(A or B)_STD_(PC or DM)_record numbers-.txt
i.e. 20170405A_STD_PC_1-20000-.txt

I'm looking to place these in the following location:
D:\FPDirect\Submitted\RUN 20170405A\20170405A_PC_ALL

I started with the following code in a OnJobStart rule and it returned code 1071. I tried it in a OnRecordStart rule and it returned code 1112.

Here is what I am trying in the rules. I'm a novice at regex so bear with my code if it is completely wrong.
------------
FusionPro.Composition.inputFileName = '[^2[0-9][0-9][0-9][0-9][0-9][0-9][0-9]A_STD_PC_1-[0-9][0-9][0-9][0-9][0-9]-.txt$]')

FusionPro.Composition.outputFileFullPathName = 'D:\FPDirect\Submitted\[^RUN 2[0-9][0-9][0-9][0-9][0-9][0-9][0-9]A\2[0-9][0-9][0-9][0-9][0-9][0-9][0-9]A_PC_ALL$]'

Any help would be appreciated. I am using the hot folders for the new Web Services dashboard and leaving the Output File location blank.

step April 18th, 2017 11:32 AM

Re: Output Files to Specific Directory with OnJobStart
 
You don't need to use regexp matching for this. Why not just split the input file name at the underscores?
Code:

var input = GetFileName(PrimaryInputFile()).split('_');
FusionPro.Composition.outputFileFullPathName = 'D:\\FPDirect\\Submitted\\RUN ' + input[0] + '\\' + input[0] + '_' + input[2] + '_ALL\\' + ReplaceFileExtension(input.join('_'), FusionPro.Composition.outputFormatExtension);


ReminderVDP April 18th, 2017 11:38 AM

Re: Output Files to Specific Directory with OnJobStart
 
Quote:

Originally Posted by step (Post 19997)
You don't need to use regexp matching for this. Why not just split the input file name at the underscores?
Code:

var input = GetFileName(PrimaryInputFile()).split('_');
FusionPro.Composition.outputFileFullPathName = 'D:\\FPDirect\\Submitted\\RUN ' + input[0] + '\\' + input[0] + '_' + input[2] + '_ALL\\' + ReplaceFileExtension(input.join('_'), FusionPro.Composition.outputFormatExtension);


Step,
Would that work for all the file names? This is a list of all the file names that I would need to compose to the correct folders:

20170405A_STD_DM_1-50000-.txt
20170405A_STD_DM_50001-100000-.txt
20170405A_STD_DM_100001-150000-.txt

Would it work for when the file name changes to a B after the run number? We alternate weeks from A to B on an 8 week cycle.

ReminderVDP April 18th, 2017 01:20 PM

Re: Output Files to Specific Directory with OnJobStart
 
I got it to work. The only issue I see is that all our data file names don't have the same number of input slots.

Thanks for your help!

step April 18th, 2017 02:10 PM

Re: Output Files to Specific Directory with OnJobStart
 
Quote:

Originally Posted by ReminderVDP (Post 19998)
Step,
Would that work for all the file names? This is a list of all the file names that I would need to compose to the correct folders:

20170405A_STD_DM_1-50000-.txt
20170405A_STD_DM_50001-100000-.txt
20170405A_STD_DM_100001-150000-.txt

Would it work for when the file name changes to a B after the run number? We alternate weeks from A to B on an 8 week cycle.

Yes, it would work for all of those scenarios. Here's a breakdown of what I mean by "splitting the input file name at the underscores" that may make it easier to visualize:
Code:

var input = PrimaryInputFile(); // /path/to/20170405A_STD_DM_1-50000-.txt
input = GetFileName(input);    // 20170405A_STD_DM_1-50000-.txt
input = input.split('_');      // [  '20170405A',    <--- input[0]
                                //    'STD',          <--- input[1]
                                //    'DM',            <--- input[2]
                                //    '1-50000-.txt']; <--- input[3]

As you can see, when the file name is split at the underscore, the first position in the resulting array (input[0]) will be the correct run number regardless of whether an A or B is used since it simply takes everything up until the first underscore as that value.

Quote:

Originally Posted by ReminderVDP (Post 20004)
The only issue I see is that all our data file names don't have the same number of input slots.

I don't know what that means.

ReminderVDP April 19th, 2017 05:21 AM

Re: Output Files to Specific Directory with OnJobStart
 
Step,
Thanks again for your help.

The part where I said the data file names don't have the same number of input slots is because we have proof files so when I have input[0], input[2] and I added an input[3], I get 20170405A_PC_test_undefined-.txt because we don't list the record numbers in the proof file names. As long as the files list the record numbers, I don't get an _undefined in the folder name.

Minor annoyance but we could just change our naming of the files.

step April 19th, 2017 06:00 AM

Re: Output Files to Specific Directory with OnJobStart
 
I see. You could just set that to a variable that returns an empty string when the record numbers are undefined:
Code:

var records = input[3] ? '_' + input[3] : '';

ReminderVDP April 25th, 2017 09:31 AM

Re: Output Files to Specific Directory with OnJobStart
 
That works great. Thanks again. If I were to strip the file extension from the folder name, would that happen in the variables? I tried it in the file path and it didn't do anything.


All times are GMT -7. The time now is 03:48 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.