如何让Windows批处理文件查看数百个文件夹并根据list.txt移动文件?

[英]How do I have a windows batch file look through hundreds of folders and move files around based on a list.txt?


I cant seem to get this to work. I need a batch file to go through a bunch of folders with files in them and move them to folders specified in the list .txt.

我似乎无法让这个工作。我需要一个批处理文件来浏览包含文件的一堆文件夹,并将它们移动到列表.txt中指定的文件夹中。

Basically I want it to do the following: sample list.txt

基本上我希望它执行以下操作:sample list.txt

folder1 file1
folder2 file1

and parse that so that i can:

并解析,以便我可以:

copy C:\folder1\file1*.txt to destination folder
copy C:\folder2\file1*.txt to destination folder
etc

Here is what I have so far:

这是我到目前为止:

Main program:

echo off
set lines=0

for /f "tokens=1 delims=" %%a in (%CD%\list.txt) do (
                echo %%a
                echo 1 %SN% from EEN %EEN%               
                call :first %%a
                echo 2 %SN% from EEN %EEN%               
                call :second %%a
                echo 3 %SN% from EEN %EEN%               
                set /a lines+=1
)

echo %lines%
pause
goto :eof

:first
set EEN=%1
goto :eof

:second
set SN=%2
goto :eof

pause

list.txt (first column is folder name, second is file name):

list.txt(第一列是文件夹名,第二列是文件名):

DM5V37H WMC1F0077774
DM5V37H WMC1F0077711
DM5V37H WMC1F0086480
DM5V37H WMC1F0086372
DM5V37H WMC1F0077655
DM5V37H WMC1F0077770

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


0  

I'm not sure about your references to SN and EEN, but I just tested this and it seems to work. The first section is a demonstration of how to access each item in a line read from the file, then the actual move operation is performed. I'm sure you can modify it to your needs.

我不确定你对SN和EEN的引用,但我只测试了它,它似乎工作。第一部分演示了如何访问从文件读取的行中的每个项目,然后执行实际的移动操作。我相信你可以根据自己的需要进行修改。

@echo off
set lines=0

for /f "tokens=1,2 delims= " %%a in (list.txt) do echo %%a %%b&set /a lines+=1
echo Number of lines: %lines%

:: Perform move operation.  
for /f "tokens=1,2 delims= " %%a in (list.txt) do (
if not exist %%a (md %%a)
move "%%b" "%%a\%%b"
)

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/10/12/ac0a5c8974f49a9d9372df86b4bade81.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com