1、呈现效果

2、后端

1)服务层

/// <summary>
/// 删除指定修改日期段及指定路径下的所有文件
/// </summary>
/// <param name="filepath">指定路径</param>
/// <returns>返回删除结果提示</returns>
public string DeleteSpecifiedPathAllFile(FileInfomationArgs args)
{
if(args.IsNull()))
{
return "参数为空,请重新获取!";
}
try
{
DirectoryInfo info = new DirectoryInfo(args.FilePath);
// 去除文件夹的只读属性
info.Attributes = FileAttributes.Normal & FileAttributes.Directory;
// 去除文件的只读属性
File.SetAttributes(args.FilePath, FileAttributes.Normal);
// 判断文件夹是否存在
if(Directory.Exists(args.FilePath))
{
// 按指定修改时间段删除文件
if(args.StartTime != null && args.EndTime != null)
{
List < FileInfo > fileInfomations = null;
fileInfomations = info.GetFiles().Where(t => t.LastWriteTime >= args.StartTime && t.LastWriteTime <= args.EndTime).ToList();
foreach(var fileInfo in fileInfomations)
{
if(File.Exists(fileInfo.FullName))
{
// 如果有子文件则删除子文件
File.Delete(fileInfo.FullName);
}
else
{
// 循环递归删除子文件夹的所有文件
DeleteSpecifiedPathAllFile(args);
}
}
}
else // 删除指定路径的全部文件
{
foreach(var file in Directory.GetFileSystemEntries(args.FilePath))
{
if(File.Exists(file))
{
// 如果有子文件则删除子文件
File.Delete(file);
}
else
{
// 循环递归删除子文件夹的所有文件
DeleteSpecifiedPathAllFile(args);
}
}
}
// 删除已空文件夹(此步骤会删除指定目录的最底层文件夹,建议保留文件夹目录,此句注释)
// Directory.Delete(filepath, true);
}
return "当前文件修改日期段的指定路径下的所有文件删除成功!";
}
catch(Exception ex)
{
return "删除出现异常,异常原因为:" + ex.Message;
}
}

2)请求参数类

/// <summary>
/// 文件信息参数
/// </summary>
public class FileInfomationArgs
{
private string _FilePath = "";
/// <summary>
/// 指定路径
/// </summary>
public string FilePath
{
get
{
return _FilePath;
}
set
{
_FilePath = value;
}
}
private DateTime ? _StartTime = null;
/// <summary>
/// 指定修改时间开始时间段
/// </summary>
public DateTime ? StartTime
{
get
{
return _StartTime;
}
set
{
_StartTime = value;
}
}
private DateTime ? _EndTime = null;
/// <summary>
/// 指定修改时间结束时间段
/// </summary>
public DateTime ? EndTime
{
get
{
return _EndTime;
}
set
{
_EndTime = value;
}
}
}

3)接口层

/// <summary>
/// 删除指定路径下的所有文件
/// </summary>
/// <param name="filepath">指定路径</param>
/// <returns>返回删除结果提示</returns>
public Result string DeleteSpecifiedPathAllFile(FileInfomationArgs args);

4)控制层

/// <summary>
/// 删除指定路径下的所有文件
/// </summary>
/// <param name="filepath">指定路径</param>
/// <returns>返回删除结果提示</returns>
[HttpPost, HttpOptions]
public IActionResult DeleteSpecifiedPathAllFile(FileInfomationArgs args)
{
return ToJsonContent(_服务层注入.DeleteSpecifiedPathAllFile(args));
}

3、前端

