Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2007, 12:36 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default subject: renaming a file w/ wildcards in name

hello,
I have this code that I'm trying to use but is not working, so I'm posting on here to see if someone can help me with how to fix the error. What the code is trying to do is to look in the subdirectory
D:\B D client data\H T\NewBusinessfor a file that will have (a string of numbers) + (.txt) as it's file name and rename that file to HT012507.txt.
There is another file in the same directory named HT.txt that needs to be left alone and not renamed. These are the only two .txt files in the subdirectory.

Visual Basic is giving me the
Run-time error '52':
Bad file name or number
when I try to run the code, and stops on the Name line, so I'm assuming the SourceFile line is the problem.

Can anyone help me with what the syntax of the below code so it will work properly?

thanks in advance,
david

Code:
Dim SourceFile, DestinationFile As String

 SourceFile = "D:\B D client data\H T\NewBusiness\[1-9]*.txt"
 DestinationFile = "D:\B D client data\H T\NewBusiness\HT" & Format(Date, "mmddyy") & ".txt"
    Name SourceFile As DestinationFile
 
Old January 25th, 2007, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you cannot use wildchar in the Name statement.
did you try using Shell?

Shell "cmd /c rename " & srcFile & " " & dstFile, vbHide

Marco

"There are two ways to write error-free programs. Only the third one works."
Unknown
 
Old February 2nd, 2007, 03:21 PM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

David, Marco is right: you can't do it that way. You can probably do this with Regular Expressions and either an array or a FileListBox. I haven't done much with regular expressions but there are some good tutorials out there that should get you started. Unfortunately it's not really a topic that can be adequately covered in a forum reply.

Always take into account what nobody would ever in a million years do, because someone will.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming an Email File Attachment jpwalters C# 1 May 21st, 2008 12:43 PM
Renaming long file name with VBA JillB Excel VBA 1 March 24th, 2008 06:20 PM
Renaming File ayazhoda Access VBA 3 April 24th, 2007 05:43 AM
Renaming a file during upload keph Pro PHP 1 October 6th, 2005 07:14 PM
Renaming File During Upload keph Beginning PHP 1 October 4th, 2005 02:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.