如何将文件夹(包括空文件夹)的内容移动(不复制)到除一个文件夹之外的新文件夹中?
我想将Entity
文件夹中的内容移动到每个实体中新创建的文件夹2013\November Estimates
。
文件夹布局是2013 \ 2 - 11月预测\基金家庭(其中32个,加上其他文件夹无关)\实体(每个基金家族独有的600个不同实体)
这是每个实体的当前布局:
Entity_01
Entity_01\2013
Entity_01\2013\November Estimates
Entity_01\entity.pdf
Entity_01\entity.xls
Entity_01\entity.doc
Entity_01\PY folder
Entity_01\Trash Folder
Entity_01\2012
所以所有文件和文件夹都移动到November Estimates
,但文件夹2012
保持原样(产生以下布局)
Entity_01
Entity_01\2013
Entity_01\2013\November Estimates
Entity_01\2013\November Estimates\entity.pdf
Entity_01\2013\November Estimates\entity.xls
Entity_01\2013\November Estimates\entity.doc
Entity_01\2013\November Estimates\PY folder
Entity_01\2013\November Estimates\Trash Folder
Entity_01\2012
以下命令行的问题:
FOR /f "delims=" %%b IN (entitylist.txt) DO (
pushd "%destdrive%:\%year%\%projections%\%%~a\%%~b\" && (
for /d %%c in (*) do if /i not "%%c"=="2012" move "%%c" "%estimates%"
move *.* "%estimates%"
popd
)
)
完成BAT
@echo off
setlocal
SET "sourcedrive=Z"
SET "destdrive=C"
SET /a year=2013
SET "projections=2 - November Projections"
SET "Estimates=November Estimates"
SET "Yearend=Year End Filings"
DIR /b /ad "%sourcedrive%:\%year%\%projections%" >fundfamily.txt
start /wait "Fund Family" C:\Windows\System32\notepad.exe "fundfamily.txt"
FOR /f "delims=" %%a IN (fundfamily.txt) DO (
MD "%destdrive%:\%year%\%projections%\%%~a"
DIR /b /ad "%sourcedrive%:\%year%\%projections%\%%~a" >entitylist.txt
start /wait "%%~a entities" C:\Windows\System32\notepad.exe "entitylist.txt"
FOR /f "delims=" %%b IN (entitylist.txt) DO MD "%destdrive%:\%year%\%projections%\%%~a\%%~b\%year%\%estimates%"
FOR /f "delims=" %%b IN (entitylist.txt) DO MD "%destdrive%:\%year%\%projections%\%%~a\%%~b\%year%\%yearend%"
FOR /f "delims=" %%b IN (entitylist.txt) DO MD "%destdrive%:\%year%\%projections%\%%~a\%%~b\2012"
FOR /f "delims=" %%b IN (entitylist.txt) DO (
pushd "%destdrive%:\%year%\%projections%\%%~a\%%~b\" && (
for /d %%c in (*) do if /i not "%%c"=="2012" move "%%c" "%estimates%"
move *.* "%estimates%"
popd
)
)
)
答案 0 :(得分:0)
关于产生错误的行,如果只有一个文件夹要避免移动,可以检查要移动的文件夹是否不是:
FOR /f "delims=" %%b IN (entitylist.txt) DO (
if "%destdrive%:\%year%\%projections%\%%~a\%%~b\2012" NEQ "%%b" MOVE /Y "%destdrive%:\%year%\%projections%\%%~a\%%~b\%all%" "%destdrive%:\%year%\%projections%\%%~a\%%~b\%year%\%estimates%"
)
答案 1 :(得分:0)
尝试将此作为最后一个循环,因为您需要一个循环来逐个移动文件夹,另一个命令来移动主文件夹中的文件。
也许这样的事情会做到。
FOR /f "delims=" %%b IN (entitylist.txt) DO (
pushd "%destdrive%:\%year%\%projections%\%%~a\%%~b\" && (
for /d %%c in (*) do if /i not "%%c"=="2012" move "%%c" "%estimates%"
move *.* "%estimates%"
popd
)
)
这会做以下事情(我要使用图片,不知道为什么我之前没想到...... -_-
CURRENT RESULTS:
DESIRED RESULTS:
它基本上重命名2013
中的entity
文件夹,并将除2012之外的所有内容移动到该文件夹中,该文件夹现在具有November Estimates
名称