# Folder path - regex

**URL:** <https://www.ruby-forum.com/t/folder-path-regex/170659>\
**Category:** Rails\
**Created:** [June 20, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/folder-path-regex/170659 "2009-06-20T12:41:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 20, 2009, 12:41pm UTC](https://www.ruby-forum.com/t/folder-path-regex/170659/1 "2009-06-20T12:41:50Z")

</div>

Hellow everyone…  
i have to validate a my folderpath field…  
could you people suggest any reqular expression to validate a valid  
path…  
that field should not accept input like â€œMy Documentsâ€  
but should accept â€œc:\Backupâ€  
i searched the web and i tried this…  
Regular Expression:  
^((([a-zA-Z]:)(\{2}[a-zA-Z]+)(\{2}\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}))(?=(\(\w[\w  
]_)))(\\w[\w]_)\*)$  
.but was not usefull…  
pls favour for me…  
Thanks for any helps

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 20, 2009, 12:57pm UTC](https://www.ruby-forum.com/t/folder-path-regex/170659/2 "2009-06-20T12:57:25Z")

</div>

On Jun 20, 11:41 am, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hellow everyone…  
> i have to validate a my folderpath field…  
> could you people suggest any reqular expression to validate a valid  
> path…  
> that field should not accept input like “My Documents”  
> but should accept “c:\Backup”

You’re going to have to be a little more precise: what is it that you  
are trying to ensure? No spaces, no special characters, absolute paths  
only, something else ? Also what about platforms where paths are  
delimited in different ways ? What will you be doing with this path ?

Fred

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 20, 2009, 1:02pm UTC](https://www.ruby-forum.com/t/folder-path-regex/170659/3 "2009-06-20T13:02:27Z")

</div>

Frederick C. wrote:

> On Jun 20, 11:41ï¿½am, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hellow everyone…  
> > i have to validate a my folderpath field…  
> > could you people suggest any reqular expression to validate a valid  
> > path…  
> > that field should not accept input like ï¿½My Documentsï¿½  
> > but should accept ï¿½c:\Backupï¿½
> 
> You’re going to have to be a little more precise: what is it that you  
> are trying to ensure? No spaces, no special characters, absolute paths  
> only, something else ? Also what about platforms where paths are  
> delimited in different ways ? What will you be doing with this path ?
> 
> Fred

thanks for the reply  
in that folder path location i m going to save files.  
and i m on windows …

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 20, 2009, 4:22pm UTC](https://www.ruby-forum.com/t/folder-path-regex/170659/4 "2009-06-20T16:22:16Z")

</div>

Newb N. wrote:  
[…]

> in that folder path location i m going to save files.

On the client side? For security reasons, Web applications don’t have  
direct access to the client-side filesystem. You’ll have to give the  
client a download link and let the browser program take care of saving  
it

OTOH, if this is on the server side, you can construct the path in a way  
that you know will be valid.

In either case, there is _no point_ to the validation you’re trying to  
do.

> and i m on windows …

Doesn’t mean your clients will be, so you can’t only accept  
Windows-style paths!

Really, there’s no validation that can do what you want here.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
