Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RENAME ABOUT 400 ".TIF" (IMAGE) FILES SAVED IN VARIOUS FOLDERS . 2

Status
Not open for further replies.

Gemini07306

Technical User
Jun 25, 2003
15
US
Please, I need all the expertise from any of you good folks.
I have about 400 files, and these file are saved in various folders in "C:\" drive.
example: C:\Image\files.TIF
I know I can acomplish this by using the "Name statement" - Oldname As Newname. What code can I use to loop thru and rename all the files in all the folders?

DOS Command in vba
-------------------
I can use a DOS command in a Dos prompt: "C:>" to copy a list of files from one folder to another.
Example: C:\JVIAIMAGE\IMAGES\01092004*.TIF > C:\NEWFOLDER\FILENAME.DOC.

How can I execute this DOS command in VBA? Is there any command,function or special character that I can put in the "DIR" Access function to execute the above copy Dos command?
Thank you all for your assistance.


 
Gemini,
Exactly what are you trying to do?

Move files from several different folders to a single folder?

Or

Rename several different files in several different folders?

Or

Rename AND move them?

If you want to rename them, what rule are you using to know what the new name should be? The old name with something appended to it? Some text and a sequential number? Creation date? Something you key into an inputbox?

I have been planning on doing something like this for myself in order to organize my digital photos. If you're wanting to the same type thing, I'd be happy to help you because it would get the job done for me, too.

Tranman
 
In VBA you can use the FileSystemObject, which gives you access to the computer's file system, including folders and subfolders.
Is that what you had in mind?
 
This sample functionh will iterate through all files in a nominated folder, and copy them to a destination folder; Note: it contains no error handling, so I'll assume that source and destination folder exist.
Code:
Function CopyFolder(SourceFolder, DestFolder)
[green]'------------------------------------------------------------------
'This function iterates through all files in a source
'folder and copies each file to the same filename in a destination folder.
'-------------------------------------------------------------------------[/green]
   Thisfile = Dir(SourceFolder)
   While Thisfile <> ""
         FileCopy SourceFolder & ThisFile, DestFolder & ThisFile
         Thisfile = Dir
   Wend
End Function
Sample invocation:
Code:
    CopyFolder("C:\SourceFolder\", "C:\DestFolder\")

For a more elegant solution, you might also wish to check out the properties and methods of the FileSystemObject, as indicated by Edski above.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
And another thing that I forgot in my last post; if instead of copying the file during the folder iteration, you want to rename it, use the NAME command; eg. from VBA online help:
Code:
OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName    [green]' Move and rename file.[/green]


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
What I usually do is in 2 steps :

Use the application.filesearch method to return all files to rename, then loop through the .founddiles running a rename function on each file.

with application.filesearch
.newsearch
.filename = "*.tif"
.lookin = "c:\images"
.searchsubfolders = true
if execute > 0 'if the search is successful
for i = 1 to foundfiles.count
name foundfiles(i) as newfilename
next i
end if
end with
 
by way of a simple correction to the above post; the line
[tt]
if execute > 0 'if the search is successful
[/tt]
should read
[tt]
if [red].[/red]execute > 0 'if the search is successful
[/tt]
ie. add the dot before the word execute, as execute is a method of application.filesearch.

sorry to 'hijack' your post p27br, but it would be a pity for it not to work because of that little error,

cheers

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
thanks steve,
the dot stayed glued to my finger !
 
A star to you, p27br. What a sweet piece of code!

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top