---
title: "getUrlFilename"
description: "从 URL 中提取文件名（不含路径和查询参数），适用于文件下载和资源管理场景。"
seo_title: "getUrlFilename"
seo_description: "Extract the filename from a URL pathname, optionally including the extension, so downloads and asset labels are simple to derive."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/url/get-url-filename"
---
# getUrlFilename

> 从 URL 中提取文件名（不含路径和查询参数），适用于文件下载和资源管理场景。

## 用法

`getUrlFilename` 函数用于获取 URL 的文件名。

```ts
import { getUrlFilename } from '@movk/core'

getUrlFilename('https://example.com/path/file.pdf') // 'file.pdf'
getUrlFilename('https://example.com/path/file.pdf', false) // 'file'
getUrlFilename('https://example.com/path/') // ''
```

## API

### `getUrlFilename(url, includeExtension?)`

获取 URL 的文件名。

### 参数

**url** (`string`) *required*: URL 字符串。

**includeExtension** (`boolean`): 是否包含扩展名,默认 true。

### 返回值

**返回值** (`string`): 文件名。

## Changelog

See commit history for [src/utilities/url/parse.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/url/parse.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
