ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
Re: validation for file
by Robert Klemme other posts by this author
May 10 2008 1:25AM messages near this date
Re: validation for file | how to do this regex substitution?
On 09.05.2008 08:38, 7stud -- wrote:
>  Sunny Bogawat wrote:
> > i am developing one application in which user uploaded one csv template
> > to my system(file). but we have to take care that user should uploaded
> > .csv file only if he trying to upload another file we have to restrict
> > it.
> > how to check for extention in ruby on rails 
>  
>  In the Ruby programming language, which is what this forum is about, you 
>  could do something like this:
>  
>  fnames = ["somefile.csv", "anotherfile.jpg"]
>  
>  fnames.each do |fname|
>    pieces = fname.split(".")
>  
>    if pieces[-1] != "csv"
>      print "bad file: ", fname
>      puts
>    end
>  
>  end

This is a rather weak check as it only tests the file name.  Note, that 
you can do this more easily:

ok = /\.csv$/i =~ file_name

Kind regards
	
	robert
Thread:
Sunny Bogawat
7stud --
Robert Klemme

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved