sver
sver

Reputation: 942

Extract file name from a particular folder and use it to get some other information

I have a libs folder, there I have few jar files. There names are like this - componentName + version.jar. There is in all 4 files in libs folder. Now I need the component names from these files and I want to use it for some other purpose. How can I get that in gradle. My jar files in libs folder are : bo-1.0.0.jar, so-2.2.1.jar, do-1.0.1.jar and fz-1.0.1.jar I want to get bo,so,do,fz in variables component_bo,component_so,component_do,component_fz.

Upvotes: 0

Views: 51

Answers (1)

Mark Vieira
Mark Vieira

Reputation: 13466

You can just list the contents of that folder and do some simple string manipulation. Here's an example of a pretty naive implementation but I think you can get the idea.

def components = fileTree('libs').collect { it.name.split('-')[0] }
components.each { component ->
    // do something
}

Upvotes: 0

Related Questions