LinuxQuestions.org
Help answer threads with 0 replies.
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, 07: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, 08: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, 08: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, 08: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 08:40 PM.
 
Old 12-05-2007, 09: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 10:50 PM.
 
Old 12-06-2007, 12:33 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:32 AM
create a folder/file within a folder using perl indu.a Programming 2 03-07-2007 11:09 PM
perl script help required to create users and changing the owner to pericular folder sridhar11 Programming 2 10-25-2005 03:16 PM
starting script, init by copy/create file in (samba) folder? muab Linux - General 7 06-22-2005 07:02 PM
perl script to create a backwards file?! WorldBuilder Programming 16 10-30-2003 11:05 PM


All times are GMT -5. The time now is 12:23 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration