By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

How can I recursively move *.jpg files ?

P: 5
How can I recursively move *.jpg files from a memory card to a specified directory?

I have searched the internet for days and not found a way to do this.

Feb 5 '08 #1
Share this Question
Share on Google+
10 Replies

Expert 100+
P: 1,295
How can I recursively move *.jpg files from a memory card to a specified directory?

I have searched the internet for days and not found a way to do this.

well, it depends of the version of VB you're using, but in most cases, something like this will help to move the file:

Expand|Select|Wrap|Line Numbers
  1. My.Computer.FileSystem.MoveFile("D:\mypic.jpg", "C:\path\mypic.jpg")
if you want to overwrite the file without asking you, you can turn off the dialogs, its an optional parameter of MoveFile.
I think using a FOR or a DO, and some time functions you can set when the files will be moved.

Remember that using smart file names can be helpful, e.g.

Expand|Select|Wrap|Line Numbers
  1. dim i as long
  2. for i = 1 to 30
  3.     My.Computer.FileSystem.MoveFile("D:\mypic" & i & ".jpg", "C:\path\mypic" & i & ".jpg")
  4. next
this way you can move mypic1, mypic2, mypic3 ... mypic30 quite easy.
otherwise, using DIR or FOR EACH might help you moving a complete directory.

Feb 5 '08 #2

P: 58

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.    Dim source_path As String, target_path As String
  4.    source_path = "C:\Documents and Settings\WinblowsME\Desktop\Images"
  5.    target_path = "C:\Documents and Settings\WinblowsME\Desktop\Backup\"
  7.    Call Copy_Files(source_path, target_path, "*.jpg")
  8.    Call Copy_Files(source_path, target_path, "*.gif")
  9.    Call Copy_Files(source_path, target_path, "*.bmp")
  10. End Sub
  12. Private Sub Copy_Files(source_path As String, target_path As String, file_type As String)
  13.    Dim regex As Object, file_name As String
  15.    Set regex = CreateObject("VBScript.RegExp")
  17.    regex.Pattern = "\\*$"
  18.    source_path = regex.Replace(source_path, "\")
  19.    target_path = regex.Replace(target_path, "\")
  21.    file_name = Dir(source_path & file_type, vbDirectory)
  23.    Do While file_name <> ""
  24.       Call FileCopy(source_path & file_name, target_path & file_name)
  26.       file_name = Dir
  27.    Loop
  28. End Sub

Expand|Select|Wrap|Line Numbers
  1. copy "source_dir\*.jpg" "target_dir"
Feb 5 '08 #3

Expert 5K+
P: 8,434
By "recursively", do you mean that you want to work your way down through the directory tree and copy all the images you find in there?
Feb 6 '08 #4

P: 5

I want to gather the .jpg buried about 2 directories down.

Search all the subdirectories.

Feb 6 '08 #5

Expert 5K+
P: 8,434
I've got some code to do a recursive scan of subdirectories. I'll try to dig it out when I can. Might not be until tonight, though (it's about 10:30 now, Sydney time).
Feb 6 '08 #6

P: 5
Thanks, I'll be waiting.
Feb 7 '08 #7

P: 58
Here's a simple solution with XCOPY.
Feb 7 '08 #8

P: 5
How would I use this in ?
Feb 7 '08 #9

Expert 5K+
P: 8,434
Forgot to dig out my code. But the basic logic is quite simple. It's a recursive routine to handle each folder. Something along these lines. I recommend using FileSystemObject, but exactly how you access the files and folders is your choice, really.

Expand|Select|Wrap|Line Numbers
  1. Sub ProcessFolder(ByVal Fld As String)
  2.   For each file F in folder Fld
  3.     ProcessFile F
  4.   Next
  5.   For each subfolder S in folder Fld
  6.     ProcessFolder S
  7.   Next
  8. End Sub
  11. Sub ProcessFile(ByVal FileName As String)
  12.   Do whatever it is you want with file FileName
  13. End Sub
Note I've just indicated we're passing the folder and file names here, as strings. But you could pass actual Folder or File objects.
Feb 7 '08 #10

P: 5

I'll try it out.
Feb 7 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.