【问题标题】:batch, Create specific folders from specific multiple files, and then move specific multiple files into specific folder批处理,从特定的多个文件创建特定的文件夹,然后将特定的多个文件移动到特定的文件夹中
【发布时间】:2013-09-30 11:44:43
【问题描述】:

我有一些文件有问题

07-01.jpg 07-02.jpg 直到 07-48.jpg

08-01.jpg 08-02.jpg 直到 08-48.jpg

....

37-01.jpg 37-02.jpg 37-03.jpg until37-48.jpg

我想创建文件夹 07, 08.... ,37 然后将多个文件 07-01.jpg, 07-02.jpg, 07-03.jpg 移动到文件夹 07 中;

08-01.jpg, 08-02.jpg, 08-03.jpg 放入文件夹 08 ;

......

37-01.jpg、37-02.jpg、37-03.jpg 放入文件夹 37 等

我可以得到任何批处理脚本来解决这个问题吗?

谢谢

【问题讨论】:

  • 到目前为止您尝试过什么?贴一些代码。我们不是来给你脚本的。

标签: windows batch-file command


【解决方案1】:

好的,首先你应该做更多的研究,我个人知道还有其他问题。其次,您还应该展示您目前拥有的脚本,以便我们对其进行改进。试试这个解决方案,如果它不起作用,请给我评论错误消息。

代码:

@echo off
setlocal enabledelayedexpansion
Rem dont include the last backslash below
set topath="C:\users\...[path to parent directory]"
pushd %topath%

for /r %%f in (*.jpg) do (
Rem Remove the below line and the correspoonding bracket to make this include sub directories
if !topath! equ "%%~ff" (
for /f "delims=_" %%n in ("%%~f") do (
if not exist %%n md %%n
move %%f %%n
)))

这应该可以正常工作,如果不行,我可以根据您提供的数据使用for /l 循环手动编写另一个代码。

手动脚本

这是一个具体的解决方案:

@echo off
pushd D:\case

for /l %%a in (1,1,9) do (
md 0%%a
for /l %%b in (1,1,9) do (
if exist 0%%a_0%%b.jpg (
move 0%%a_0%%b.jpg 0%%a
)))

for /l %%a in (10,1,37) do (
md %%a
for /l %%b in (10,1,48) do (
if exist %%a_%%b.jpg (
move %%a_%%b.jpg %%a
)))
popd

必须工作。如果两者都不起作用,请在命令提示符下运行它,以便您可以给我一条错误消息以供使用。 莫娜

【讨论】:

  • 它不起作用,实际上我的文件名使用“_”而不是“-”,所以它是 07_01.jpg 等谢谢你的帮助
  • 对不起,如果我当前的文件在 D:\case 中,我必须将 C:\users\...[path to parent directory] ​​更改为 D:\case 吗?
  • @user257182 检查我的编辑,我已经建立了一个特定的解决方案。
猜你喜欢
  • 2017-11-14
  • 1970-01-01
  • 2023-01-10
  • 1970-01-01
  • 2014-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多