473,382 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

File Copying With Globbing

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

Apr 30 '06 #1
3 2624
Daz wrote:
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.
--
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?clcpp
Apr 30 '06 #2
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!

Apr 30 '06 #3
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.

May 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Luc Saffre | last post by:
Hello, I had a strange problem when freezing (using either py2exe or McMillan installer) a script that imports reportlab (which imports PIL (which imports FixTk))). - Python 2.3.3c (also with...
5
by: Thomas Lotze | last post by:
Hi, another question: What's the most efficient way of copying data between two file-like objects? f1.write(f2.read()) doesn't seem to me as efficient as it might be, as a string containing...
4
by: HKannen | last post by:
Hi everybody, I'd like to create a link to a file instead of copying the file to the new destination. Is there a possibility to do this ? Is there something like a Link Object in C# .NET ? ...
29
by: jaysherby | last post by:
I'm new at Python and I need a little advice. Part of the script I'm trying to write needs to be aware of all the files of a certain extension in the script's path and all sub-directories. Can...
2
by: TwistedPair | last post by:
All, This is sort of a continuation of a previous post of mine. The code below basically reads a registry key to get a path to a folder and it watches for files created in that folder (only...
0
by: Kenneth Porter | last post by:
Due to a mis-feature in Windows filesystems, I need a globbing function in C or C++ that can emulate the globbing done by the built-in FindFirstFile API. The license should allow it to be...
23
by: bc90021 | last post by:
Hi All, Thanks in advance for any and all help! I have this code: g = open(fileName, 'a') where fileName is defined before the line it's used in. It works fine when I use it outside a...
9
by: tdahsu | last post by:
All, I have the following code: for fileTarget in dircache.listdir("directory"): (dirName, fileName) = os.path.split(fileTarget) f = open(fileTarget).readlines() copying = False for i in...
8
by: aki | last post by:
Hi All, I describe the problem as below. A directory( path known) , contains 0 to any number of files . The file names are with following structure : ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.