<html>
<head></head>
<body>
<template>
<el-form size="small" :model="form" :rules="rules" ref="form" label-width="120px">
<div class="head_main">
<el-row :gutter="24">
<el-col :span="20">
<div class="key_tip">
【关于文件清理的说明】
<p style="color: red;">本页面功能主要是删除本地指定日期段及指定路径下的所有文件</p>
<p style="color: green;">☞指定路径:本地文件夹的绝对路径</p>
<p style="color: green;">☞指定日期段:本地文件夹下的文件的最新修改日期</p>
</div>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="指定路径:" prop="filePath">
<el-input class="entity" type="textarea" clearable="" placeholder="请输入指定路径" v-model="form.filePath">
</el-input>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="12">
<el-form-item label="指定日期段:" prop="operationTime">
<el-date-picker class="entity" v-model="operationTime" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" clearable="" size="small" style="width:100%">
</el-date-picker>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="15">
<el-col :span="24">
<el-form-item>
<el-button type="primary" des="el" @click="cleanUp">
清理
</el-button>
<el-button des="el" @click="reset">
重置
</el-button>
</el-form-item>
</el-col>
</el-row>
</div>
</el-form>
</template>
<script>
import { 方法名 } from '方法名所在JS文件' export default {
data () {
return {
form: {
filePath: '',
operationTime: '',
},
rules: {
filePath: [
{ required: true, message: '请输入指定路径', trigger: 'blur' },
],
},
}
},
created () {
},
methods: {
// 清理
cleanUp () {
this.$refs.form.validate(async (valid) => {
if (!valid) return
let startTime, endTime
if (this.operationTime) {
startTime = this.operationTime[0]
endTime = this.operationTime[1]
}
try {
await DeleteSpecifiedPathAllFile({
FilePath: this.form.filePath,
StartTime: startTime,
EndTime: endTime,
})
this.$notify({
type: 'success',
offset: 50,
title: '当前文件修改日期段的指定路径下的所有文件删除成功',
})
return
} catch (error) {
console.log('error:', error)
}
})
},
// 重置
reset () {
this.form.filePath = ''
this.operationTime = ''
},
},
}
</script>
<style lang="scss">
.head_main {
.key_tip {
box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
padding: 8px 16px;
background-color: #ecf8ff;
border-radius: 4px;
border-left: 5px solid #50bfff;
margin: 20px 0;
line-height: 22px;
}
}
</style>
</body>
</html>

代码和呈现效果如上所述。

注:指定路径为本地的绝对路径;指定日期段的判定依据是文件的修改日期

