Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

String handling of file Path

Hi all,

This is part of my script:

for each FoundFile in filelist( Root & '\*.csv') 

        let vTemp=  '$(FoundFile)';

        let vTemp2= upper(left(filename('$(FoundFile)'),len(filename('$(FoundFile)'))-21));

The result is:

vTemp"C:\decisioning\log\dcs\1\1\dcs_meta_data_20131126113434.csv"
vTemp2<NULL>

I'm trying to isolate the file name without the date stamp, extension and folders and to show it in upper case letters.

where am I wrong?

Thanks,

Boris

1 Solution

Accepted Solutions
MVP
MVP

Re: String handling of file Path

Sorry, my mistake:

let vFileName = mid('$(FoundFile)', index('$(FoundFile)', '\', -1) +1);

let vTemp2= upper(left('$(vFileName)', len('$(vFileName)') -21));

- Ralf

9 Replies
dfoster9
Valued Contributor

Re: String handling of file Path

I dont think you need the single quotes around your $(Foundfile) declarations.

Not applicable

Re: String handling of file Path

If I remove them then I don't get event a result for vTemp

dfoster9
Valued Contributor

Re: String handling of file Path

Sorry I misread the double quotes in your question. The issue is the filename function. It only works when loading data from a file. You should just look at using normal string functions.

please try:

LET vTemp2 = UPPER(RIGHT('$(vTemp)'),20);

MVP
MVP

Re: String handling of file Path

Hi

You don't need to use expansions in these expressions, and filename() only works in a LOAD statement. Rather use subfield(), like this:

for each vFoundFile in filelist( Root & '\*.csv')

  Let vTemp1 = SubField(vFoundFile, '\', -1);   // file name including extension

  Let vTemp2 = SubField(SubField(vFoundFile, '\', -1), '.', 1);   // file name excluding extension

...

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
MVP
MVP

Re: String handling of file Path

Hi Boris,

filename() function works only in a LOAD statement (see help). To extract the filename I would suggest to use index():

let vFileName = mid('$(FoundFile)', index('$(FoundFile)', '\', -1) +1);

let vTemp2= upper(left('$(FoundFile)', len('$(vFileName)') -21));

- Ralf

Not applicable

Re: String handling of file Path

Ok, but now I get the file name without the extension but with the date stamp.

how can I remove the date stamp?

if I use right function then I get the time stamp.

if I use left function I get partial names because each file has different name.

how can I remove only the date stamp and to get finally this result for the current path:

C:\decisioning\log\dcs\1\1\dcs_meta_data_20131126113434.csv

Result:   DCS_META_DATA

Not applicable

Re: String handling of file Path

Doesn't work.

get only c:\dec

dfoster9
Valued Contributor

Re: String handling of file Path

If it is a constant length then use left/right/mid functions to select what you need. If it is variable length then use the subfield function.

MVP
MVP

Re: String handling of file Path

Sorry, my mistake:

let vFileName = mid('$(FoundFile)', index('$(FoundFile)', '\', -1) +1);

let vTemp2= upper(left('$(vFileName)', len('$(vFileName)') -21));

- Ralf

Community Browser