File Copying With Globbing

D

Daz

Hi everyone!

This is my first time posting in this group, although I have been
watching it for the past few months and have to say this is possibly
the best group I have seen on Google so far! (That wasn't a
butt-kissing comment, I just believe in giving praise when it's due).

I would like to copy files using globbing, and I am not sure of the
best way to do it. I have tried using system("COPY [source]
[destination]"), but It's still not quite what I am looking for.

Firstly (as this is a console application), I see the message "1
file(s) copied.", which I would rather not see. And...
Secondly I need to know the name of the output file once the copying
has completed.

I need to be able to copy files using both '*' and '?' wildcards, and I
will need a method of finding out what the output file was. I can only
think of long-winded ways of acheiving my objective, and if that's the
route I need to take, then so be it, but it would be great if there is
a function that I have overlooked so I don't need to find a big regex
header file to use in my tiny program.

Copying the file is only the first phase of the operation, before the
output file is formatted (hence why I need to know the name of the
output file).

If there is no standard way of doing this, any suggestions would be
fantastic. I have been learning C++ for about 3 months now, and I am
self-taught (to give me a headstart when I go to college), so I am far
from being an expert. With that said, I am not using it as an excuse
for my ignorance as I believe the best way to learn it by 'doing'.
However, I would rather learn to do something in the best way, as
opposed to learning the best ways in which how NOT to do something, and
never finding the best answer.

I don't necessarilly expect a solution, but any pointers (not *pointers
:p) would be very much appreciated.

Best wishes

Daz
 
D

Diomidis Spinellis

Daz said:
Hi everyone!

This is my first time posting in this group, although I have been
watching it for the past few months and have to say this is possibly
the best group I have seen on Google so far! (That wasn't a
butt-kissing comment, I just believe in giving praise when it's due).

I would like to copy files using globbing, and I am not sure of the
best way to do it. I have tried using system("COPY [source]
[destination]"), but It's still not quite what I am looking for.

Firstly (as this is a console application), I see the message "1
file(s) copied.", which I would rather not see. And...
Secondly I need to know the name of the output file once the copying
has completed.

I need to be able to copy files using both '*' and '?' wildcards, and I
will need a method of finding out what the output file was. I can only
think of long-winded ways of acheiving my objective, and if that's the
route I need to take, then so be it, but it would be great if there is
a function that I have overlooked so I don't need to find a big regex
header file to use in my tiny program.

Copying the file is only the first phase of the operation, before the
output file is formatted (hence why I need to know the name of the
output file).

If there is no standard way of doing this, any suggestions would be
fantastic. I have been learning C++ for about 3 months now, and I am
self-taught (to give me a headstart when I go to college), so I am far
from being an expert. With that said, I am not using it as an excuse
for my ignorance as I believe the best way to learn it by 'doing'.
However, I would rather learn to do something in the best way, as
opposed to learning the best ways in which how NOT to do something, and
never finding the best answer.

I don't necessarilly expect a solution, but any pointers (not *pointers
:p) would be very much appreciated.

Filename globbing is either implemented at the level of the operating
system command shell (this is for example the case in Unix-type
systems), or by individual programs (this is for example the case on the
Windows platform default shell cmd32). In the first case your program
will receive the already expanded arguments in argv[]. In the second
case, you program could either perform the globbing by itsself (through
platform-specific mechanisms, like opendir, readdir) or rely on an
external library. For example, on some versions of Microsoft's
compilers you can have globbing performed internally before the
command-line arguments are passed to main by linking your program with
the supplied setargv.obj file. As you can see, none of globbing options
are related to the C++ language; all depend on platform-specific
functionality.
 
D

Daz

In the second case, you program could either perform the globbing by itsself
(through platform-specific mechanisms, like opendir, readdir) or rely on an
external library. For example, on some versions of Microsoft's
compilers you can have globbing performed internally before the
command-line arguments are passed to main by linking your program with
the supplied setargv.obj file.

Unfortunately, before the globbing needs to take place, there are
various other functions I didn't mention for the sake of simplicity,
(such as checking to see if the input or output file exists). I think I
may just try to work with _findfirst and _findnext for now (which I
think have a very similar function to opendir and readdir).

I need to learn about how to design classes, too, so now might be a
good opportunity for me to do so.

Thank you so much for your input, and for such a rapid response. It's
very much appreciated!
 
D

Daz

Hi all!

I'm afraid I am still having trouble expanding wildcards. Really, it's
only 1 argument that needs to be expanded. Here is an example:

expandWild(thisfile.txt, *s2.doc)
should output "this2.doc"

This appears to be how WIN32-COPY works. I can't use _setargv.obj as I
need to expand the wildcard in accordance to the input filename.

I hope this makes sense.

I have tried looking on Google (for days now), and can't seem to find
anything that is much help. I can only seem to find information on
wildcard searching, but I don't believe this is what I need.

Any assistance would be appreciated as always.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top