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/

RichardawameRichardawame2017/10/07 06:09These items turn out to be particularly essential for those who go through any tough patches.Be sure to include an easily-completed unsubscribe link in all of your marketing emails. These real estate buildings are occupied by automobile showrooms as well as theme eateries. <a href=http://www.wholesalejerseyscheaper.com/>Wholesale Jerseys Cheap</a>.Power and magnification are both indispensable, and they should be borne in mind before purchasing a rifle.linkedin.When you are intending on travelling in the coming several weeks,<a href=http://www.wholesalejerseyscheaper.com/>Wholesale NFL Jerseys Online</a>, ensure that your vision out for advertising offers on the web by means of various discounted journey internet sites.Search For Free Indiana Criminal Records OnlineSearch For Free Indiana Criminal Records OnlineAugust 25, 2013 | Author: Christopher Evans | Posted in BusinessRecords of arrest in Indiana are opened and can be easily accessed by the local residents of the state. CONTIN?A EN " HOSPITALIZACION DOCMICILIARIA ", INCAPAZ DE VALERSE POR SI MISMA.<a href=http://www.wholesalejerseyscheaper.com/>Wholesale Jerseys Online</a>. Try to click on "Amend" found close to "Tongue" to display the language drop-down menu.com. Usted dice que mi esposa se movi?, de la misma manera en que dijo que en ocho d?as super?a el grave problema que se le caus?. Others, keen to provide their entrepreneurial skills, go crazy about the leadership front.
Visit my site:http://www.wholesalejerseyscheaper.com/

DavidGressDavidGress2017/10/11 18:50Considering the plenty of online shops present today, an individual should be vigilant regarding what store or dealer they is enrolling to. It brings down the quality of your latest news information site and you can get fined by the search engine crawlers because it will be a repetition of content. In fact, <a href=http://www.cheapnfljerseyschinawholesaler.com/>Cheap Authentic NFL Jerseys</a>, the Red Stockings were still practically covered from waist to ankle with knee pants and red socks, which offered better protection than the Sox's skimpy shorts.aitheinhealing. Taking into concerns this truth, buying products online can be of no difficulty. * Keep the top of the battery clean. One could easily try to find their required things in just few seconds.<a href=http://www.cheapnfljerseyschinawholesaler.com/>Cheap Jerseys From China</a>. If this happens, you will require a brand-new car battery replacement to get your vehicle running again.As hydroponic farming is turning out to be more popular, the selling of hydroponic kits has happen to be a thriving business. You consequently do not want those embarrassing moments whenever your friends are existing.<a href=http://www.cheapnfljerseyschinawholesaler.com/>Cheap Vintage Jerseys Sale</a>. You cannot be sure until you get people to come and check the entire premises for the presence of such a chemical. I recommend that you watch the video to gain a better understanding of Lead Generation.
Visit my site:http://www.cheapnfljerseyschinawholesaler.com/

RichardawameRichardawame2017/10/12 14:41Cisco as of late reported that by 2017, 80 percent of all Internet activity will be feature sees. Most lease businesses usually allow about 45, 000 on free usage limits for any duration of three years. Consider the office example discussed earlier: even in two offices with the same hardwood furnishings, both designed for intellectual contemplation, the office with two lamps and reflective finishes on the hardwood will probably seem lighter and larger than an office which relies solely upon a single overhead light for illumination.) Look for a great and trustworthy online store.Someday your midwifery services business might become such a success that you might consider selling it. For example, <a href=http://www.wholesalejerseyscheapnfl.us.com/>Wholesale NFL Jerseys</a>, you can use two different forms of the same sales page and see which one converts more often. But when it comes to PPC, a tip that can prove to be golden for many online marketers is to take it one step at a time.Entertainment optionsHow will you entertain your guests? If the venue has a dance floor, then you can hire a DJ and that pretty much solves the entertainment aspect. You can possibly get a hold of the services workout psychologist and up a scheduled appointment with ease. Here are things you should do to find the right people this time.<a href=http://www.wholesalejerseyscheapnfl.us.com/>Wholesale NFL Jerseys Online</a>. Regardless of the truth which the ideologies directing modern styles are similar even in the dining space furnishings, person requirements is often captured inside the customized sorts of the dining space furniture.<a href=http://www.wholesalejerseyscheapnfl.us.com/>Wholesale NHL Jerseys China</a>. Online networking is additionally a key instrument for making new client associations that can blossom into future business.
Visit my site:http://www.wholesalejerseyscheapnfl.us.com/