首页 \ 问答 \ 按类型组织文件(Organizing files by type)

按类型组织文件(Organizing files by type)

我有这个脚本,它定期运行以收集桌面文件,并通过文件类型将它们组织到备份驱动器上的单个文件夹中。

function get-destbytype($ext) 
{
    switch ($ext)
    {
        { $ext -match '(jpg|png|gif|bmp)'} { "images" }
        { $ext -match '(divx|mpeg|avi)'} { "videos" }
        { $ext -match '(cs|js|java|py|class|vbs|jsp)'} { "code" }
        { $ext -match '(sql|ps1|pl|py)'} { "scripts" }
        { $ext -match '(zip|7z|rar)'} { "compressed" }
        { $ext -match '(ppt|pptx|doc|docx|pdf)'} { "documents" }
        { $ext -match '(csv|xls|xlsx)'} { "spreadsheets" }
        { $ext -match '(exe|dll|jar|ear|bat|cmd)'} { "executables" }
        { $ext -match '(txt|log)'} { "text" }
        { $ext -match '(msg|htm|html|lnk)'} { "miscellaneous" }
        { $ext -match '(properties|xml|ini)'} { "config" }
        default {"$ext" }
    }
}

$dirtyfolder = "C:\Documents and Settings\user\Desktop\"
$org = "$nas\Desktop\ORG"

ls $dirtyfolder/* | ? {!$_.PSIsContainer} | %{
  $dest = "$($org)\$(get-destbytype $_.extension)"
  if (! (Test-Path -path $dest ) ) 
  {
    write-host "creating $dest"
    new-item $dest -type directory
  }
  mv -path $_ -destination $dest 
}

剧本经过了彻底的测试,在我能想象到的大多数情况下似乎运行良好。 最近当第一次遇到.csv文件时,它们被移动到名称的新文件夹中

code spreadsheets

这显然是因为.cs文件应该转到code文件夹,并将.csv文件转到spreadsheets文件夹,并且该脚本不区分.cs.csv

我如何修改脚本不做这件事?

也可以做什么来排除扩展名为.lnk桌面快捷方式?


I have this script which runs periodically to collect desktop files and organizes them by the file type into a single folder on backup drive.

function get-destbytype($ext) 
{
    switch ($ext)
    {
        { $ext -match '(jpg|png|gif|bmp)'} { "images" }
        { $ext -match '(divx|mpeg|avi)'} { "videos" }
        { $ext -match '(cs|js|java|py|class|vbs|jsp)'} { "code" }
        { $ext -match '(sql|ps1|pl|py)'} { "scripts" }
        { $ext -match '(zip|7z|rar)'} { "compressed" }
        { $ext -match '(ppt|pptx|doc|docx|pdf)'} { "documents" }
        { $ext -match '(csv|xls|xlsx)'} { "spreadsheets" }
        { $ext -match '(exe|dll|jar|ear|bat|cmd)'} { "executables" }
        { $ext -match '(txt|log)'} { "text" }
        { $ext -match '(msg|htm|html|lnk)'} { "miscellaneous" }
        { $ext -match '(properties|xml|ini)'} { "config" }
        default {"$ext" }
    }
}

$dirtyfolder = "C:\Documents and Settings\user\Desktop\"
$org = "$nas\Desktop\ORG"

ls $dirtyfolder/* | ? {!$_.PSIsContainer} | %{
  $dest = "$($org)\$(get-destbytype $_.extension)"
  if (! (Test-Path -path $dest ) ) 
  {
    write-host "creating $dest"
    new-item $dest -type directory
  }
  mv -path $_ -destination $dest 
}

The script was tested thoroughly and seems to run fine in most cases I could imagine. Recently when .csv files were encountered for the first time, they were moved into a new folder by the name

code spreadsheets.

This is obviously because the .cs files are supposed to go to the code folder and the .csv files to the spreadsheets folder, and the script does not distinguish between .cs and .csv.

How do I modify the script to not do this?

Also what can be done to exclude desktop shortcuts with extension .lnk?


原文:https://stackoverflow.com/questions/6477612
更新时间:2022-01-23 17:01

最满意答案

你可以使用OnSelectItem这样做。

  • 记住最后选择的项目。
  • OnSelectItem触发时,检查当前所选项目是否与您记住的项目不同。
  • 如果是,请执行您的任务,并记下新选择的项目。

You can do it like this using OnSelectItem.

  • Remember the last selected item.
  • When the OnSelectItem fires, check if the current selected item differs from the one you remembered.
  • If so, perform your task, and make a note of the new selected item.

相关问答

更多
  • Xamarin.Forms中有触发器。 这似乎是一个事件触发器将做你所需要的。 例如: public class NumericValidationTriggerAction : TriggerAction { protected override void Invoke (Entry entr ...
  • 你可以使用OnSelectItem这样做。 记住最后选择的项目。 当OnSelectItem触发时,检查当前所选项目是否与您记住的项目不同。 如果是,请执行您的任务,并记下新选择的项目。 You can do it like this using OnSelectItem. Remember the last selected item. When the OnSelectItem fires, check if the current selected item differs from the one ...
  • 如果我理解得当,我认为你正在做的是创建一个看起来与tab 2相同但不是同一个对象的新活动。 因此,您在startActivity()中启动的活动是唯一获取数据的活动。 我建议使用带有片段和接口的ViewPager来传递/更新父活动中的数据。 这可能有点过于先进,并不是你可以轻易写出来的答案,但是有很多关于这个过程的教程。 当你刚刚开始时,你可能想要探索更快的选择,但这就是我要做的。 快速修复可能是访问选项卡主机并将现有选项卡2活动替换为您刚刚创建的具有数据的活动。 If I understand prope ...
  • 将您的task ID存储在项目的Tag属性中: row.Tag = task.id; 然后处理ListView.SelectedIndexChanged事件 private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { var id = (int) listView1.SelectedItems[0].Tag ...
  • 上面的方法名称拼写错误,您可以通过添加@Override注释在应用中验证。 你在使用自定义视图吗? Your method name above is misspelled, which you can verify in your app by adding the @Override annotation. Are you using custom views?
  • 这是你通常不应该解决的问题。 用户故意点击某处,这可能是因为她想要取消选择一个项目。 如果它是无意的,那么她就会明白发生了什么,并知道如何纠正它。 为标准控件提供非标准行为往往只会使用户感到困惑。 但你可以解决它。 您需要阻止本机ListView控件看到单击。 这需要重写WndProc()方法并检查点击发生的位置。 在项目中添加一个新类并粘贴下面显示的代码。 编译。 将新控件从工具箱顶部拖放到表单上。 using System; using System.Drawing; using System.Wind ...
  • 您可以在ListView使用SelectedItems.Count属性,只要它为0返回,或者如果它大于0则处理事件,所以你需要的只是事件处理程序中的if语句,如 if(yourListView.SelectedItems.Count == 0) return; //Do your thing 要么: if(yourListView.SelectedItems.Count > 0){ //Do your thing } You can use the SelectedItems.Count ...
  • 看起来你只是缺少样式的TargetType 。 根据Kent的原始代码添加ListViewItem的目标类型。
  • Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) 可能是违反直觉的,但你去了。 用于通过键盘或鼠标进行选择,但与ListBox控件不同,在以编程方式设置所选项时不起作用。 Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) May be counter-intuitive, but there you go. Works for sel ...
  • 你能试试这个吗? private void Listview1_SelectionChanged(object sender, SelectionChangedEventArgs e) { TextBlock textBlock = (sender as ListView).SelectedItem as TextBlock; string value = textBlock.Text; // OR string value2 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。