473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file deletion in a directory with some conditions .

aki

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 :

OMCID_NETYPE_NE NAME_NAMEOFTHEA PPLIEDFILE_APPL YDATE_trans.csv
For example :

4_TC_TC_48_NoST Configuration_1 971-1-1_trans.csv

where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIE DFILE=NoSTConfi guration
APPLYDATE=1971-1-1

i have to perform delete operation on the file with matching three
fields .
OMCID , NETYPE, NENAME (All three known )

Could somebody try to answer the problem . or tel how to proceed

Regards
Aki
Jul 31 '08 #1
8 2276
aki wrote:
>
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 :

OMCID_NETYPE_NE NAME_NAMEOFTHEA PPLIEDFILE_APPL YDATE_trans.csv
For example :

4_TC_TC_48_NoST Configuration_1 971-1-1_trans.csv

where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIE DFILE=NoSTConfi guration
APPLYDATE=1971-1-1

i have to perform delete operation on the file with matching three
fields .
OMCID , NETYPE, NENAME (All three known )

Could somebody try to answer the problem . or tel how to proceed
Firstly C doesn't have *any* support for directories, so you may want to
ask in a group for your system like comp.unix.progr ammer.

Secondly, once you get a list of all the files in your directory, you
need to match the OMCID, NETYPE, and NENAME fields of these names with
your criteria. If you don't want to write code to do this, you can use
a regular expression library, which is not a part of Standard C but is
nevertheless included with most major implementations . This will
relieve you of the tedium of writing the string comparison code and the
possibilities of bugs, testing, etc. A further advantage is that using
this method you can easily adapt your code to match any criteria with
just a few simple changes. Custom code may need major additions and
restructuring.

Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

In summary while this can be easily done in fully portable C (provided
the list of file names is somehow gathered, since ISO C has no support
for reading directories), a more robust solution would be to use a
pattern matching library. If you are on a POSIX system investigate
regex.h and glob.h.

Jul 31 '08 #2
On Jul 31, 6:10*am, santosh <santosh....@gm ail.comwrote:
aki wrote:
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 :
OMCID_NETYPE_NE NAME_NAMEOFTHEA PPLIEDFILE_APPL YDATE_trans.csv
For example :
4_TC_TC_48_NoST Configuration_1 971-1-1_trans.csv
where
*OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIE DFILE=NoSTConfi guration
APPLYDATE=1971-1-1
i have to perform delete operation on the file with matching *three
fields .
OMCID , NETYPE, NENAME (All three known )
Could somebody try to answer the problem . or tel how to proceed

Firstly C doesn't have *any* support for directories, so you may want to
ask in a group for your system like comp.unix.progr ammer.

Secondly, once you get a list of all the files in your directory, you
need to match the OMCID, NETYPE, and NENAME fields of these names with
your criteria. If you don't want to write code to do this, you can use
a regular expression library, which is not a part of Standard C but is
nevertheless included with most major implementations . This will
relieve you of the tedium of writing the string comparison code and the
possibilities of bugs, testing, etc. A further advantage is that using
this method you can easily adapt your code to match any criteria with
just a few simple changes. Custom code may need major additions and
restructuring.

Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

In summary while this can be easily done in fully portable C (provided
the list of file names is somehow gathered, since ISO C has no support
for reading directories), a more robust solution would be to use a
pattern matching library. If you are on a POSIX system investigate
regex.h and glob.h.
Adding to what Santosh told:
If you are on a Linux box and use are using Libc4 or Libc5, you can
use functions scandir() and alphasort()
to obtain directory listing. you need to look for header files
dirent.h

