找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19829|回复: 5

【已解决】40元求文件搜索移动

  [复制链接]
发表于 2020-9-17 18:13:13 | 显示全部楼层 |阅读模式
本帖最后由 lxh623 于 2020-9-17 20:31 编辑

文件夹成千上万的png,是文字图像。
有个文本Unicode是,内容是:
U_0031DE
U_0031E2
U_0031E3
U_001B0A6
U_004E00
U_004E01
U_004E02
U_004E03
U_004E04
1、想创建子文件夹。
2、文件夹文件名类似于,U_004E00.png。当前文件夹列目录,得到文本a。
3、如果文本a的一行在文本Unicode里面搜索不到,就移动到子文件夹。
或许可以把结果写入文本,最后集中移动。
注意:最好整行搜索,完全一样。

谢谢!
发表于 2020-9-17 18:55:23 | 显示全部楼层
回复 1# lxh623
  1. @echo off
  2. set "NewFolder=子文件夹"
  3. set "FileList=a.txt"
  4. set "FileCheck=Unicode.txt"
  5. if not exist "%NewFolder%" (
  6.     md "%NewFolder%"
  7. )
  8. dir /b *.png > "%FileList%"
  9. (for /f "" %%i in ('dir /b *.png') do (
  10.     echo,%%~ni
  11. ))>"%FileList%.tmp"
  12. for /f "delims=" %%i in ('type "%FileList%.tmp" ^| findstr /v /x /g:"%FileCheck%"') do (
  13.     move "%%i.png" "%NewFolder%"
  14. )
复制代码

评分

参与人数 1技术 +1 收起 理由
lxh623 + 1 乐于助人

查看全部评分

发表于 2020-9-17 19:52:45 | 显示全部楼层
  1. <# :
  2. cls
  3. @echo off
  4. cd /d "%~dp0"
  5. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
  6. pause
  7. exit
  8. #>
  9. $self=get-item -liter $args[0];
  10. $path=$self.Directory.FullName;

  11. $newfolder=".\#NotFound";
  12. $txtfile=".\Unicode.txt";
  13. $ext=@(".png");

  14. $newfolder=$newfolder -replace '^\.',$path;$txtfile=$txtfile -replace '^\.',$path;
  15. if(-not (test-path -liter $txtfile)){Write-host ('"'+$txtfile+'" not found');exit;};
  16. if(-not (test-path -liter $newfolder)){[void](md $newfolder)};
  17. $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';
  18. $text=[IO.File]::ReadAllLines($txtfile,[Text.Encoding]::Default);
  19. for($i=0;$i -lt $text.count;$i++){
  20.     $line=$text[$i].trim();
  21.     if(-not $dic.ContainsKey($line)){$dic.add($line,'')};
  22. };
  23. $files=@(dir -liter $path|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
  24. for($i=0;$i -lt $files.length;$i++){
  25.     $base=$files[$i].BaseName;
  26.     if(-not $dic.ContainsKey($base)){
  27.         write-host $files[$i].Name;
  28.         move-item -liter $files[$i].FullName ($newfolder+'\'+$files[$i].Name);
  29.     };
  30. }
复制代码

评分

参与人数 1技术 +1 收起 理由
lxh623 + 1 乐于助人

查看全部评分

 楼主| 发表于 2020-9-17 20:18:10 | 显示全部楼层
回复 2# Batcher
要是这个删除,就更完美了。
谢谢!
a.txt.tmp
发表于 2020-9-17 20:19:51 | 显示全部楼层
回复 4# lxh623


    请自行在最后加一行 del 命令吧
 楼主| 发表于 2020-9-17 20:32:08 | 显示全部楼层
回复 5# Batcher
赞助了论坛。
谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 04:13 , Processed in 0.018050 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表