> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to load rake task from a custom file or directory
- URL: https://til.codes/load-rake-files-and-run-tasks-from-other-files/
- Published: 2016-07-11T12:50:00.000Z
- Updated: 2016-07-12T12:58:12.000Z
- Author: Manu Ajith
- Tags: ruby, til, rake, #Import 2024-07-13 21:01

If you are wondering how you can load a rake task from a custom file, then this is guide will help you to accomplish your task.

Lets assume you have a rake task named `hello.rake` under your project directory's lib folder like:

```
<project>/lib/tasks/hello.rake

```

Then you can create a simple `Makefile` in your  directory to load it like this: 

```
Dir.glob('lib/tasks/*.rake').each { |r| load r}

```

Of course, this will load all files ending with the rake extension. You can simply load `hello.rake` like this:

```
load './lib/tasks/hello.rake'

```

To see all the tasks that have been loaded use

```
rake -T

```

Note that we've used lib/tasks since that's the standard approach taken by Rails applications. You could use assets or whatever you prefer, though I prefer lib/tasks even in non-Rails projects.

Alternatively, you can either put your tasks into `rakelib/` folder which rake loads by default or add a specific folder in your Rakefile via:

```
Rake.add_rakelib 'lib/tasks'

```