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: 

Find the full directory path of a folder on my machine

Former Member
0 Kudos

I have a folder say 'xyz' on my machine, using just that i want to find out the exact path of this folder on my machine, like say 'c:\abc\xyz'. How can I achieve this. Is there a function module for this or some code that I will have to write ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I am pretty sure you are not able to search your entire host for a random folder name. If the folder name is not random then I assume that the location of the folder is known. In which case you could use logical file names (Transaction FILE).

If you truly do not know the absolute path of your folder then you are looking at having to search the file system of your host - this could take quite sometime and also if the host is Windows Vista or greater then you might well hit issues with UAC as some directories are protected.

Where does the requirement to find the absolute path of an unknown folder name come from? We may be able to find another way for you to achieve your goal.

21 REPLIES 21

Former Member
0 Kudos

This message was moderated.

former_member195402
Active Contributor
0 Kudos

Hi,

please have a look at class CL_GUI_FRONTEND_SERVICES.

For example you can use methods FILE_OPEN_DIALOG or FILE_SAVE_DIALOG or one of the DIRECTORY...-methods.

Regards,

Klaus

Former Member
0 Kudos

Hey Giri and Klaus,

I have tried most of these  function modules but none of them accept a pattern for a directory name like '%xyz%' and return the full path if the directory is found. I don't know whether the folder is on c:, or d: or some other drive.

0 Kudos

Hi,

I don#t think you will find a fm or method which is searching a frontend path for you. Normally you have to know, where the path is.

But I think you may be able to use the methods of class CL_GUI_FRONTEND_SERVICES to code a search yourself. Start with the root directory (C:\), get content list with method DIRECTORY_LIST_FILES and option DIRECTORIES_ONLY, search all directories recursively, and if the path is not found start with root directory D:\ and so on.

regards,

Klaus

0 Kudos

And what should happen if more directories follow your pattern ?

I don't think it is possible with a standard function module or method and agree with Klaus that you will need to program this yourself from scratch.

former_member201275
Active Contributor
0 Kudos

Like so:

DATA: IT_FILES TYPE FILETABLE,

      WA_FILES LIKE LINE OF IT_FILES,

      LV_RC TYPE I.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PCPATH.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG.

EXPORTING

  WINDOW_TITLE = 'Select Files'

  •   DEFAULT_EXTENSION = '*.txt'
  •   DEFAULT_FILENAME =
  •   FILE_FILTER =
  •   WITH_ENCODING =
  •   INITIAL_DIRECTORY =

  MULTISELECTION = 'X'

CHANGING

  FILE_TABLE = IT_FILES

  RC = LV_RC

<i>  IT_FILES will contain list of files selected or

  name of file selected if

    MULTISELECTION = ' '</i>

Hope this helps you.

Regards,

Glen.

Former Member
0 Kudos

Hi Mrunal,

Kindly use the following fms if they are working:

FILE_GET_NAME_AND_LOGICAL_PATH,

FILE_GET_NAME_USING_PATH,

FILE_GET_NAME

I guess the first one should work since in this you can assign physical filename and get logical file path.

Hope it helps!!!!

Thanks And Regards,

Alora

former_member220538
Active Participant
0 Kudos

Hi,

Use the method in the class cl_gui_frontend_services.

v_sel_path contain selected folder path.

DATA: v_sel_path    TYPE string.

CALL METHOD cl_gui_frontend_services=>directory_browse
CHANGING
  selected_folder = v_sel_path
EXCEPTIONS
  cntl_error      = 1
  error_no_gui    = 2
  OTHERS          = 3 .

Regards,

Jeffin

0 Kudos

Hi Jeffin,

Can I pass 'xyz' to v_sel_path ?

0 Kudos

Hi,

When executing , a popup window will appear and you can choose the folder. Output parameter  v_sel_path will contain the path of the folder .

0 Kudos

Jeffin,

Thanks but thats not what I want.

Former Member
0 Kudos

Hi Mrunal,

Have a look on the function module 'TMP_GUI_GET_SYSTEMDIR', also go through all the function modules under the function group 'SI72'.

Execute the function module 'TMP_GUI_GET_SYSTEMDIR' it gives the path of the system directory something like C:\Windows\system32

CALL METHOD OF H_COM1 'GetSystemDirectory'        = SYSTEMDIR.

In this function module a call is made to the windows function GetSystemDirectory to get the system directory information. Make a search for windows function which are available suitable in your case. If you find such windows function then just copy the function module and replace the windows function. But not sure if there is a readily available windows function that suits your requirement.

Hope this helps.

Thanks,

Tooshar Bendale

Former Member
0 Kudos

I am pretty sure you are not able to search your entire host for a random folder name. If the folder name is not random then I assume that the location of the folder is known. In which case you could use logical file names (Transaction FILE).

If you truly do not know the absolute path of your folder then you are looking at having to search the file system of your host - this could take quite sometime and also if the host is Windows Vista or greater then you might well hit issues with UAC as some directories are protected.

Where does the requirement to find the absolute path of an unknown folder name come from? We may be able to find another way for you to achieve your goal.

0 Kudos

The actual requirement came from the problem where in our organisation admin rights for all users were removed, due to which programs that downloaded DMS documents to the machine started giving errors, that, file could not be created as write access was removed.

The actual requirement now is to download documents to a users "TEMP" folder on a windows/linux machine which would have write access. The download happens through the FM for DMS : CVAPI_DOC_VIEW. 

Now to locate this folder(TEMP) on the users machine and then pass this path to the fm CVAPI_DOC_VIEW to download the document, is the tough part, whose solution I was looking for through this question. I shall try with the method Klaus suggested.

Regards,

Mrunal.

0 Kudos

Hi,

here is a sample fm for getting all folders of a drive in Windows 7. But it isn't very fast, it lasted several minutes for searching 35000 folders on drive C:\ and some seconds for searching 189 folders on drive D:\ .

Regards,

Klaus

0 Kudos

Mighty Thanks Klaus!

0 Kudos

Can you not simply download the file to the SAP AS and then allow the user to open the file from there? You could use a FM to open the file, something like:

CALL FUNCTION 'GUI_EXEC'

  EXPORTING

    command          = 'C:\WINWORD.EXE'

    PARAMETER        = P_DATA

IMPORTING

   RETURNCODE       = RETURNCODE .

I know there is a method to call IE as well and pass it a URL. The URL in this case could be your directory path to your file on the SAP AS. IE would then open the file. This might be a better solution then spending a lot of time searching all directories of a local machine? ....

0 Kudos

Adam,

If I were to download the file to SAP AS, please keep in mind there are some 300 odd users we have and each of them opens at least a 20-30 files with respective data. Imagine saving so many files on the AS. Saving it to the users desktop is definitely the way out. Thanks anyway.

raymond_giuseppi
Active Contributor
0 Kudos

Why not create an enviropnment variable on user desktop with the path (like the usual TEMP or TMP) you could then read this variable with method ENVIRONMENT_GET_VARIABLE of CL_GUI_FRONTEND_SERVICES.

Regards,

Raymond

0 Kudos

Raymond,

Like I said to Adam, the number of users we have is large, thanks anyway.

0 Kudos

Its a bummer - I was hoping that the users would not have to wait minutes for directory discovery. Users always like things instantly. Hope all works!