2.86 FAQ-870 How to extract file name without extension to column comments?
Last Update: 1/7/2019
Origin 2017 SR2 and higher
From Origin 2017 SR2, you can check Append Filename to Column Comment and uncheck Include File Path when Appending Filename under (Re)naming Worksheet and Workbook branch of any import tools to extract file name without extension to column Comments.
|Notes:. If you want to include file extension when append file name to column Comments, you can use the Set System Variables dialog for the job. Choose Preferences: System Variables to open the dialog. Set IFE to 0.
Origin 2017 SR1 and older
For older versions, when checking "Append File name to Column Comments", file extension will be included by default. So you need to import data through Import Wizard, during which you can create a new parameter in the workbook that specifies the file name without file extension, and then copy file name from parameter row to column Comments.
- Select Data: Import from File: Import Wizard.
- Select your data under Data Source. Select the desired import mode within Import Mode. Click Next.
- Customize header lines settings on Header Lines page if needed. Click Next.
- From Extract variables from file names and file headers select Specify location of variable names and values using delimiters checkbox and select Create User Parameter rows for each variable, Select Next.
- In the following page, the top white box should list the file name with and without the extension. Under Variable, select the line you wish to add. Select Enter variable name and specify the name. Select Add. This will specify your new variable in the grey box. Select Next.
- Customize data column and skip column settings as prompted. Click Next under you see Save Filters page.
- Under Save filters, you can save this import wizard setting so that you do not have to repeat these steps every time you import a file. Select Save filter checkbox and under Filter Description name your filter.
- To take the file names in each column within the new parameter and put into the Comments row, select Specify advanced filters options checkbox. Click Next.
- In the white box under Script after All Files Imported input the below script and then click Finish. Note fname is the defined variable we gave for the new parameter created:
//The goal of this loop is to 1) place all the columns in fname row into the comments row and to 2) hide fname row
wcol(j)[C]$ =wcol(j)[fname]$; //places fname into comments
wks.UserParam1=0; //hides fname row in the workbook
To use this filter setting again, when you select Import Wizard you must initially select List filters applicable to both Data Type and file name under Import filter and then select from Import Filters to the current Data Type drop-down to select the filter you want to use.
If you don't do steps 8 and 9, the file name will be imported into the new parameter row. When you plot, the legend automatically lists the columns from Comments. To update the legend with file name, you will need to either
- redefine the legend as your new parameter
- Manually copy and paste the new parameter row into Comments.
Keywords:extract file name, trim file extension