LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2007, 06:52 PM   #1
sportivo888
LQ Newbie
 
Registered: Dec 2007
Posts: 15

Rep: Reputation: 0
Smile Help create perl script for delete file/folder


Hi Everyone,
i have not yet found any post for runing a script to delete file or folder.

o/s red hat

can anyone help me out with this.

Thank in advances

Steven
 
Old 12-05-2007, 07:02 PM   #2
Slokunshialgo
Member
 
Registered: Jan 2006
Distribution: Ubuntu 9.04, Fedora 10
Posts: 76

Rep: Reputation: 17
Do you want the folder pre-set, passed in through command line, or...?

Because the only way that pops to mind would basically be running a shell command from inside the script, which would make the script itself useless.
 
Old 12-05-2007, 07:16 PM   #3
sportivo888
LQ Newbie
 
Registered: Dec 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Slokunshialgo View Post
Do you want the folder pre-set, passed in through command line, or...?

Because the only way that pops to mind would basically be running a shell command from inside the script, which would make the script itself useless.

yes folder to be preset and run frmo the command.

do you have an example of delete script?
 
Old 12-05-2007, 07:38 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
in perl?
Code:
perldoc -f rmdir
perldoc -f unlink

Last edited by ghostdog74; 12-05-2007 at 07:40 PM.
 
Old 12-05-2007, 08:36 PM   #5
sportivo888
LQ Newbie
 
Registered: Dec 2007
Posts: 15

Original Poster
Rep: Reputation: 0
#!/usr/bin/perl.exe

$delete = "untitled folder"; #folder named (untitled folder) to be delete in the same directory

opendir (DIR,".");
@files = grep(/$delete/, readdir (DIR));
closedir (DIR);

foreach $file (@files)
{
rmdir $file;
}



finally i have solve my problem,
i don't know why that (unlink) won't work.
but rmdir can do the job

Thank you for help ghostdog74 & slokunshialgo
very appreciate

Steven

Last edited by sportivo888; 12-05-2007 at 09:50 PM.
 
Old 12-05-2007, 11:33 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
This explains unlink: http://perldoc.perl.org/functions/unlink.html.
Also, what's with perl.exe? That an MS thing. In Unix it's (normally) just perl (no extension).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A script within a folder to delete the folder, script, and the folder's contents Cyberman Programming 15 10-17-2007 07:32 AM
create a folder/file within a folder using perl indu.a Programming 2 03-07-2007 10:09 PM
perl script help required to create users and changing the owner to pericular folder sridhar11 Programming 2 10-25-2005 02:16 PM
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 06:02 PM
perl script to create a backwards file?! WorldBuilder Programming 16 10-30-2003 10:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration