Hatena::Groupperl

perl初心者

2008-12-31

指定したディレクトリの特定の名前のファイルを削除する

15:30

指定したディレクトリの特定の名前のファイルを削除するスクリプトを作ってみました。

削除するファイル名は「***(1).mp3」のようなmp3ファイルで、( )内の数字は1桁の数値が入っています。

#! /bin/perl -w
use strict;

my $dirname = 'C:\Documents and Settings\work';
opendir(DIR, $dirname) or die "$dirname: $!";
while (my $dir = readdir(DIR)) {
	next unless ($dir =~ /\(\d\)\.mp3$/);
	my $filename = $dirname.'\\'.$dir;
	print '削除ファイル ===== ', "$filename\n";
	unlink($filename);
	}
closedir(DIR);

opendirでディレクトリをディレクトリハンドル"DIR"に関連付けて、readdirで読み込みます。

正規表現のパターンマッチでファイルを選別して、削除しています。

  

readdirで読み込むのがディレクトリエントリというのが理解できなくて、unlink($dir);として、動作しなくて少し悩みました。unlink($dir);だとカレントディレクトリの$dirというファイルが削除されるんですね。

my $filename = $dirname.'\\'.$dir;のようにして、きちんとファイルを指定する必要がありました。

  

はてなスターありがとうございます。Uchimataさん。

EnvippinoEnvippino2017/05/27 22:51It will be easier for you if they are going to explain the details about the item you are about to purchase. What can you do?"Benefits of Using Managed HostingBenefits of Using Managed HostingJune 7, 2012 Author: Dhruv Patel Posted in MarketingOnline businesses are easy to manage only when it is small. <a href=http://www.cheapchinanfljerseyswholesale.us.com/>Wholesale NFL Jerseys</a>.<a href=http://www.cheapchinanfljerseyswholesale.us.com/>Wholesale Jerseys From China</a>. Men and women can be in a position to seem stylish with this choice. Good Luck. There are also many other similar products and services offered over in The information you collect will help you know which ones offer ideal costs and payment choices.<a href=http://www.cheapchinanfljerseyswholesale.us.com/>Cheap NFL Jerseys</a>."I would give big money, but not for long years," Hamels said during a May conversation about the frailty of pitchers. You can rest assure on their quality of merchandise and services. With dedicated server, you do not have any loop holes in the internet security. The military will tell you to take the test but will not let you know what the test is about. Rigel continually updates themselves to be sure they can to give their customer the best and most up to date products. There are also others who are very comfortable with it.
Visit my site锟斤拷http://www.cheapchinanfljerseyswholesale.us.com/

EnvippinoEnvippino2017/06/15 01:42Number of View :118Many organizations do have a Human Resource team to assist them with the hiring of brand new staff to help grow and improve the crew. It just makes sense because most clubs have numerous activities which can be dangerous and can involve accidents and mishaps.Ultimately health is something we do to ourselves, <a href=http://www.cheapnfljerseyssportsshop.com/>Cheap Jerseys</a>, not something others do to us.Jamie Carragher, Graeme Souness and Jamie Redknapp have all been critical in their roles for Sky, though, when pressed, Rodgers would only say: “I am talking about people outside of here. Crank out confident that yourself reach your software program very carefully and pin issue the parts, which yourself do not desire. There are many people, that like to buy one of these brilliant items,<a href=http://www.cheapnfljerseyssportsshop.com/>Cheap NFL Jerseys Wholesale</a>, however they do not check with experts plus they do not read about the models on the web. once the height is as thick as the pad of yourforefinger, the height is proper. Otherwise, you could pull a muscle and be out of commission for a while. Some allow multiple links from the resource box; others only allow a couple of. That's when I thought I'd rather say something and hopefully catch this thing before I make the same mistake I made a couple of years ago, when I tried to play through it and made it worse. Your self must be guaranteed that by yourself are seeking into the info that an representative features your self with regards toward the agreement that your self are having into.<a href=http://www.cheapnfljerseyssportsshop.com/>Cheap NFL Jerseys China Wholesale</a>.Most people know the frustration and feeling of helplessness one experiences when one is in a hurry and suddenly forced to a crawling pace or standstill when the road is blocked due to an accident or construction work.
Visit my site:http://www.cheapnfljerseyssportsshop.com/

