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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use wildcards in FileCopy

Status
Not open for further replies.

CptTom

Programmer
Jul 16, 2001
117
0
0
US
I can not find anything written either way. I want to write:

strSource = "C:\Data\*.dat"
strDestination = "c:\complete\allfiles.dat"
FileCopy strSource, strDestination
'Merge all .dat into a single .dat file called allfiles.dat

I get error '52 Bad Filename or number
My variables are picking up the correct info, so that is not the problam.

Any ideas???

Larry
 
I haven't used the FileCopy command, but if you use the Shell command, you can pass it the *.DAT and the destination file name.

Will that work for you? Terry M. Hoey
 
I'm trying to get away from using the shell command if at all possible. I have been using it to run DOS batch routines, but as my program is beginning to migrate to other computers running older versions of Windows & Office, Shell gets more & more complicated.

I guess the real question is, If Microsoft put FileCopy into VBA, why didn't they set it up for wildcards?

Larry
 
Larry, are you asking why Microsoft didn't think logically??? Please, it scares my co-workers when I laugh that loud... Terry M. Hoey
 
And my boss once wrote me:

Actually, I just assumed that you "programmer types" sat around in your spare time quaffing your drink de jour and contemplating ways to make life more Bill Gates-dependent.
 
CptTom:
I'm pretty sure you can't use the FileCopy function in that manner. You can use it to copy all the files from one directory to another (using the wildcards for Source), like this:
Code:
strSource = "C:\Data\*.dat"
strDestination = "c:\complete\"
FileCopy strSource, strDestination
which would move *.dat from C:\Data\ to your complete folder, but this isn't what you want.

What I'd do (and unfortunately I hate this) is Open a new file for Output (on first go, then append) and open and close each file and concatinating each into the a destination file. (Looping through each line until EOF and using Line Input # and Print #)
This should work on straight Ascii files.

The problem with this is- Access doesn't like binary data. I tried doing something similar while trying to build a program to concatinate many binary (but sequential) files togethor- doesn't work. Cuts them short, and the final product won't be what you want. I ultimately re-wrote my program just to output a shell string (Copy /b f1.txt+f2.txt+f3.txt) and etc, to the debug window, and used that in a dos shell. No, not eligant, and definately not professional for other users, but for myself, it worked.

However, if it's straight ASCII you're using, you shouldn't have a problem.

If it IS Binary data, I think I might have a reference for a solution, albeit, not a very nice-and-easy one for you- it's going to take a little research, but it's research that you may find enlightening if you haven't been exposed to API calls much:

If you absolutely must get it done, an Invaluable reference sight for more advanced programming (working with the Windows API), and the best VB API site I've found yet, is www.vbapi.com

Follow the Reference link, click Function Information...By Category, and under Files, you should see the links for infomration on the API calls for ReadFile and WriteFile. These will use buffers to read in, and write out the data you're trying to open. (The write also uses the CreateFile and CloseHandle APIs. Make sure you DO USE THE CloseHandle api call!)

If you knew about all that, and were just looking for some simple code Access might use, I'm sorry- I don't know of any.

However, this solution should do it. I haven't used this specific technique yet, but I'm planning on taking a look at it shortly. If I come up with some nice efficient code to handle your question (which eventually is what I want to do get anyhow) I'll post it.

-MoGryph
[8O)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top