.net core + vue + elementui 删除指定日期段、指定路径下的所有文件的更多相关文章

  1. unity3d 依据指定的Assets下的目录路径 返回这个路径下的全部文件名称

    using UnityEngine; using System.Collections; using System.Collections.Generic; using System.IO; < ...

  2. python之实现循环查看指定路径下的所有文件---os.walk

    循环查看指定路径下的所有文件.文件夹,包含隐藏文件注:“.filename” 以点开头的是隐藏文件 import os for cur_path,cur_dirs,cur_files in os.wa ...

  3. Python3在指定路径下递归定位文件中出现的字符串

    [本文出自天外归云的博客园] 脚本功能:在指定的路径下递归搜索,找出指定字符串在文件中出现的位置(行信息). 用到的python特性: 1. PEP 318 -- Decorators for Fun ...

  4. Python小代码_15_遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间

    遍历指定路径下的所有文件和文件夹,并格式化输出文件路径文件名和文件夹名,文件大小,修改时间 import osimport datetime def print_tree(dir_path): for ...

  5. Python复制指定目录的各个子目录下的同名文件到指定文件夹并重命名

    Python复制指定目录的各个子目录下的同名文件到指定文件夹并重命名 #编码类型 #-*- coding: UTF-8 -*- #导入包 import os import shutil srcpath ...

  6. mysql 获取指定日期到指定日期 区间段的日期

    第一种方法: cross join (就相当于mysql中的循环) CROSS JOIN 把两张表中的数据进行 N * M的组合,即笛卡尔积 这里的两张表利用 union all都有5条数据,所以进行 ...

  7. python删除执行路径下的空文件夹

    def rm_emp_dir(path): """ 删除指定路径下的空文件夹 :param path: 指定路径 :type path: str :return: Non ...

  8. 算法积累:解决如何获取指定文件夹路径或者文件路径下所有子文件后缀为.h .m .c的文本的行数

    1.先解决如何获取一个文件的代码行数 一开始对于这个问题,我的思路就回荡在:1字符串子字符串的判断 2循环直到结束的想法 3将原来是"\n"替换掉之类的想法 一个问题总会有多种解决 ...

  9. vue@cli3 项目模板怎么使用public目录下的静态文件,找了好久都不对,郁闷!

    作为图片最好放在static目录下,但是vue@cli3没有static,网上都说放在public目录下,行,那就放吧,可问题是图片放了怎么使用 第一次尝试 肯定用绝对路径这就不说了,用相对路径,we ...

  10. js实现指定日期增加指定月份

    首先,大致思路为: 1. 先将字符串格式的时间类型转化为Date类型 2. 再将Date类型的时间增加指定月份 3. 最后将Date类型的时间在转化为字符串类型 1.  先将字符串格式的时间类型转化为 ...

随机推荐

  1. AArch32/AArch64系统级内存模型(三)

    1. 内存系统架构 1.1 系统级存储系统体系结构的形式   Armv8的a -profile体系结构包括一个虚拟内存系统体系结构(Virtual Memory System Architecture ...

  2. C ++:树

    C++:树 树的概念: 所谓"树"是输就结构的一种,树大概可以分为两大类: 有根树 和 无根树 有根树使有一个确定的根节点,反之为无根树 · 子节点:从树根开始,通过树边向下扩展的 ...

  3. Day21:方法重写以及注意细节

    目录 方法重写 什么是方法重写? 方法重写有什么用? 方法重写的注意细节 方法重写 什么是方法重写? 方法重写指的是当子类和父类出现了一摸一样的方法声明 方法重写有什么用? 当父类中有一个方法时,子类 ...

  4. vue3 watch笔记

    watchEffect 执行传入的一个函数,同时自动追踪函数中依赖到的数据,并在其依赖变更时重新运行该函数. 并且会在 组件挂载前 立即调用一次,(默认是挂载前,可通过修改 flush 属性改变,后边 ...

  5. .NET性能优化-ArrayPool同时复用数组和对象

    前两天在微信后台收到了读者的私信,问了一个这样的问题,由于私信回复有字数和篇幅限制,我在这里统一回复一下.读者的问题是这样的: 大佬您好,之前读了您的文章受益匪浅,我们有一个项目经常占用 7-8GB ...

  6. SpringBoot中搭配AOP实现自定义注解

    1 springBoot的依赖 确定项目中包含可以注解的依赖 <dependency> <groupId>org.springframework.boot</groupI ...

  7. Python:界面开发,wx入门篇

    以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「englyf」https://mp.weixin.qq.com/s/3Yb_YAKiMte_f5HanetXiA 本文大概 3617 个 ...

  8. 从面试题入手,畅谈 Vue 3 性能优化

    前言 今年又是一个非常寒冷的冬天,很多公司都开始人员精简.市场从来不缺前端,但对高级前端的需求还是特别强烈的.一些大厂的面试官为了区分候选人对前端领域能力的深度,经常会在面试过程中考察一些前端框架的源 ...

  9. 基于 Traefik 的 Basic Auth 配置

    前言 Traefik是一个现代的HTTP反向代理和负载均衡器,使部署微服务变得容易. Traefik可以与现有的多种基础设施组件(Docker.Swarm模式.Kubernetes.Marathon. ...

  10. JavaScript:显式转换数据类型:如何转换为数值、字符串和布尔值类型?

    JS的运算符以及某些内置函数,会自动进行数据类型的转换,方便计算,即隐式转换数据类型: 但是很多时候,我们希望可以手动控制数据类型的转换,即显示转换数据类型: 转换为字符串 String()函数 使用 ...