6

I'm using Tasker and have a step of List Files. I grab that result and stuff it into %files. I then go into a For loop reading %files and under items %files(). However, this is giving me the full path to the files such as /storage/emulated/0/Tasker. All I'd really like is the file name. Is there a step I can do before I enter this loop to truncate the variable results?

Goal would be to just get a list of file names and not the full path.

Firelord
  • 25,084
  • 20
  • 124
  • 286
rsaturns
  • 63
  • 1
  • 1
  • 5

2 Answers2

4

You can use a Variable Split action with a splitter of / to get the pieces, then use %VAR(<) to get the filename. If the fact that the full filename is in an array already gives you problems, copy the array element into a non-array variable first.

From your comments, it sounds like you have this code:

List files Dir /storage/Tasker/project/test/ Variable %files match *.wav
For Variable %files Items %files()
  Variable Split Name %files Splitter /
  Popup Text %files(<)
End For

It's probably not a good idea to use %files as both the "Variable" and the "Items" portion of the For loop. Try using %file for the Variable, then replace all references to %files inside the loop with %file.

Please correct me if I've not captured your code correctly.

Trebor Rude
  • 1,064
  • 8
  • 23
1

I just used the replace function but left the replace string blank. I chose to replace the directory path with nothing and that left me with an array of filenames.

Adrian
  • 11
  • 1