Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This is a little helper named ncopy. It copies files from one place to another.

Syntax:
ncopy <files(s)> <target>
<files(s)> is just a filename (wildcards possible) and <target> is an expression for the target of the copy operation. So far there is nothing new. Here comes the interesting part:

In the target expression you can use the following to refer to parts of the source path and name:
*0 first directory after root *1 second directory after root ... *-1 first directory above sourcefile *-2 second directory above sourcefile ... *n name of the sourcefile *s0 first suffix of the sourcefile *s1 second suffix oft the sourcefile
So given the files a.txt and b.txt in c:\temp\foo\bar" and calling the script:
C:\temp\foo\bar>ncopy.pl *.txt .\*1\*n\*-1\t.*s0 mkpath C:\temp\foo\bar\foo\a\bar a.txt -> C:\temp\foo\bar\foo\a\bar\t.txt mkpath C:\temp\foo\bar\foo\b\bar b.txt -> C:\temp\foo\bar\foo\b\bar\t.txt
As you can see you can easily transform file names while copying.

It's only tested under Windows, but should be cross platform.


holli, /regexed monk/

In reply to Re: Private Utilities by holli
in thread Private Utilities by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-24 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found