Question about Get Folder Contents

files-and-folders
get-folder-content

#1

Hi
when I use the Get Folder Contents action I get the same result, no matter if I select contents to list “files” or “files and folders”.

In both options I get a list like this:
C:\Users\dell\file1.pdf
C:\Users\dell\file2.pdf
C:\Users\dell\file3.pdf

But I would like to get only the file names
file1.pdf
file2.pdf
file3.pdf

Is that possible and how?
If not, does anyone have an idea how to extract only the file name from the complete filepath?

Thanks!
Tim


#2

A couple different options:

  1. Move it to a variable and use the “substring between” command to find the filename… Since you know the “directory” you can extract after C:\Users\dell\
  2. Move it to a variable and use the “substring” command to find the filename after … Since you know the “directory” you can extract after 14 characters
  3. Move it to a variable and use the “substring between” command to find the filename… If you know the partial “directory” you can extract after dell\

JD


#3

Thanks @jdoering
I used the option of putting the filepath into a variable and then use the replace action on the path+filename:
Replace in element, search for variable “filepath” and replace with “empty”. What is left over it the filename.

Anyway, I am still curious why the standard action “get folder content” doesn’t seem to work as it is supposed to.


#4

@timriewe The action returns full paths in all case. If you have any other folders inside this folder and use options “Files and Folders”, the sub-folders are written in the variable, too. And if you use Files options, only paths to files are written to the variable.
Since you don’t have any folders inside dell\ folder, the results are the same in both cases.


#5

Ok, thanks @ashapkina!


#6

I found another way to extract only the filemane from a filepath of which I dont know the lenght.

My problem was that the filepath is variable within a list of elements.
So it could be any of these:
C:\Users\dell\folder1\folder2\folder3\file.pdf
C:\Users\dell\folder1\folder2\file.pdf
C:\Users\dell\folder1\folder2\folder…\file.pdf

and I need to extract only the filename “file.pdf”. I did it using the action “split string”.
Split string of the element that contains the complete filepath including filename and store it in a list variable.
Then loop at that list variable storing the list element value in a “filename” variable.
The last item in the list variable (when the loop has finished) is the filename :slight_smile:


#7

@timriewe Tim, I just tried it - works great :+1::grinning: Thank you!


#8

hi can you please post code here.