Application Development and Automation 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: 
Read only

File type from file name

Former Member
0 Likes
2,265

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
Read only

Former Member
0 Likes
1,877

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	\

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

7 REPLIES 7
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,877

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

Read only

0 Likes
1,877

Why we need to put into internal table?

Is string variable not enough?

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

...Naddy

Read only

0 Likes
1,877

"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)

Read only

0 Likes
1,877

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

...Naddy

Read only

0 Likes
1,877

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 '.'

Read only

0 Likes
1,877

I'll try your method.

what is the line type 'Internal Table'?

...Naddy

Read only

Former Member
0 Likes
1,878

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	\