Board logo

标题: 【已解决】40元求文件搜索移动 [打印本页]

作者: lxh623    时间: 2020-9-17 18:13     标题: 【已解决】40元求文件搜索移动

本帖最后由 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里面搜索不到,就移动到子文件夹。
或许可以把结果写入文本,最后集中移动。
注意:最好整行搜索,完全一样。

谢谢!
作者: Batcher    时间: 2020-9-17 18:55

回复 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. )
复制代码

作者: zaqmlp    时间: 2020-9-17 19:52

  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. }
复制代码

作者: lxh623    时间: 2020-9-17 20:18

回复 2# Batcher
要是这个删除,就更完美了。
谢谢!
a.txt.tmp
作者: Batcher    时间: 2020-9-17 20:19

回复 4# lxh623


    请自行在最后加一行 del 命令吧
作者: lxh623    时间: 2020-9-17 20:32

回复 5# Batcher
赞助了论坛。
谢谢!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2