将文件从子文件夹批量移动到父文件夹 [英] batch moving file from subfolder to parent folder

查看:1374
本文介绍了将文件从子文件夹批量移动到父文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况.

这是我的文件夹结构

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

这篇关于将文件从子文件夹批量移动到父文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