Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

trim file path

i have field like below

c:/rootfolder/file1.txt

c:/rootfolder/file2.txt

how can i trim the path and only get file1.txt  file2.txt

1 Solution

Accepted Solutions
albertovarela
Partner - Specialist
Partner - Specialist

Hello, use the subfield function.  subfield('c:/rootfolder/file2.txt','/',-1) . BTW you might want to check your example.. it has forward slashes when they're supposed to be '\'...

hope this helps

View solution in original post

11 Replies
maxgro
MVP
MVP

=subfield('c:/rootfolder/file1.txt', '/', 3)

or filename, from online help

Returns a string containing the name of the table file currently being read, without path but including the extension.

Example:

Load *, filename( ) as X from

C:\UserFiles\abc.txt

Will return 'abc.txt' in field X in each record read.

albertovarela
Partner - Specialist
Partner - Specialist

Hello, use the subfield function.  subfield('c:/rootfolder/file2.txt','/',-1) . BTW you might want to check your example.. it has forward slashes when they're supposed to be '\'...

hope this helps

Not applicable
Author

how can i direct output of this code into qvd file.

set vRoot = 'C:\vbscript';

FOR Each Ext in 'qvd'

FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)

  Load subfield('$(File)','\',3) as Name, FileSize( '$(File)' ) as

  Size, FileTime( '$(File)' ) as FileTime

  autogenerate 1;

  next File

next Ext

Not applicable
Author

this will work

=subfield('c:/rootfolder/file1.txt', '/', 3)

albertovarela
Partner - Specialist
Partner - Specialist

Give your table a name then use the STORE statement:  e.g.


set vRoot = 'C:\vbscript';

  FOR Each Ext in 'qvd'

  FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)

   TableList:

   Load

    subfield('$(File)','\',-1)   as Name,  //

    FileSize( '$(File)' )       as Size,

    FileTime( '$(File)' )      as FileTime

   autogenerate 1;

   next File

  next Ext

STORE TableList into C:\path\TableList.qvd;

Not applicable
Author

I get syntax error and execution error when i do this:

set vRoot = 'C:\vbscript';

TableList:

  FOR Each Ext in 'qvd'

  FOR Each File in filelist ('$(vRoot)'&'\*.'&Ext)

   TableList:

   Load

    subfield('$(File)','\',-1)   as Name,  //

    FileSize( '$(File)' )       as Size,

    FileTime( '$(File)' )      as FileTime

   autogenerate 1;

   next File

  next Ext

STORE TableList into C:\path\TableList.qvd;

albertovarela
Partner - Specialist
Partner - Specialist

Are you using a valid path?

Not applicable
Author

yes

albertovarela
Partner - Specialist
Partner - Specialist

Delete the 3rd line on the script (where says TableList:). That will fix it. You are specifying the table name right before the LOAD statement