将文件从子文件夹批量移动到父文件夹

编程入门 行业动态 更新时间:2024-10-22 09:31:37
本文介绍了将文件从子文件夹批量移动到父文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的情况.

这是我的文件夹结构

C:\DOCS\Project1\docname1\image.jpg \docname2\image.jpg \docname3\image.jpg C:\DOCS\Project2\docname1\image.jpg \docname2\image.jpg \docname3\image.jpg

我正在尝试从.DOCS文件夹中运行一个.bat文件,并将所有image.jpgs上一个文件夹从"docname"文件夹移至" Project文件夹.

I'm trying to get a .bat going that will run from the "DOCS" folder, and move all the image.jpgs up one folder from the "docname" folders to the ""Project" folder.

文档名称和项目名称都不同,并且遵循特定的命名方案,因此我不能仅使用源目录和目标目录.

The docname and project names are all different and follow to specific naming scheme so I cant just use a source and dest directory.

必须是可以找到image.jpg并将其上移到父文件夹的东西.

It would have to be something that would just find the image.jpg and move it up a parent folder.

这是香港专业教育学院得到的,但没有用.

this is what ive got but it isnt working.

for /d %f in (docs\*) do ( pushd %f copy .\*.jpg .. popd )

我每个项目文件夹只需要一个.jpgs.因此,更换/重新命名不是问题.

Also I only need one of the .jpgs per project folder. so replacing/renaming isnt an issue.

推荐答案

@echo off setlocal enabledelayedexpansion for /f "tokens=*" %%a in ('dir /A:D /S /B "C:\docs\*"') do ( for %%y in ("%%a\*.jpg") do ( call :GETPARENTPARENT "%%y" ret echo ret=!ret! move /Y "%%y" "!ret!" ) ) goto:EOF :GETPARENTPARENT set fileP=%1 echo received=%fileP% for %%a in (%fileP%) do ( set parent=%%~dpa cd !parent!\.. set PPPath=!cd! for %%x in ("!PPPath!") do ( set "%~2=%%~dpnx" ) ) GOTO:EOF

更多推荐

将文件从子文件夹批量移动到父文件夹

本文发布于:2023-11-09 21:09:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   批量   文件   从子

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!