AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1419414
Accepted
somebadhat
somebadhat
Asked: 2019-03-31 07:59:24 +0800 CST2019-03-31 07:59:24 +0800 CST 2019-03-31 07:59:24 +0800 CST

Powershell 和正则表达式:Notepad++“保存时备份”文件列表。编辑名称,按上次写入时间排序

  • 772
# Microsoft Windows [Version 10.0.17134.648] 
# powershell 5.1.17134.48
# Calculate time to complete task using Notepad++ "backup on save" feature.  Create a copy and paste table of files sorted by LastWriteTime.    
# Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-1); gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time}| sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
# start it in %userprofile%\Documents\NOTEPAD++ AUTOBACKUP
Set-Location -Path "$env:userprofile\Documents\NOTEPAD++ AUTOBACKUP"
# how old a file? Today? 4 days old?
$time = (Get-Date).AddDays(-1)
# $time = (Get-Date).AddDays(-4)
# do you want to exclude files with -exclude? Do you want to include with -include?
gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time}| sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, Name -HideTableHeaders
# gci * | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
# gci * -include [0-9][0-9][0-9]*, avail* | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders

输出:

5/4/2019 10  :  47  :  27 AM  114036 springhill_falls2bd750_885.jpg
5/4/2019 10  :  45  :  25 AM 1301974 springhill_falls2bd750_885.psp
5/4/2019 10  :  37  :  08 AM   19268 springhill_falls2bd13.html
5/4/2019 10  :  37  :  08 AM   94007 available13.html
5/4/2019 10  :  37  :  08 AM   36729 index.html
5/4/2019 10  :  32  :  16 AM   62801 aj.php

和:

5/4/2019 10  :  47  :  27 AM  114036 springhill_falls2bd750_885.jpg.2019-05-04_104748.bak
5/4/2019 10  :  45  :  25 AM 1301974 springhill_falls2bd750_885.psp.2019-05-04_105221.bak
5/4/2019 10  :  37  :  08 AM   19268 springhill_falls2bd13.html.2019-05-04_105856.bak
5/4/2019 10  :  37  :  08 AM   94007 available13.html.2019-05-04_105657.bak
5/4/2019 10  :  37  :  08 AM   36729 index.html.2019-05-04_105657.bak
5/4/2019 10  :  32  :  16 AM   62801 aj.php.2019-05-04_103229.bak

Microsoft Windows [版本 10.0.17134.648]
powershell 5.1.17134.48

使用 Notepad++ / NPP / Notepad Plus“保存时备份”功能计算完成任务的时间。

创建按 LastWriteTime 排序的文件的复制和粘贴表。

可以用作快捷方式:

powershell -noexit $time = (Get-Date).AddDays(-1); gci * -exclude _*, 1* |
    where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending |
    Format-Table LastWriteTime, length, @{n='foo';e={$_.Name
    -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders

在 NPP 自动备份所在的目录中启动它。我的文件备份到%userprofile%\Documents\NOTEPAD++ AUTOBACKUP

此脚本创建一个格式化的表格输出,其中包含编辑后的文件名、大小、日期和每次写入文件的时间。可以很容易地修改要搜索的文件、如何编辑文件名以及要搜索文件的天数。这是跟踪文件处理时间、任务完成时间、项目时间的便捷方式。

有关正则表达式的信息,请参阅下面的 LotPings 答案。

windows-10 powershell text-editing
  • 2 2 个回答
  • 737 Views

2 个回答

  • Voted
  1. Best Answer
    LotPings
    2019-03-31T08:35:28+08:002019-03-31T08:35:28+08:00

    我将使用具有零长度后视断言的 RegEx来删除html from之后的所有内容$_.Name

    这可以通过计算属性来完成,Select-Object或者也可以在Format-*

    Get-ChildItem -File | 
      Format-Table @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$'}},Name -HideTableHeaders
    

    示例输出:

    available13.html available13.html.2019-03-26_081523.bak
    index.html       index.html.2019-03-26_081538.bak
    
    • 4
  2. phuclv
    2019-03-31T08:40:28+08:002019-03-31T08:40:28+08:00

    Add-Member您可以像这样添加一个新属性

    $time = (Get-Date).AddDays(-4)
    $files = gci * -include index*,avail* | where {$_.LastWriteTime -gt $time}
    foreach ($f in $files) {
        $f | Add-Member noteproperty newName -Value `
                 $f.Name.Substring(0, $f.Name.Length - ".yyyy-mm-dd_iiiiii.bak".Length)
    }
    $files | Format-Table -HideTableHeaders newName,Length,LastWriteTime
    

    请注意,上面的代码片段假定您的名字始终以.yyyy-mm-dd_iiiiii.bak. 如果他们有其他格式,那么您必须在问题中包含该信息,并且您可能需要使用其他字符串方法,如 replace、substring... 来删除不必要的部分

    • 4

相关问题

  • VMware Workstation USB 仲裁服务无法自动启动

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 资源管理器侧面板中的桌面外壳快捷方式

  • 为什么我不能将文件从 Android 发送到 Windows 10?

  • 在多个文件上打开方式?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve