我想移动这个文件(扩展名是irrilevant)
cane pazzo.txt
cane.torrent
incredibile cane s03.xx
进入文件夹
cane
我有这个代码
@echo off
setlocal enabledelayedexpansion
pushd %1
for /F "USEBACKQ tokens=*" %%a in (`dir /b /a:-d`) do (
set "_file=%%a"
for /D %%b in (*) do (
if NOT "x!_file:%%b=!" == "x!_file!" (
move %%a %%b
)
)
)
popd
但我只能移动与文件夹同名的文件
cane.torrent --> cane
相反,这些文件
cane pazzo.txt
incredibile cane s03.xx
由于文件名中有多个单词,因此未在内部移动。为什么?
有.bat脚本的解决方案吗?
您的逻辑是正确的。唯一的一点是move
命令应该用引号将文件括起来,以便正确处理包含空格的名称:
move "%%a" "%%b"
我也会在比较中去掉"x",因为这是不必要的:
if NOT "!_file:%%b=!" == "!_file!" (