Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file path without extension in Rust?

Please help me to find an elegant way to get file path without extension; cut off file extension from path or something.

like image 375
lem0nify Avatar asked Jan 26 '16 05:01

lem0nify


People also ask

How do you get a file name in Rust?

Given an open File object in Rust, you can get the inode number using the ino() method. If you know the directory the log file is in, you can use std::fs::read_dir() to iterate over all entries in that directory, and each entry will also have an ino() method, so you can find the one(s) matching your open file object.

What is the extension of Ruby file?

An RB file is a software program written in Ruby, an object-oriented scripting language. Ruby is designed to be simple, efficient, and easy to read. RB files can be edited with a text editor and run using Ruby. Ruby is available in several different versions, or "gems," including Ruby on Rails, Mongrel, and Capistrano.

What is a go file?

Source code for a program written in Go, a programming language originally developed by Google; contains code written in plain text format that must be compiled before being run as a program. Go is loosely based off of the programming language C, which uses the . C file extension for its source code.


Video Answer


2 Answers

Check the Path::file_stem method. You can find an example there. It works at least from Rust 1.6.

like image 71
Tibor Benke Avatar answered Oct 16 '22 22:10

Tibor Benke


Using the Path::with_extension("") method gives you the full path with a possible file extension removed.

like image 5
V02460 Avatar answered Oct 16 '22 23:10

V02460