I am not sure about its portability to other systems :(

For more information,

http://www.gnu.org/software/libtool/...ectory-Content
Jul 31 '08 #3
Ajay wrote:
On Jul 31, 6:10*am, santosh <santosh....@gm ail.comwrote:
>aki wrote:
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 :
OMCID_NETYPE_NE NAME_NAMEOFTHEA PPLIEDFILE_APPL YDATE_trans.csv
For example :
4_TC_TC_48_NoST Configuration_1 971-1-1_trans.csv
where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIE DFILE=NoSTConfi guration
APPLYDATE=1971-1-1
i have to perform delete operation on the file with matching *three
fields .
OMCID , NETYPE, NENAME (All three known )
Could somebody try to answer the problem . or tel how to proceed
[ ... ]
Adding to what Santosh told:
If you are on a Linux box and use are using Libc4 or Libc5, you can
use functions scandir() and alphasort()
to obtain directory listing. you need to look for header files
dirent.h

I am not sure about its portability to other systems :(
They are not very portable at all. They are also deprecated by at least
one standard. A more portable solution is to use
opendir/readdir/closedir along with the facilities defined in regex.h.
All of these are standardised by POSIX and hence fairly portable.

For further discussions of these functions the OP should consider
posting on comp.unix.progr ammer, where there is a higher likelyhood of
receiving better, more accurate, peer reviewed answers, as there are
far more active Unix/POSIX experts there than here.

<snip>

Jul 31 '08 #4
santosh <sa*********@gm ail.comwrites:
[...]
Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.
[...]

The remove() function is standard in ISO C.

<OT>No, Unix 'rm' doesn't have built-in support for file globbing and
pattern matching; that's handled by the shell.</OT>

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 2 '08 #5
On 2 Aug 2008 at 23:32, Keith Thompson wrote:
santosh <sa*********@gm ail.comwrites:
>Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

No, Unix 'rm' doesn't have built-in support for file globbing and
pattern matching; that's handled by the shell.
But system() goes via /bin/sh, so the effect is the same.

If the user is using fork()/exec() directly, then again he can use
/bin/sh -c to execute rm and get globbing.

Aug 3 '08 #6
Antoninus Twink <no****@nospam. invalidwrites:
On 2 Aug 2008 at 23:32, Keith Thompson wrote:
>santosh <sa*********@gm ail.comwrites:
>>Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

No, Unix 'rm' doesn't have built-in support for file globbing and
pattern matching; that's handled by the shell.
[snip information more appropriate for a Unix group]

I don't normally respond to AT, but in this case he has quoted me in a
deliberately misleading manner. I had surrounded my remarks about the
'rm' command with "<OT>" and "</OT"tags. AT deleted those tags,
giving the false impression that I care as little about topicality as
he does.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 3 '08 #7
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>Antoninus Twink <no****@nospam. invalidwrites:
>On 2 Aug 2008 at 23:32, Keith Thompson wrote:
>>santosh <sa*********@gm ail.comwrites:
Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

No, Unix 'rm' doesn't have built-in support for file globbing and
pattern matching; that's handled by the shell.
[snip information more appropriate for a Unix group]

I don't normally respond to AT, but in this case he has quoted me in a
deliberately misleading manner. I had surrounded my remarks about the
'rm' command with "<OT>" and "</OT"tags. AT deleted those tags,
giving the false impression that I care as little about topicality as
he does.
God almighty, we couldn't have that, now could we?

Geez, what small lives you people live.

Aug 4 '08 #8
In article <sl************ *******@nospam. invalid>,
Antoninus Twink <no****@nospam. invalidwrote:
>On 2 Aug 2008 at 23:32, Keith Thompson wrote:
>santosh <sa*********@gm ail.comwrites:
>>Another possibility, if your program will be restricted to suitable
systems, is to use the system's delete file command. The Unix command
for this, 'rm' has built-in support for file globbing and pattern
matching. For further details ask in a group for your system.

No, Unix 'rm' doesn't have built-in support for file globbing and
pattern matching; that's handled by the shell.

But system() goes via /bin/sh, so the effect is the same.

If the user is using fork()/exec() directly, then again he can use
/bin/sh -c to execute rm and get globbing.
Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

As far as the standard is concerned, system() could go via /keith/is/god.

Aug 4 '08 #9

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

Similar topics

7
1610
by: Tony | last post by:
Hi there, Is there any event you can catch that would you allow to cancel the deletion of a file or directory. The FileSystemEventHandler allows you to catch file operations after they have occurred but I need to be able to catch it before it occurs. Does anyone know a way of doing this? Thanks,
5
1113
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up until the CDO.DropDirectory.GetMessages() method is called. At this point, the files are locked until I shut down the service. After processing and delivery, I need to be able to delete all the files in the drop directory. I can delete them via...
3
1626
by: jaws | last post by:
My problems is as follows. Hope you guys can provide some insight. 1. I have a class which opens a file and simply spits out the text. Methods in place to open, print, close, and delete the file. 2. This class is instantiated as a thread, I have several acting on different files. 3. The application is web based. The user can kill the app. from the browser, effectively leaving my temp files undeleted because the app can
3
1675
by: A_Republican | last post by:
I am interested in writing my own secure file deletion program. I want to be able to read and write to my hard drive directly. My application will seach my hard drive for all locations marked for deletion and then replace it with "x" or something that securely removes previoius data. My question is what objects, API calls, etc, etc do I use to read and write directly to the hard drive? -- Regards, Shaun Goldston
9
2231
by: Claudio Grondi | last post by:
I am aware, that it is maybe the wrong group to ask this question, but as I would like to know the history of past file operations from within a Python script I see a chance, that someone in this group was into it already and is so kind to share here his experience. I have put already much efforts into this subject googling around, but up to now in vain. Best option I encountered yet is usage of the Greyware 'System Change Log' service...
13
4176
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them from the html page (replace the words in the html page with blank space) I'm new to python and could use a little push in the right direction, any ideas on how to implement this? Thanks!
11
5786
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This method is to be inherited by all listing classes to allow for * list-wide deletion of latent server-created ZIP files for security purposes *
8
215
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 : OMCID_NETYPE_NENAME_NAMEOFTHEAPPLIEDFILE_APPLYDATE_trans.csv For example :
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.