# Code to return drive

**URL:** <https://resource.dopus.com/t/code-to-return-drive/38572>\
**Category:** Help & Support\
**Created:** [May 20, 2021, 6:04am UTC](https://resource.dopus.com/t/code-to-return-drive/38572 "2021-05-20T06:04:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [May 20, 2021, 6:04am UTC](https://resource.dopus.com/t/code-to-return-drive/38572/1 "2021-05-20T06:04:56Z")

</div>

Is there a code to return the drive (`C:`) of a given path?

I expected `{sourcepath|\|noterm}` to work, but the backslash doesn't get removed.

Background: Some DOS commands require the pure drive, e.g.

```
subst {sourcepath|\|noterm} /D
pause

```

will complain about the `\`.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 20, 2021, 8:09am UTC](https://resource.dopus.com/t/code-to-return-drive/38572/2 "2021-05-20T08:09:50Z")

</div>

Noterm keeps the backslash for drive roots as a special case, as a lot of things are confused without it.

You'll probably need to use scripting for this currently, but we should be able to add a "notermroot" or similar to make things easier in the future.

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [May 20, 2021, 8:36am UTC](https://resource.dopus.com/t/code-to-return-drive/38572/3 "2021-05-20T08:36:53Z")

</div>

Alright, that'd be nice. How about `drive`?

And wouldn't `drivelabel` be useful, too?

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 20, 2021, 9:16am UTC](https://resource.dopus.com/t/code-to-return-drive/38572/4 "2021-05-20T09:16:31Z")

</div>

> [@lxp](#):
>
> How about `drive`?

I think something that works like the existing `noterm` would be best, since then you can use it in more places. e.g. `{sourcepath|..|notermroot}` would give you the parent path without a slash on the end, whether you're in C:\x\y\z or C:\x. When you want the drive letter you can still combine `\` and `notermroot`, but you'll also be able to do other things which wouldn't be possible with a code that always returns only the drive letter.

(I'm not sure if `notermroot` is the best name for it, but I can't think of a better name at the moment.)

> [@lxp](#):
>
> And wouldn't `drivelabel` be useful, too?

Are there places that's needed in commands? I can't think of many, since the labels are almost always display-only and not fed in to many commands. Might be useful in the destination path when copying things to a backup drive, I guess?

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [May 20, 2021, 9:30am UTC](https://resource.dopus.com/t/code-to-return-drive/38572/5 "2021-05-20T09:30:08Z")

</div>

Yes, copying and renaming was what I had in mind.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [May 24, 2021, 2:55pm UTC](https://resource.dopus.com/t/code-to-return-drive/38572/6 "2021-05-24T14:55:27Z")

</div>

We've added `notermdrive`, `driveletter` and `drivelabel` for the next update.

Note that these only currently work in commands, not within the Rename dialog (since things like "noterm" don't work and aren't generally needed in Rename). We could add Rename codes for drive letters and labels if needed.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [July 9, 2021, 2:15pm UTC](https://resource.dopus.com/t/code-to-return-drive/38572/7 "2021-07-09T14:15:01Z")

</div>

That change is in the beta released today: [Directory Opus 12.24.1 (Beta)](https://resource.dopus.com/t/directory-opus-12-24-1-beta/38885)