EnvippinoEnvippino2017/06/17 14:57The user can also have the chance to format the text, italics as well as the colors of such files. Just about all tattoo artists are aware of the great need of a great tattoo machine and every time demands good quality tattoo machines for superb work.You can stay on top of fashion by being unique.When you would be selecting the Bharatanatyam Los Angeles class, there would be many options that would be available. It is not going to be use ledgers that can add to the mess in your office. Accessories for your hair include scrunchies in a myriad of colors and fabrics, headbands, elegant barrettes, and even clip-on hair extensions. <a href=http://www.cheapnfloutletjerseys.us.com/>Cheap Jerseys</a>.Just have things throughout the dwelling that displays them you are the very best. Hit flat and decisively to the point if desired. Most of the breast pumps introduced to the market in the last year or so also have a space on them so that you can actually place your babies picture right in front of you too. Mordred, with a white face and hisarm in a sling, was leaning at the embrasure of one of the windows, looking out.<a href=http://www.cheapnfloutletjerseys.us.com/>Cheap NFL Jerseys</a>.<a href=http://www.cheapnfloutletjerseys.us.com/>Wholesale Jerseys</a>.
Visit my site锟斤拷http://www.cheapnfloutletjerseys.us.com/

EnvippinoEnvippino2017/06/20 15:16org today. When you feel like going casual, grab a ponytail holder and wear your hair back. Starting with your fingertips make slow circular movements towards your nipple finishing off with some larger movements and complete hand movements down the chest. These innocent pets depend on their owners to ensure they lead the best life possible. <a href=http://www.cheapnfljerseyschina-wholesale.us.com/>Wholesale Jerseys Free Shipping</a>.<a href=http://www.cheapnfljerseyschina-wholesale.us.com/>Cheap NFL Jerseys Outlet</a>. These days,<a href=http://www.cheapnfljerseyschina-wholesale.us.com/>Wholesale Nike NFL Jerseys</a>, people can make tattoos with the help of a tattoo kit as well as other products for tattoo artists are available in the marketplace. You can even approach some instructors so that they can give you an advice about the best course that will be right for you.If you're the ideal in grades, use a chart up within the review room. Plug ins and add ons can also be added for your system to work better. Truly people obtain confused regarding which tattoo supplies is the best as well as which tattoo machines kit to start with is easily the most appropriate for all of them. There are special diets designed specifically for aging dogs to guard against joint problems.
Visit my site锟斤拷http://www.cheapnfljerseyschina-wholesale.us.com/

EnvippinoEnvippino2017/06/21 17:47Young has one year and $16 million left on his contract.65 ERA in 31 appearances. It puts them in a better position regarding taking preventative steps.This is an ancient style in dancing for some Indians that may be known up to their moment. Accessories and shoes are also important components of good style. Wear your hair a little messy, <a href=http://www.cheapnfloutletjerseys.us.com/>Wholesale NFL Jerseys</a>, unbutton your shirt, or wear shoes that don’t perfectly match your outfit. Try the relaxation techniques and breathing exerciThings to consider before buying a tattoo kitHarpold Yoshimura   Submitted 2014-01-01 09:02:29 Prior you get a tattoo done you require to think about all the essential elements that could influence your whole curiosity about a selection of the tattoo design.How To Select The Best Bharatanatyam ClassHow To Select The Best Bharatanatyam ClassNovember 16,<a href=http://www.cheapnfloutletjerseys.us.com/>Cheap Jerseys From China</a>, 2013 Author: Alyce Powell Posted in EducationBharatanatyam Los Angeles has been a very popular Indian dance that belongs to the Southern part of the state.<a href=http://www.cheapnfloutletjerseys.us.com/>Wholesale Jerseys From China</a>. Plug ins and add ons can also be added for your system to work better.”“But this is monstrous!” he exploded.
Visit my sitehttp://www.cheapnfloutletjerseys.us.com/