Thanks a lot Mr. Hans for your great and helpful efforts. I appreciate your help a lot
Thank you very much
I have posted a thread at this link
https://www.excelforum.com/excel-progra ... names.html" onclick="window.open(this.href);return false;
Move files by list in array
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Move files by list in array
At last I could figure it out using this code
Thanks a lot Mr. Hans for your great efforts in this issue
Regards
Code: Select all
Sub Move_Files()
Dim e As Variant
Dim x As Variant
Dim s As String
Dim t As String
Dim f As String
Dim c As Long
s = ThisWorkbook.Path & "\المستمسكات\"
t = ThisWorkbook.Path & "\مستمسكات القائمة\"
For Each e In Array("*.jpg")
f = Dir(s & e)
Do While f <> ""
x = Application.Match(Replace(f, "." & Split(e, ".")(1), ""), Columns(1), 0)
If Not IsError(x) Then
FileCopy s & f, t & f
Kill s & f
c = c + 1
End If
f = Dir
Loop
Next e
MsgBox "Total Number Of Moved Files : " & c, 64
End Sub
Regards
-
- Administrator
- Posts: 78615
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Move files by list in array
What is the purpose of
The only value in the array is "*.jpg" so there is no need for a loop...
Code: Select all
For Each e In Array("*.jpg")
...
Next e
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Move files by list in array
First may be I can deal with other extensions in the future
Second is that this is the way I could escape from the file names themselves as I depended on the extension and see if the file name is existing in the column or not ..
Second is that this is the way I could escape from the file names themselves as I depended on the extension and see if the file name is existing in the column or not ..
-
- Administrator
- Posts: 78615
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Move files by list in array
OK, I get the first point.
And instead of looping through the names in column A, you're looping through the files in the source folder and checking if they match column A.
And instead of looping through the names in column A, you're looping through the files in the source folder and checking if they match column A.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Move files by list in array
But this way works for me and I don't know why other ways doesn't work. That seems too weird for me
-
- Administrator
- Posts: 78615
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Move files by list in array
I don't know either, but perhaps the way left-to-right text and right-to-left text are combined in the filename cause the problem.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Move files by list in array
If so why the hard-coded code that I typed the names of the files work well ..!!?
-
- Administrator
- Posts: 78615
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- PlatinumLounger
- Posts: 4931
- Joined: 31 Aug 2016, 09:02
Re: Move files by list in array
Thank you very very much Mr. Hans
I really appreciate your great efforts my tutor. You are awesome
I really appreciate your great efforts my tutor. You are awesome