Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Processing files in a directory

0 views
Skip to first unread message

Susheel Koushik

unread,
Nov 10, 2008, 6:39:44 PM11/10/08
to saty...@gmail.com, beginn...@perl.org
use the PERL system command. Its a wrapper for system call on your host OS.

ex: system("rm *.tmp");

susheel

On Mon, Nov 10, 2008 at 3:32 AM, saty...@gmail.com <saty...@gmail.com>wrote:

> Hi Everyone,
>
> I have around 2000 files in a directory. During processing of these
> files, a temp* will be created for each file and its removed after
> processing that file. If the processing is unsuccessful, temp* file
> still exists. Can u plz help me to write a script to automate this
> process using Perl ie., when a temp* file is found (which stays for
> abt 10 secs max), I hv to move that temp* file to some other folder.
>
> Thanks in advance,
> Satish
>
>
> --
> To unsubscribe, e-mail: beginners-cg...@perl.org
> For additional commands, e-mail: beginners...@perl.org
> http://learn.perl.org/
>
>
>


--
Susheel Koushik M
Graduate Student
Ira A Fulton School of Engineering
Arizona State University

Susheel Koushik

unread,
Nov 11, 2008, 4:17:13 PM11/11/08
to John W. Krahn, beginn...@perl.org
of course, there are many ways to do a job in perl. Its upto the implementer
to choose.

-Susheel

On Mon, Nov 10, 2008 at 10:40 PM, John W. Krahn <kra...@telus.net> wrote:

> Susheel Koushik wrote:
>
>> use the PERL system command. Its a wrapper for system call on your host
>> OS.
>>
>> ex: system("rm *.tmp");
>>
>

> Why, when you can just do:
>
> unlink <*.tmp>;
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall

Susheel Koushik

unread,
Nov 11, 2008, 4:16:04 PM11/11/08
to satish km, beginn...@perl.org
Doing what you propose is possible, but would take system resources and a
bit tedious.

Here's an alternate solution:

From what I infer, you are processing on a file and then the code decides if
its a success or a failure and your job is to remove tmp files if it fails.
Here, when the processing code is done with its job, ask it to return an
exit status (say return1 for success and 0 for failure). Then based on this
return status, you can do your job.

If itsn't clear, get back

-susheel

On Tue, Nov 11, 2008 at 6:18 AM, satish km <saty...@gmail.com> wrote:

> Hi,
>
> My requirement is like this:
>
> 1. There are 1000 files in a directory(DIR1)
> 2. When processing is started, ex file1 wil be converted to temp_file1,
> then processed and both file1 + temp_file1 are removed from DIR1 within 2-3
> seconds.
>
> if any temp_file* (ex: temp_file6) is still present in DIR1 means
> processing failed.
>
> So I need to periodically check in if any temp_file* generated is staying
> for more than 30 seconds (which means processing failed), then I hv to move
> this temp_file* to some other folder and restart processing again of the
> remaining files.
>
> I am trying to achieve this using perl. Can u plz let me know how to
> achieve this.
>
> Thanks,
> Satish


>
>
> On Tue, Nov 11, 2008 at 5:11 AM, Susheel Koushik <sush...@gmail.com>wrote:
>
>> use the PERL system command. Its a wrapper for system call on your host
>> OS.
>>

>> ex: system("mv $filename $new_location/$filename");
>>
>> susheel

0 new messages