-
I have a program that copies files in a directory and saves them into a backup folder. There are multiple files that the program (the program that creates the files I backup) makes when they save. I need to be able to access all of the files to copy... They enter the name of the save...and that can be used to get the files names...but not the extension.
How would i make the filecopy function copy their text (for the files names) and make it copy all extensions that share the same name?
FileCopy "C:\Windows\Filesname.*", "D:\backup\Filesname.*"
Would something like that work?
-
you could use a filebox with a filter and run down the list
-
You could use Dir function and return all files of that extension, and you can use wildchars too, then copy each of them
-
can you guys give me an example...
And I there are other files in the directory...so I cant copy all files in the dir.
-
Code:
Dim A as string
A=Dir(Source)
Do
FileCopy A, Destination
A=Dir
Loop While len(a)
Where you put Source String to "C:\Windows\Filesname.*" and Destination String to "D:\backup"
-
that didn't work :-((((((((((((
-
Drop the following into a module.
Code:
Option Explicit
Sub Main()
'Method1
Call p_CopyMethod1("C:\Internet Download\*.*", "C:\Unzip Area")
'Method2
Call p_CopyMethod2("C:\Internet Download", "C:\Unzip Area")
End Sub
Sub p_CopyMethod1(str_Source As String, str_Destination As String)
Dim v_FileSystemObject As Object
Set v_FileSystemObject = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'PURPOSE:Copy all files in current directory
v_FileSystemObject.CopyFile str_Source, str_Destination, True
'PURPOSE:Copy all sub directories in current directory
'v_FileSystemObject.CopyFolder str_Source, str_Destination, True
Set v_FileSystemObject = Nothing
End Sub
Sub p_CopyMethod2(str_Source As String, str_Destination As String)
'PURPOSE:Check if user inputted a "\" or not
If Right(str_Source, 1) <> "\" Then
str_Source = str_Source & "\"
End If
If Right(str_Destination, 1) <> "\" Then
str_Destination = str_Destination & "\"
End If
'PURPOSE:Change directory
ChDir str_Source
Dim str_File As String
str_File = Dir(str_Source & "*.*")
Do Until str_File = ""
FileCopy str_Source & str_File, str_Destination & str_File
str_File = Dir()
Loop
End Sub
If you want to filter out only specific file extensions, play around with the *.
-
I have no clue how that would work...
Let me try and explain my problem again..there has to be a easier solution...
Ex.
I have 4 files in the same directory:
test.tjf
test.dkj
test.csd
test.kjd
I want to copy all four of thoes files to another directory. I cant simply copy the directory, because there are files other than the ones I want to copy in the directory. Is there an easier way than explained above (that works) to do this?
-
Oh, just one thing i forgot, you need to have both fullpaths with filecopy: Just add Filepart function somewhere in a module
Code:
Dim A as string
A=Dir(Source)
Do
FileCopy A, Destination & "\" & Filepart(A)
A=Dir
Loop While len(a)
Code:
Function Filepart(filepath)
For n = Len(filepath) To 1 Step -1
If Mid(filepath, n, 1) = "\" Then Exit For
Next n
Filepart = Mid(filepath, n + 1)
End Function
-
Sac
As I said, play around with the *.*. In this case, you would change the *.* to Test.* because you are copying all files with the name TEST and whatever extensions.
Drop this into a project with only a module and test run it. Make sure in the SUB MAIN below, change it to your source location and destination location.
Code:
Option Explicit
Sub Main()
'Method1
Call p_CopyMethod1("C:\Your Source Directory\Test.*", "C:\Where you want to copy it to")
End Sub
Sub p_CopyMethod1(str_Source As String, str_Destination As String)
Dim v_FileSystemObject As Object
Set v_FileSystemObject = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'PURPOSE:Copy all files in current directory
v_FileSystemObject.CopyFile str_Source, str_Destination, True
'PURPOSE:Copy all sub directories in current directory
'v_FileSystemObject.CopyFolder str_Source, str_Destination, True
Set v_FileSystemObject = Nothing
End Sub
Once you get this working, check over the codes I posted last night. I putted METHOD1 and METHOD2 mean there are two different ways to do this.
[Edited by Nitro on 07-29-2000 at 06:02 PM]
-