[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Moving Files with * Wildcard

Posted on 2003-03-17
8
Medium Priority
?
255 Views
Last Modified: 2010-05-01
I am trying to move all files of a cretain type from a directory I specify to another different directory. The idea is like the following from the command line:

move C:\*.text C:\temp\

How can I achieve this with VB6 as simply as possible?

Thanks-
Mack1er
0
Comment
Question by:mack1er
8 Comments
 
LVL 1

Accepted Solution

by:
JH0401 earned 280 total points
ID: 8154828
Dim NewFile

Do
New_File = Dir("C:\*.txt")
if new_file = "" then
   exit do
else
   filecopy "C:\" & new_file, "C:\temp\" & new_file
   kill "C:\" & new_file
end if
loop
0
 
LVL 1

Expert Comment

by:JH0401
ID: 8154859
the above assumes "C:\temp" directory exists
0
 
LVL 1

Expert Comment

by:JH0401
ID: 8154905
Sorry --- I guess it would help to define
the same variable you will be using in the
code!!!!

Dim New_File$
Do
New_File = Dir("C:\*.txt")
if new_file = "" then
  exit do
else
  filecopy "C:\" & new_file, "C:\temp\" & new_file
  kill "C:\" & new_file
end if
loop
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 3

Expert Comment

by:Hornet241
ID: 8154919
Try this

Dim fname
fname = dir("C:\*.text")
do while fname > ""
    Name "C:\" & fname as "C:\temp\" & fname
    fname = dir
loop

All Done
0
 

Expert Comment

by:OzWolf
ID: 8154954
Try the following:

Dim strFileName as String
Dim strOldFileName as String
Dim strNewFileName as String

strFileName = Dir("C:\*.txt")

While strFileName <> ""
   strNewFileName = "C:\Temp\" & strFileName
   strOldFileName = "C:\" & strFileName
   Name strOldFileName as strNewFileName
   strFileName = Dir()
Wend
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8155892
This is simple:

Private Sub Command1_Click()
Shell "command.com /c move C:\*.text C:\temp\", vbNormalFocus
End Sub

you could replace vbNormalFocus with vbHide if you do not want to see the window.
0
 

Author Comment

by:mack1er
ID: 8158662
JH0401,

That worked like a charm. Thanks!

Mack1er
0
 

Author Comment

by:mack1er
ID: 8158671
Worked great - thanks for the quick response.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question