0

I have a CSV file which I have exported from our data module, which only contain product numbers. The product numbers are comma separated, which may or may not course a problem (I am not that good of a programmer). I found a fancy little batch here at stackoverflow, which has helped me to read the csv when running the batch, however, I am lost when it comes to trigger the right commands.

@echo off
set "theDir=C:\Web\Photos"
for /F "delims=" %%x in (C:\Web\MySQL_active_product_numbers.csv) do (
   copy %theDir%\%%x*.* "C:\Web\ActivePhotos\"
)

I have set the directory I want to scan, using the theDir variable, and in my csv file I have a list a product numbers. Example of csv content (one column only):

10000,02,65
10000,25,65
10001,02,65
...

The files I want to copy contain more characters than what each line in the csv contain, which is why I need the wildcard search to locate and copy the file. Example of files.

10000,02,65 chocolate bar.jpg
10000,25,65 ice cream cone.jpg
10001,02,65 candy.jpg
....

I really want to copy the jpgs from one directory to another, but as you can see from my csv, I only have the product numbers to match the filename, but I can't figure out how to use the wilcard search within my batch, to loop through the csv, to locate each file and copy it to a different directory. I hope it all made sense, and I appreciate all your input and support with my batch problem. Thanks.

4

1 回答 1

1

代替

copy %theDir%\%%x*.* "C:\Web\ActivePhotos\"

尝试:

copy "%theDir%\%%x*.*" "C:\Web\ActivePhotos\*.*"

(您的文件名包含空格!)

编辑 好,它在我的电脑上运行良好。path\filename用Doubleqoutes ( ) 括起来可以很容易地解决逗号和空格的问题。"这是证明:

C:\Users\Stephan\CanCan>type t.bat
@echo off
dir C:\users\Stephan\CanCan\New\*.*

set "theDir=C:\users\Stephan\CanCan"
for /F "delims=" %%x in (C:\users\Stephan\CanCan\t.csv) do (
   copy "%theDir%\%%x*.*" "C:\users\Stephan\CanCan\New\*.*"
)

dir C:\users\Stephan\CanCan\New\*.*

C:\Users\Stephan\CanCan>type t.csv
10000,02,65
10000,25,65
10001,02,65
C:\Users\Stephan\CanCan>
C:\Users\Stephan\CanCan>dir *.jpg
 Datenträger in Laufwerk C: ist Boot
 Volumeseriennummer: FA25-2E12

 Verzeichnis von C:\Users\Stephan\CanCan

01.08.2013  18:45                 6 10000,02,65 chocolate bar.jpg
01.08.2013  18:45                 6 10000,25,65 ice cream cone.jpg
01.08.2013  18:45                 6 10001,02,65 candy.jpg
               3 Datei(en),             18 Bytes
               0 Verzeichnis(se), 753.621.913.600 Bytes frei

C:\Users\Stephan\CanCan>t.bat
 Datenträger in Laufwerk C: ist Boot
 Volumeseriennummer: FA25-2E12

 Verzeichnis von C:\users\Stephan\CanCan\New

01.08.2013  18:52    <DIR>          .
01.08.2013  18:52    <DIR>          ..
               0 Datei(en),              0 Bytes
               2 Verzeichnis(se), 753.621.913.600 Bytes frei
C:\users\Stephan\CanCan\10000,02,65 chocolate bar.jpg
        1 Datei(en) kopiert.
C:\users\Stephan\CanCan\10000,25,65 ice cream cone.jpg
        1 Datei(en) kopiert.
C:\users\Stephan\CanCan\10001,02,65 candy.jpg
        1 Datei(en) kopiert.
 Datenträger in Laufwerk C: ist Boot
 Volumeseriennummer: FA25-2E12

 Verzeichnis von C:\users\Stephan\CanCan\New

01.08.2013  18:53    <DIR>          .
01.08.2013  18:53    <DIR>          ..
01.08.2013  18:45                 6 10000,02,65 chocolate bar.jpg
01.08.2013  18:45                 6 10000,25,65 ice cream cone.jpg
01.08.2013  18:45                 6 10001,02,65 candy.jpg
               3 Datei(en),             18 Bytes
               2 Verzeichnis(se), 753.621.913.600 Bytes frei


C:\Users\Stephan\CanCan>
于 2013-08-01T13:18:37.017 回答