cancel
Showing results for 
Search instead for 
Did you mean: 

MAX: .csv does not have .pdf extension in file name

We recieve a .csv file direct from a client. It has column that is the file name, but lacking the .pdf extension. My workflow works fine if I edit that column to add the extension, so I'm looking for the most straightforward way to automate adding that.

Appreciate any help,
-Dave

0 Kudos
2 Replies
DavidU54339-XRX
FreeFlow Production Workflow Moderator
FreeFlow Production Workflow Moderator

Re: MAX: .csv does not have .pdf extension in file name

In Excel, one could create another column and use the formula =A1&".pdf". This assume that the filename data is in column 1 and starts in row A. See below. The formula needs to be "dragged" the length of the new column.

p1.png

0 Kudos
StefanT-Xerox
FreeFlow User

Re: MAX: .csv does not have .pdf extension in file name

This can be done with a script on the hot folder. If you have csv that looks like this:

1;filename1
2;filename2

the attached Python script will add the .pdf extension like this:

1;filename1.pdf
2;filename2.pdf

If you want to give this a try then first install Python https://www.python.org/. You then need to install pandas with Python. From cmd as admin you can use "pip install pandas".

Upload both scripts (bat + py) to the FFCore scripts folder. In the bat file you likely need to change the path to where Python is installed as well as the path to the FFCore scripts folder.

Set the FFCore hot folder to "Execute Script Prior to Workflow" and select the bat file. Use the default parameters "$FFin$" "$FFout$"

You likely need to do the changes to the py file depending on your csv. This line controls how the file is read:

df = pd.read_csv(sys.argv[1], sep = ';', header=None)

This uses ; as delimiter and assumes there is no header. If you have some other delimiter, for instance | and a header,  change to this:

df = pd.read_csv(sys.argv[1], sep = '|')

The column to be added with the .pdf extension is controlled by the line:

df.iloc[:,1] = df.iloc[:,1]+'.pdf'

This is the second column. If you need to add this to the fifth column for instance, then change to:

df.iloc[:,4] = df.iloc[:,4]+'.pdf'

The writing of the new csv is controlled by the line:

df.to_csv(outfile, sep = ';', index=False, header=None)

You may need to change delimiter and add a header. Example:

df.to_csv(outfile, sep = '|', index=False)

The script also uses a temp folder which is "C:/Temp/".  You can use some other folder for this if you like. Use forward slashes for this. Example: D:/mytempfolder/

That's it.

Stefan

0 Kudos