Solved copy images from a txt list to a folder

November 17, 2015 at 05:02:28
Specs: Windows 64
I have more than 15000 image files in a single folder. I need to find files that i have in a .txt file and copy them to a different folder

for /f "delims=" %a in (C:\Users\Paul\Desktop\list3.txt) do for /r "C:\Users\Paul\Desktop\Rala Upload\Rala Images 2" %b in ("%a*") do copy "%~Fb" C:\Users\Paul\Desktop\DestinationFolder

this runs but no images end up in the destination folder could anyone save my hair line I am a complete novice at this cmd stuff and batch files so please excuse being a numpty

message edited by Geord


See More: copy images from a txt list to a folder

Report •

✔ Best Answer
November 25, 2015 at 05:32:00
I cannot offer you a batch solution but i can offer you a VBA one. The code below reads each line from a text file, checks if the file exists in the source folder, then copies it to a destination folder. What it also does is make a record in Excel of all the files it has found and copied and all those that it couldnt find.

Assumptions

1) The text file being read has all enteries on a new line, for example

 
File1.txt
File2.txt
House.jpg
File4.txt

Here is the code.

You will need to modify the paths for 'SourceFolder' and 'DestinationFolder', you will also need to change the path to the file you need to read each line from, this is 'FileName'

Private Sub LetsStart()
    
    Dim FileNum As Integer
    Dim ReadLine As String
    Dim FileName As String
    
    Dim SourceFolder As String
    Dim DestinationFolder As String
    
    Dim NewRow As Integer
    
    SourceFolder = "P:\Source\"
    
    FileName = "P:\PWConvert.txt"
    DestinationFolder = "P:\Dest\"

    FileNum = FreeFile()
    
    Open FileName For Input As #FileNum

    While Not EOF(FileNum)
        Line Input #FileNum, ReadLine
            
        If FileExists(SourceFolder & ReadLine) Then
            
            FileCopy SourceFolder & ReadLine, DestinationFolder & ReadLine
            
            NewRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
            Sheet1.Range("A" & NewRow + 1).Value = ReadLine
            
            NewRow = 0
        
        Else
            NewRow = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
            Sheet1.Range("B" & NewRow + 1).Value = ReadLine
            
            NewRow = 0
        End If
        
        
    Wend
    
    Close #FileNum
   
End Sub

Private Function FileExists(iFile As String) As Boolean
    
    If Dir(iFile) <> "" Then
        FileExists = True
    Else
        FileExists = False
    End If
    
End Function

If you PM me your email address i can send you the Excel file with the code.

message edited by AlwaysWillingToLearn



#1
November 17, 2015 at 05:21:33
I'm no programmer either but, while you are waiting, I think this line should have quotes around it:
C:\Users\Paul\Desktop\DestinationFolder

... because it contains an item (DestinationFolder) which is more than 8 characters.

message edited by Derek


Report •

#2
November 17, 2015 at 05:34:21
Thanks for input Derek
have just tried but still the same results fella

Report •

#3
November 17, 2015 at 09:04:06
It would depend on a number of factors, including the contents of "list3.txt", if you're doing this in a batch file or directly from the Command Prompt, and what you're attempting by having two FOR loops.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
November 25, 2015 at 05:32:00
✔ Best Answer
I cannot offer you a batch solution but i can offer you a VBA one. The code below reads each line from a text file, checks if the file exists in the source folder, then copies it to a destination folder. What it also does is make a record in Excel of all the files it has found and copied and all those that it couldnt find.

Assumptions

1) The text file being read has all enteries on a new line, for example

 
File1.txt
File2.txt
House.jpg
File4.txt

Here is the code.

You will need to modify the paths for 'SourceFolder' and 'DestinationFolder', you will also need to change the path to the file you need to read each line from, this is 'FileName'

Private Sub LetsStart()
    
    Dim FileNum As Integer
    Dim ReadLine As String
    Dim FileName As String
    
    Dim SourceFolder As String
    Dim DestinationFolder As String
    
    Dim NewRow As Integer
    
    SourceFolder = "P:\Source\"
    
    FileName = "P:\PWConvert.txt"
    DestinationFolder = "P:\Dest\"

    FileNum = FreeFile()
    
    Open FileName For Input As #FileNum

    While Not EOF(FileNum)
        Line Input #FileNum, ReadLine
            
        If FileExists(SourceFolder & ReadLine) Then
            
            FileCopy SourceFolder & ReadLine, DestinationFolder & ReadLine
            
            NewRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
            Sheet1.Range("A" & NewRow + 1).Value = ReadLine
            
            NewRow = 0
        
        Else
            NewRow = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
            Sheet1.Range("B" & NewRow + 1).Value = ReadLine
            
            NewRow = 0
        End If
        
        
    Wend
    
    Close #FileNum
   
End Sub

Private Function FileExists(iFile As String) As Boolean
    
    If Dir(iFile) <> "" Then
        FileExists = True
    Else
        FileExists = False
    End If
    
End Function

If you PM me your email address i can send you the Excel file with the code.

message edited by AlwaysWillingToLearn


Report •

Ask Question