我被卡住了,我已经尝试了所有我能想到的东西,但没有运气。我读过关于usebackq的文章,但不能让它工作。
我正在尝试创建一个批处理文件。应该检查folder1是否存在。如果存在,批处理文件将在folder1中创建名为Batch_1 Batch_2的文件夹。将folder1中的所有文件移动到Batch_1,然后将文件从某个位置移动到batch_2。
如果batch_2存在,它应该创建batch_3,然后将文件从某个位置移动到Batch_3,依此类推。
这就是我到目前为止所拥有的。当路径中没有空格时,它就像一个护身符...
@echo off &setlocal
set fullDest="C:\Users\Peppes Bodega\Desktop\hej hej\123"
set fullDest=%fullDest:"=%
if exist "%fullDest%" goto:omg2
echo %fullDest%
:omg1
echo normal flytt syntax
pause
goto:eof
:omg2
if exist %fullDest%\Batch_2 goto:omg3
for /d %%i in (%fullDest%) do (
pushd %%i\
set /a count=0
for /d %%j in (*.*) do set /a count+=1
popd
call echo %%count%% folder(s^) in %%i
call mkdir %fullDest%\Batch_%%count%%
call MOVE C:\Users\%username%\Desktop\_BP_TEMP\*.txt %fullDest%\Batch_%%count%%
pushd %%i\
set /a count=0
for /d %%j in (*.*) do set /a count+=1
popd
call mkdir %fullDest%\Batch_%%count%%
call MOVE C:\Users\%username%\_BP_TEMP\*.txt %fullDest%\Batch_%%count%%
)
pause
goto:eof
:omg3
for /d %%i in (%fullDest%) do (
pushd %%i\
set /a count=0
for /d %%j in (*.*) do set /a count+=1
popd
call mkdir %fullDest%\Batch_%%count%%
call MOVE C:\Users\%username%\Desktop\_BP_TEMP\*.txt %fullDest%\Batch_%%count%%
)
pause
goto:eof如果能帮上hand.cr的忙我会很感激的
发布于 2015-05-08 03:33:42
首先,让我们弄清楚一些笨拙的语法。
set fullDest="C:\Users\Peppes Bodega\Desktop\hej hej\123"
set fullDest=%fullDest:"=%更好的方法是
设置"fullDest=C:\Users\Peppes Bodega\桌面\hej hej\123“
语法SET "var=value" (其中值可以为空)用于确保赋值的值中不包含任何零散的尾随空格。set /a可以安全地使用“无引用”。
接下来,如果目标包含通配符,则for /d会列出目录,因此您需要
for /d %%i in ("%fullDest%\*") do (同样,无论在哪里使用fulldest,都需要用引号将名称括起来,以确保它被视为一个单独的项,而不是一个列表,因此
if exist "%fullDest%\Batch_2" goto:omg3(类似于您的初始使用)
call MOVE "C:\Users\%username%\Desktop\_BP_TEMP\*.txt" "%fullDest%\Batch_%%count%%"(move需要move source destination -引号,如图所示,告诉cmd每个元素可以包含空格)
类似地,
call mkdir "%fullDest%\Batch_%%count%%"诸若此类。
pushd%s中的结束\是多余的。
https://stackoverflow.com/questions/30108802
复制相似问题