Sponsored Content
Full Discussion: File extensions in a dir
Top Forums Shell Programming and Scripting File extensions in a dir Post 302369078 by ganga.dharan on Friday 6th of November 2009 11:31:00 AM
Old 11-06-2009
thanks danmero and scrutinizer,, ur soln works great..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File name extensions

Hello people, I was wondering if anyone could help me? I want to produce a shell script that changes the filename extension on all matching file. E.G. change all files called ‘something.rtf' to ‘something.doc' by giving the command: Changex rtf doc *where ‘Changex' is the name of... (2 Replies)
Discussion started by: thurrock
2 Replies

2. Shell Programming and Scripting

copying a file from one dir to another dir

hi i have a script compareFiles() { find /tmp/Satya -type f | \ while read filename1 do echo "----------------------------------------$filename1" find /tmp/Satya -type f | \ while read filename2 do if diff $filename1 $filename2 then echo "Both files... (3 Replies)
Discussion started by: Satyak
3 Replies

3. Shell Programming and Scripting

Moving file(s) from dir to dir

Hi, I am fairly new to writing scripts. I am trying to write a script that moves either One or All of the files from one directory to another. I know how to make the actual command to do it, but i don't quite know how to add operators to it, ie -i or -a. I want -i to move one file from... (4 Replies)
Discussion started by: SirJoeh
4 Replies

4. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

Checking file extensions

I am trying to store file with certain file extensions to list but having some problems. Here is a part of the code set fryLst = "" set fxtLst = "" foreach f ($AfullNameLst) set fname = $f:r set fext = $f:e if ("$fext" == ".ry") set fryLst = "$fryLst $f" if ("$fext" == ".xt")... (2 Replies)
Discussion started by: kristinu
2 Replies

7. Shell Programming and Scripting

Checking file extensions

I'm in csh and have a list of file names, example set Lst = "file1.ry file2.ry file3.ry file4.ry" I want to check if all the extensions are ry. Is they are, I want to do something. (1 Reply)
Discussion started by: kristinu
1 Replies

8. UNIX for Dummies Questions & Answers

HELP, Need to capitalize all files in dir without capitalizing extensions

Hello everyone, I may sound stupid for asking this but I have files that need to be loaded onto every system at work. When loaded the files are for example.... 5peasw.sim the end result needs to be 5PEASW.sim this is for over 50 files in the directory they go to. I am trying to... (5 Replies)
Discussion started by: E404UserNotFoun
5 Replies

9. Shell Programming and Scripting

Create file Dir and Sub Dir same time

Hi Guys , I want create files Dire and Sub Dire. as same time using variable. EX: x1="/hk/Pt/put/NC/R1.txt" x2="/hk/pt/Put/Ot/NC/RN.txt" And i want delete all after done with my script. Thanks (2 Replies)
Discussion started by: pareshkp
2 Replies

10. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies
Template::Plugin::Directory(3)				User Contributed Perl Documentation			    Template::Plugin::Directory(3)

NAME
Template::Plugin::Directory - Plugin for generating directory listings SYNOPSIS
[% USE dir = Directory(dirpath) %] # files returns list of regular files [% FOREACH file = dir.files %] [% file.name %] [% file.path %] ... [% END %] # dirs returns list of sub-directories [% FOREACH subdir = dir.dirs %] [% subdir.name %] [% subdir.path %] ... [% END %] # list returns both interleaved in order [% FOREACH item = dir.list %] [% IF item.isdir %] Directory: [% item.name %] [% ELSE %] File: [% item.name %] [% END %] [% END %] # define a VIEW to display dirs/files [% VIEW myview %] [% BLOCK file %] File: [% item.name %] [% END %] [% BLOCK directory %] Directory: [% item.name %] [% item.content(myview) | indent -%] [% END %] [% END %] # display directory content using view [% myview.print(dir) %] DESCRIPTION
This Template Toolkit plugin provides a simple interface to directory listings. It is derived from the Template::Plugin::File module and uses Template::Plugin::File object instances to represent files within a directory. Sub-directories within a directory are represented by further "Template::Plugin::Directory" instances. The constructor expects a directory name as an argument. [% USE dir = Directory('/tmp') %] It then provides access to the files and sub-directories contained within the directory. # regular files (not directories) [% FOREACH file IN dir.files %] [% file.name %] [% END %] # directories only [% FOREACH file IN dir.dirs %] [% file.name %] [% END %] # files and/or directories [% FOREACH file IN dir.list %] [% file.name %] ([% file.isdir ? 'directory' : 'file' %]) [% END %] The plugin constructor will throw a "Directory" error if the specified path does not exist, is not a directory or fails to "stat()" (see Template::Plugin::File). Otherwise, it will scan the directory and create lists named '"files"' containing files, '"dirs"' containing directories and '"list"' containing both files and directories combined. The "nostat" option can be set to disable all file/directory checks and directory scanning. Each file in the directory will be represented by a Template::Plugin::File object instance, and each directory by another "Template::Plugin::Directory". If the "recurse" flag is set, then those directories will contain further nested entries, and so on. With the "recurse" flag unset, as it is by default, then each is just a place marker for the directory and does not contain any further content unless its "scan()" method is explicitly called. The "isdir" flag can be tested against files and/or directories, returning true if the item is a directory or false if it is a regular file. [% FOREACH file = dir.list %] [% IF file.isdir %] * Directory: [% file.name %] [% ELSE %] * File: [% file.name %] [% END %] [% END %] This example shows how you might walk down a directory tree, displaying content as you go. With the recurse flag disabled, as is the default, we need to explicitly call the "scan()" method on each directory, to force it to lookup files and further sub-directories contained within. [% USE dir = Directory(dirpath) %] * [% dir.path %] [% INCLUDE showdir %] [% BLOCK showdir -%] [% FOREACH file = dir.list -%] [% IF file.isdir -%] * [% file.name %] [% file.scan -%] [% INCLUDE showdir dir=file FILTER indent(4) -%] [% ELSE -%] - [% f.name %] [% END -%] [% END -%] [% END %] This example is adapted (with some re-formatting for clarity) from a test in t/directry.t which produces the following output: * test/dir - file1 - file2 * sub_one - bar - foo * sub_two - waz.html - wiz.html - xyzfile The "recurse" flag can be set (disabled by default) to cause the constructor to automatically recurse down into all sub-directories, creating a new "Template::Plugin::Directory" object for each one and filling it with any further content. In this case there is no need to explicitly call the "scan()" method. [% USE dir = Directory(dirpath, recurse=1) %] ... [% IF file.isdir -%] * [% file.name %] [% INCLUDE showdir dir=file FILTER indent(4) -%] [% ELSE -%] ... The directory plugin also provides support for views. A view can be defined as a "VIEW ... END" block and should contain "BLOCK" definitions for files ('"file"') and directories ('"directory"'). [% VIEW myview %] [% BLOCK file %] - [% item.name %] [% END %] [% BLOCK directory %] * [% item.name %] [% item.content(myview) FILTER indent %] [% END %] [% END %] The view "print()" method can then be called, passing the "Directory" object as an argument. [% USE dir = Directory(dirpath, recurse=1) %] [% myview.print(dir) %] When a directory is presented to a view, either as "[% myview.print(dir) %]" or "[% dir.present(view) %]", then the "directory" "BLOCK" within the "myview" "VIEW" is processed. The "item" variable will be set to alias the "Directory" object. [% BLOCK directory %] * [% item.name %] [% item.content(myview) FILTER indent %] [% END %] In this example, the directory name is first printed and the content(view) method is then called to present each item within the directory to the view. Further directories will be mapped to the "directory" block, and files will be mapped to the "file" block. With the recurse option disabled, as it is by default, the "directory" block should explicitly call a "scan()" on each directory. [% VIEW myview %] [% BLOCK file %] - [% item.name %] [% END %] [% BLOCK directory %] * [% item.name %] [% item.scan %] [% item.content(myview) FILTER indent %] [% END %] [% END %] [% USE dir = Directory(dirpath) %] [% myview.print(dir) %] AUTHORS
Michael Stevens wrote the original Directory plugin on which this is based. Andy Wardley split it into separate File and Directory plugins, added some extra code and documentation for "VIEW" support, and made a few other minor tweaks. COPYRIGHT
Copyright (C) 2000-2007 Michael Stevens, Andy Wardley. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template::Plugin, Template::Plugin::File, Template::View perl v5.16.3 2011-12-20 Template::Plugin::Directory(3)
All times are GMT -4. The time now is 05:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy