Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

File type from file name

Former Member
0 Kudos
695

Hi,

Is there any standard method to get a file type from file name?

File name can be ‘C:\test.doc’ or “C:\test’(test – is file) i.e. with or without file type extension.

...Naddy

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos
307

You can use the Function module PC_SPLIT_COMPLETE_FILENAME

export paramter extension will tell the type of file

Sample Output

Import	COMPLETE_FILENAME	C:\TEST.TXT
Import	CHECK_DOS_FORMAT	
Export	DRIVE	C
Export	EXTENSION	TXT
Export	NAME	TEST
Export	NAME_WITH_EXT	TEST.TXT
Export	PATH	\

7 REPLIES 7

JozsefSzikszai
Active Contributor
0 Kudos
307

hi Naddy,

I think you can adopt the following logic:

check if the file name contains dot.

if yes split the file name at the dot into an internal table

the last line of the internal table will contain the extension

something like:

IF filename CA '.'.

SPLIT filename AT '.' INTO itab.

read last line of itab...

ENDIF.

hope this helps

ec

0 Kudos
307

Why we need to put into internal table?

Is string variable not enough?

what if file name without extension i.e. '.'?

...Naddy

0 Kudos
307

"Why we need to put into internal table?"

just to be sure, when there are more dots in the filename (for example: C:\temp\te.mp\test.doc, in this case there will be three lines (because of the SPLIT AT '.')

"what if file name without extension i.e. '.'?"

then there will be an empty line in your interna table (as last line)

0 Kudos
307

what if file name is 'C:\temp\te.mp\test'?

...Naddy

0 Kudos
307

you are right...

than I would suggest to do in two steps:

first SPLIT AT '\'

Than take the last line and if it contains a dot, than SPLIT AT '.'

0 Kudos
307

I'll try your method.

what is the line type 'Internal Table'?

...Naddy

former_member188685
Active Contributor
0 Kudos
308

You can use the Function module PC_SPLIT_COMPLETE_FILENAME

export paramter extension will tell the type of file

Sample Output

Import	COMPLETE_FILENAME	C:\TEST.TXT
Import	CHECK_DOS_FORMAT	
Export	DRIVE	C
Export	EXTENSION	TXT
Export	NAME	TEST
Export	NAME_WITH_EXT	TEST.TXT
Export	PATH	\