【发布时间】:2016-09-03 10:59:47
【问题描述】:
我想移动这些文件(扩展名无关紧要)
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 脚本有什么解决方案吗?
【问题讨论】:
-
在 PowerShell 中为
foreach ($dir in gci -Directory) { gci | where Name -match $dir.Name | mv -Destination $dir } -
所以文件夹
cane已经存在了,它的名字就是文件名中要搜索的词? -
@aschipfl 是的,它是正确的..但我不知道我必须如何使用 powershell。我复制命令,但它告诉我无效..
标签: batch-file filenames directory