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

有偿20.把文件夹内文件路径提取到表格。求大神帮个忙 非常感谢

  [复制链接]
发表于 2022-4-9 22:39:57 | 显示全部楼层 |阅读模式
一个文件夹内有许多产品文件夹,把产品文件夹内的图片(有多张)路径提取到表格,横着排走。求大神帮帮忙. 一个产品一行
发表于 2022-4-9 23:00:49 | 显示全部楼层
test.bat
  1. @echo off & cd /d "%~dp0"
  2. setlocal enabledelayedexpansion
  3. (
  4.         for /d %%i in (*) do (
  5.                 pushd "%%i"
  6.                 set "a=0"
  7.                 for /f "delims=" %%a in ('dir /s /b *.png *.jpg 2^>nul') do (set /p="%%a,"<nul & set "a=1")
  8.                 if "!a!"=="1" echo.
  9.                 popd
  10.         )
  11. ) > "list.csv"
  12. echo list.csv
  13. pause&exit
复制代码
 楼主| 发表于 2022-4-9 23:26:08 | 显示全部楼层
回复 2# went


    有效果,但是只提取了20个文件夹,然后每个文件夹图片也没提取全
发表于 2022-4-9 23:39:38 | 显示全部楼层
本帖最后由 zaqmlp 于 2022-4-9 23:51 编辑
  1. <# :
  2. cls&echo off&cd /d "%~dp0"
  3. powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText("%~f0",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
  4. pause
  5. exit
  6. #>
  7. $outfile=".\all.csv";

  8. $codes=@'
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Runtime.InteropServices;
  12. public static class ExpDir
  13. {
  14.     [DllImport("Shlwapi.dll", CharSet=CharSet.Unicode)]
  15.     public static extern int StrCmpLogicalW(string p1, string p2);
  16.     public static string[] Sort(string[] f)
  17.     {
  18.         Array.Sort(f, StrCmpLogicalW);
  19.         return f;
  20.     }  
  21. }
  22. '@;
  23. Add-Type -TypeDefinition $codes;

  24. [System.Collections.ArrayList]$s=@();
  25. $folders=@(dir -literal "."|?{$_ -is [System.IO.DirectoryInfo]});
  26. for($i=0;$i -lt $folders.length;$i++){
  27.     write-host $folders[$i].Name;
  28.     $files=@(dir -literal $folders[$i].FullName|?{$_ -is [System.IO.FileInfo]}|%{$_.Name});
  29.     if($files.length -ge 1){
  30.         $arr=[ExpDir]::Sort($files);
  31.         $line=@($arr|%{'"'+$folders[$i].FullName+'\'+$_+'"'}) -join "`t";
  32.         [void]$s.add($line);
  33.     }
  34. }
  35. [IO.File]::WriteAllLines($outfile, $s, [Text.Encoding]::Unicode);
复制代码
发表于 2022-4-9 23:41:35 | 显示全部楼层
回复 3# xiaohutok1


    如果文件夹里没有jpg和png文件就不会提取,你可以自己添加其它格式
 楼主| 发表于 2022-4-9 23:46:50 | 显示全部楼层
回复 4# zaqmlp


    你好 提取出来排序乱了,能不能按照名称排序走。主图跑到后面去了
发表于 2022-4-9 23:52:10 | 显示全部楼层
回复 6# xiaohutok1


    已修改
 楼主| 发表于 2022-4-10 00:12:48 | 显示全部楼层
回复 7# zaqmlp


    查收
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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