2

File1.txt内容にいくつかの名前が保持されているマスターファイル( )があります。そのような名前のファイル(ワイルドカード)をフォルダ内で見つけて、バッチファイルプログラムを使用して別のフォルダに移動する必要があります。

例:File1.txt内容があります

  abcd
  efgh

今フォルダにc:\temp\Source私は次のようなファイルがあると言います

12abcd34.asc
56efgh78.asc
testing.asc

これらの2つのファイルだけをc:\ temp\Targetというフォルダーに移動する必要があります。

これが私のコードですが、現時点ではi*。*は予期しないものであるというエラーが表示されます。助けてくれませんか。

@Echo Off
title Test move files
set dir1=C:\temp\Source
dir %dir1%
Echo Directory Changed
FOR /f "eol=; delims=, " %i in (file1.txt) do move /y "*%i*.*" Target
4

1 に答える 1

1

どうぞ....

これが私が始めたときのディレクトリ構造です...

C:\Temp>tree /f
Folder PATH listing for volume OS
Volume serial number is XXXX-XXXX
C:.
│   file1.txt
│   run.bat
│
├───Source
│       12abcd34.asc
│       56efgh78.asc
│       testing.asc
│
└───Target

これは後で実行するrun.batです..バグ修正が含まれています...

C:\Temp>copy run.bat con
@Echo Off

title Test move files

set dir1=Source

dir %dir1%

Echo Directory Changed

FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
        1 file(s) copied.

今、私はバッチファイルを実行します...

C:\Temp>run.bat
 Volume in drive C is OS
 Volume Serial Number is XXXX-XXXX

 Directory of C:\Temp

19/07/2012  00:03    <DIR>          .
19/07/2012  00:03    <DIR>          ..
18/07/2012  23:59                 0 12abcd34.asc
18/07/2012  23:59                 0 56efgh78.asc
18/07/2012  23:59                 0 testing.asc
               3 File(s)              0 bytes
               2 Dir(s)  41,653,194,752 bytes free
Directory Changed
C:\Temp\Source\12abcd34.asc
        1 file(s) moved.
C:\Temp\Source\56efgh78.asc
        1 file(s) moved.

これが最終的なディレクトリ構造です...これで、機能していることがわかります...

C:\Temp>tree /f
Folder PATH listing for volume OS
Volume serial number is XXXX-XXXX
C:.
│   file1.txt
│   run.bat
│
├───Source
│       testing.asc
│
└───Target
        12abcd34.asc
        56efgh78.asc

これが必要なforループです...

FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target

変更点:

[1] within FOR you use %%i not %i.
[2] You need this format:

%dir1%  <-- Where
\       <-- path delimiter
*       <-- starts with anything
%%i     <-- contains what you want to search
*.*     <-- ends with anything

お役に立てれば。

于 2012-07-18T23:07:02.903 に答える