Question: My code is working so wrong! After entering and sorting some numbers of list, for some numbers it doesn't work and deletes older node or doesn't show them. Couldn't get what's wrong. 

Sometimes it looks like it is working fine, for example : I entered 4, 6, 7, 2 and it showed truly in the sorted list. but after entering 3 it didn't show 3 in the list.

Here is my code:

```
if(head == NULL)     
{
    head = info;    
    last = info;
    info->next = NULL;   
}
else  
{
    if(info->number > last->number)  
    {
        last->next = info;  
        last = info;            
        info->next = NULL;  
    }
    else if (info->number < head->number ) 
    {          
        info -> next = head;       
        head = info;            
    }

    prev = head;

    for(temp = head-> next ; temp!= NULL; temp = temp->next) 
    {
        prev = prev->next;
        if(info->number >temp->number)
        {
            temp->next = info;                          
        }
        else
        {
            temp-> prev = info;
            info = prev;
        }
    }
}   

```

Answer: 
Write a simple `RemoveContents` function. For example,

```
package main

import (
    "fmt"
    "os"
    "path/filepath"
    "strings"
)

func RemoveContents(dir string) error {
    d, err := os.Open(dir)
    if err != nil {
        return err
    }
    defer d.Close()
    names, err := d.Readdirnames(-1)
    if err != nil {
        return err
    }
    for _, name := range names {
        err = os.RemoveAll(filepath.Join(dir, name))
        if err != nil {
            return err
        }
    }
    return nil
}

func main() {
    dir := strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0]))
    dir = filepath.Join(os.TempDir(), dir)
    dirs := filepath.Join(dir, `tmpdir`)
    err := os.MkdirAll(dirs, 0777)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    file := filepath.Join(dir, `tmpfile`)
    f, err := os.Create(file)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    f.Close()
    file = filepath.Join(dirs, `tmpfile`)
    f, err = os.Create(file)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    f.Close()

    err = RemoveContents(dir)
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

```
You could use `filepath.Glob()` to get a slice of the contents of the folder, then delete everything it returns. This allows you to use `/tmp/*` to indicate what you want to delete, and could also be used to delete `/tmp/*.go`, or `/tmp/*/*.go`, etc.

```
package main

import (
    "log"
    "os"
    "path/filepath"
)

func RemoveGlob(path string) (err error) {
    contents, err := filepath.Glob(path)
    if err != nil {
        return
    }
    for _, item := range contents {
        err = os.RemoveAll(item)
        if err != nil {
            return
        }
    }
    return
}    

func main() {
    err := RemoveGlob("/tmp/*")
    if err != nil {
        log.Fatalf("Error removing files: %+v", err)
    }
}

```