Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anuhyak1
Creator
Creator

Replace characters of a file. dynamically change first few characters of file with equivalent Tid.

Hello,

Read all the text files in that folder.

I have a text files in a folder like "13_22_pt.csv". 13 is Sid need to get equivalent Tid is 35. Replace the file with Tid "35_22_pt.csv" .  If no matching Tid is found replace with 'NA'. Attached excel sheet with example.

i/p : 13_22_pt.csv       o/p: 35_22_pt.csv 

 

1 Reply
mfchmielowski
Creator II
Creator II

Hi.

If you want to rename name of the file check https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Scripting/Scrip...

From my experience this is not a very safe way to handle file with qlikview. It's the BI tool. This issue i would handle by running some cmd or powershell script.

On the other hand: you can create subdirectory to have store created renamed files. This can be handled with for each loop

for each inFile in FileList('Input/*')
	
	TmpTable:
	load
		*
		// parse inputfileName according to requirements and name it as outputFileName
	;
	LOAD *
		, filename() as inputfileName
	FROM
	[$(inFile)]
	(txt, codepage is 1250, no labels, delimiter is '\t', msq);

	let outputFileName = peek('TmpTable', 0, 'outputFileName');
	
	drop fields inputfileName; // drop every other column you've created to create outputFileName column
	
	store TmpTable into 'Output/$(outputFileName).csv'(txt);
	
	drop table TmpTable;

next inFile;