473,503 Members | 1,360 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_NENAME_NAMEOFTHEAPPLIEDFILE_APPLYDATE _trans.csv
For example :

4_TC_TC_48_NoSTConfiguration_1971-1-1_trans.csv

where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIEDFILE=NoSTConfiguration
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 2259
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_NENAME_NAMEOFTHEAPPLIEDFILE_APPLYDATE _trans.csv
For example :

4_TC_TC_48_NoSTConfiguration_1971-1-1_trans.csv

where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIEDFILE=NoSTConfiguration
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.programmer.

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....@gmail.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_NENAME_NAMEOFTHEAPPLIEDFILE_APPLYDATE _trans.csv
For example :
4_TC_TC_48_NoSTConfiguration_1971-1-1_trans.csv
where
*OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIEDFILE=NoSTConfiguration
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.programmer.

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....@gmail.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_NENAME_NAMEOFTHEAPPLIEDFILE_APPLYDATE _trans.csv
For example :
4_TC_TC_48_NoSTConfiguration_1971-1-1_trans.csv
where
OMCID =4
NETYPE= TC
NENAME= TC_48
NAMEOFTHEAPPLIEDFILE=NoSTConfiguration
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.programmer, 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*********@gmail.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_Keith) 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*********@gmail.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*********@gmail.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_Keith) 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.org>,
Keith Thompson <ks***@mib.orgwrote:
>Antoninus Twink <no****@nospam.invalidwrites:
>On 2 Aug 2008 at 23:32, Keith Thompson wrote:
>>santosh <sa*********@gmail.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*********@gmail.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
1587
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...
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...
3
1616
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...
3
1669
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...
9
2228
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...
13
4163
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...
11
5755
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...
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 : ...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
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,...
0
7339
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...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5017
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...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.