2008 Mar 13 9:39 AM
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
2008 Mar 13 10:18 AM
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 \
2008 Mar 13 9:47 AM
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
2008 Mar 13 9:52 AM
Why we need to put into internal table?
Is string variable not enough?
what if file name without extension i.e. '.'?
...Naddy
2008 Mar 13 9:56 AM
"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)
2008 Mar 13 10:07 AM
2008 Mar 13 10:11 AM
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 '.'
2008 Mar 13 10:19 AM
I'll try your method.
what is the line type 'Internal Table'?
...Naddy
2008 Mar 13 10:18 AM
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 \