473,386 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I recursively move *.jpg files ?

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.

Thanks,
Feb 5 '08 #1
10 3329
kadghar
1,295 Expert 1GB
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.

Thanks,
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
  5.  
this way you can move mypic1, mypic2, mypic3 ... mypic30 quite easy.
otherwise, using DIR or FOR EACH might help you moving a complete directory.

HTH
Feb 5 '08 #2
VBA.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.    Dim source_path As String, target_path As String
  3.  
  4.    source_path = "C:\Documents and Settings\WinblowsME\Desktop\Images"
  5.    target_path = "C:\Documents and Settings\WinblowsME\Desktop\Backup\"
  6.  
  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
  11.  
  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
  14.  
  15.    Set regex = CreateObject("VBScript.RegExp")
  16.  
  17.    regex.Pattern = "\\*$"
  18.    source_path = regex.Replace(source_path, "\")
  19.    target_path = regex.Replace(target_path, "\")
  20.  
  21.    file_name = Dir(source_path & file_type, vbDirectory)
  22.  
  23.    Do While file_name <> ""
  24.       Call FileCopy(source_path & file_name, target_path & file_name)
  25.  
  26.       file_name = Dir
  27.    Loop
  28. End Sub
  29.  
MS-DOS

Expand|Select|Wrap|Line Numbers
  1. copy "source_dir\*.jpg" "target_dir"
Feb 5 '08 #3
Killer42
8,435 Expert 8TB
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
ronqa
5
Yes,

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

Search all the subdirectories.

Thanks,
Feb 6 '08 #5
Killer42
8,435 Expert 8TB
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
ronqa
5
Thanks, I'll be waiting.
Feb 7 '08 #7
Here's a simple solution with XCOPY.

http://www.tech-recipes.com/rx/2682/...e_exclude_flag
Feb 7 '08 #8
ronqa
5
How would I use this in VB.net ?
Feb 7 '08 #9
Killer42
8,435 Expert 8TB
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
  9.  
  10.  
  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
ronqa
5
Thanks,

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

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

Similar topics

4
by: Ruby Tuesday | last post by:
Is there a fast way to read files/directory recursively? Instead of inspecting each file(s)/dir(s), is there a way to know that its a file or a directory from its hidden attribut both for windows...
1
by: Antonio Lopez Arredondo | last post by:
hi all !!! I need to copy a folder and its subfolders to another location; which class should I use ? could only find the System.IO.Directory.MOVE but don't know how to COPY. thanks in...
2
by: melo | last post by:
Hello, I've been struggling with a function(s) to recursively set all folders and files to NOT read-only. So, I thought I'd post this message. What I need to do is: given a starting path, I...
5
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
3
by: Kamen TOMOV | last post by:
Hi, Is uploading recursively directories to a web server possible with JavaScript? I mean is it possible read a directory recursively and dynamically construct <input type="file"> with value...
2
by: Zytan | last post by:
You can download them here: http://msdn2.microsoft.com/en-us/vstudio/aa718338.aspx This snippet seems wrong: Visual C# 2005 Code Snippets -filesystem -Search a Directory for Files Recursively ...
9
by: pamela fluente | last post by:
What is the most current (for framework 2.0) and easy way to copy recursively all files from folder "Folder1" to folder "Folder2" ? Is there any simple function in the framework to do that? ...
9
by: bhumikas | last post by:
Hi all, I need a help in perl script.The basic idea is,it must have command line arguments for the user flexibility.the files are in the format as shown below. MainFolder Directory ...
5
by: Jeff Schwab | last post by:
I need to move a directory tree (~9GB) from one machine to another on the same LAN. What's the best (briefest and most portable) way to do this in Python? I see that urllib has some support for...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.