Adding a prefix to a file name if the prefix is not already there

I have a script that adds a prefix to a file name then moves the file from its source directory to a destination directory. The problem I am encountering is that if the destination directory is unavailable for any reason the file fails to move &
so remains in the source directory and then the next time the script runs the prefix gets added again so I sometimes end up with files that look like this:
"Prefix_Prefix_Prefix_Prefix_Prefix_Prefix_1234_20141020_9786_8404.tif"
I need to build in some kind of logic that prevents this from happening so that if the Prefix_ is there it doesn't add it again, but not I'm not sure what the best way to do this is.  Here is the code that adds the prefix.
Get-ChildItem $Source\* -include *.jpg,*.tif,*.pdf -exclude *.log | % {Rename-item $_.Fullname ("Prefix_" + $_.Name)}
# When I wrote this script only God and I knew what I was doing. # Now, only God Knows!

Another option, but I like Bill's better:
$prefix = 'prefix'
Get-ChildItem | ForEach {
If ($_.Name -notlike "$prefix*") {
Rename-Item -Path $_.FullName -NewName "$($prefix)_$($_.Name)"
Don't retire TechNet! -
(Don't give up yet - 13,085+ strong and growing)

Similar Messages

  • Add file name to the element in target message

    Hi all!
    I try to configure scenario:
    Get all files from directory (it will not be the same number of file every time) and mapping this file to the ERP system. I use File adapter to do this. But what Is necessary I need to mapp the file name to the element in target message.
    I mean: When I have got the RFC structure imprted from ERP and there I have got the element "filename". I would like to put the file name of file which I mapping to this element. Next put the all file contents with file name to the ERP table.
    It is possible to do that??
    I found in sap help that I can keep file name in the message header to get the same target file name, but I wont to put file contents (with file name) to the ERP table not to another file.
    THX for all your opinions.

    The DynamicConfiguration fin inbound message:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Inbound Message
      -->
    - <SAP:DynamicConfiguration xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="Directory">/usr/sap/PXD/put/archive</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileEncoding">ISO646-US</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileTimestamp">20061212T121622Z</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileType">txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileName">200610.TXT</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileSize">124</SAP:Record>
      </SAP:DynamicConfiguration>
    and for Response:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Response
      -->
    - <SAP:DynamicConfiguration xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileSize">124</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileType">txt</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="SourceFileTimestamp">20061212T121622Z</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileEncoding">ISO646-US</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="FileName">200610.TXT</SAP:Record>
      <SAP:Record namespace="http://sap.com/xi/XI/System/File" name="Directory">/usr/sap/PXD/put/archive</SAP:Record>
      </SAP:DynamicConfiguration>

  • Adding file name in the sender Adaptor

    Hi ,
    I am facing some problem in adding file name .
    The scenario is like this :
    The file needs to be send from on system  and needs to be Archived . Once processed, the archived file should be prefixed with ARCH_ so that it is not picked up again .And the other thing given is the file name used will be of the format XXX_YYY_nnnnnnnnnn.DAT where nnnnnnnnnn is the date stamp .
    Please help it's urgent ......
    Thanks and regards
    Anita

    Hi,
    if you can have XML achvived files you can use
    standard
    processing mode: Archive
    with one swich you can set the timestamp mode
    yyyMMdd-hhMMss-SSS_.
    ref
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/content.htm
    Regards,
    michal

  • Previously Firefox would show a number at the end of the file name (renaming the file by adding a number) showing that I had already downloaded a file at least once before. Recently that isn't happening. How do I get that feature back?

    When downloading, previously Firefox would show a number at the end of the file name (renaming the file by adding a number) showing that I had already downloaded a file at least once. Now that isn't happening. How do I get that feature back?

    When downloading, previously Firefox would show a number at the end of the file name (renaming the file by adding a number) showing that I had already downloaded a file at least once. Now that isn't happening. How do I get that feature back?

  • Dynamic File Name - Suppress the Substitue varible

    Hi All,
    I am doing the scenarios like File name at the recevier end would be dynamic for that i take an extra field NAME mapped with UDF which return the file name dynamically. It is working fine and doing good. But the problem here is , this field is the first field in my target structure so i am getting an empty line in the target file.
    So My structure as follows:
    <b>MT_BNK01           1..1
      NAME                1..1
      RECORD             0..Unbound
          --Record_data  0..Unbound</b>
    So in the recever side i written as follows
    Recordset Structure:: RECORD
    <b>RECORD.fieldSeparator = 'nl'
    RECORD.endSeparator = 'nl'</b>
    But according to this weblog i can suppress the empty line but it is not working
    /people/sravya.talanki2/blog/2005/08/11/solution-to-the-problem-encountered-using-variable-substitution-with-xi-sp12
    means, NAME is also in the same level of RECORD in the Structure. So How can i pass the structure as ??
    I tried to pass the RecordSet Structure: NAME,RECORD
    and following parameters, it is not working
    <b>NAME.fieldFixedLength =0
    NAME.fieldLengthTooShortHandling = Cut</b>
    Can you please  suggest me what could be the reason. Tell me what information i need to pass the RecordSet Structure and attrubute information also.
    One more thing like, My sender side it is not picking the empty lines. What could be the reason. I given fieldSeparator and endSeparator as 'nl'. So to catch the empty line what i need to do???
    Thanks in Advance,
    Best Regards,
    Vijay

    Hi Vijaya,
    This can be solved. Actually i had the same scenario where i was getting blank line for the header. Suppose Header was carrying the file name after i cut the value i would get a blank line in file.
    So i added in content conversion parameter the following line
    Header.endSeparator - '0'
    then the first line was not blank.
    Try this, i think your issue will be solved
    Regards,
    Ramesh P
    Message was edited by:
            Ramesh Parashivamurthy

  • Should the web page address be included in the file name in the meta data dialog box?

    In the page properties > meta data > below is a field with the label file name: (the the area to type in the field), after the field, it is labeled .html.
    I have 2 questions here.
    1. If I type in http//:www (my page url), do I include .html at the end? I didn't know if this is automatically added because it is off to the side of the field?
    2. If I type in the entire URL address: http//:www (etc, etc).html,    after closing the page properties dialog box, I make it a habit to double check my work. What happens is the http//:www.xxx changes to (htttpwww.xxx). It drops the //: on the URL.
    So would it be better to just type in www.xxx (without the http//:www.xxx)
    and do you type in the .html at the end?
    I am assuming this will help with SEO page ranking or at least makes it easier for the search engines to crawl your site??
    I hope this makes sense.
    Advise would be very helpful.
    Ben

    You are absolutely correct with the URL Ben. Taking your above example, you just need to type in "Services" in the file name and the webpage will be exported as services.html and the URl will be  www.xyz.com/services.html.
    All the webpages (be it parent page or child page) gets physically saved at the root directory of your website on the server (where your website resides).
    This name is just the name of the file using which it is physically stored and called from the server. It does not help search Engines to crawl deeper inside the website.
    As I explained, "name which you wants the .html file to be stored with" here means the name of the physical file which is getting saved on the server.
    Most users leave the file name same as Page name. If you have it different from page name then this will be the workflow :
    Page Name : About
    File Name : test
    domain : www.mysite.com
    Now if you are  using a Menu Widget, it will list "About" in the Menu. And when end user will click on "About" then it will call the file named "test.html" from the server location (where all the files of your website are stored).
    And it will open a page with address "www.mysite.com/test.html"
    Hope I am able to explain the concept of File Name here. Please let us know if you have further queries on this.
    Regards,
    Sachin

  • How do i map from file name to the device it resides on

    hi
    i need to find a way to map from a file name to the disk device it resides on( so i can do ioctl to that device ).
    i know that stat(2) returns a dev_t value, but i don't know how to translate from that dev_t to the device name( e.g. /dev/dsk/c0d0... )
    THANKS
    Gabriel

    thanks for the reply,
    i'm using a similar mechnisem on linux - using getmntent(3) to find the longest prefix of the filename realpath(3).
    i was actually looking for a mechnisem similar to the devname(2) syscall on the BSD os. with this call the kernel do all the work for you simply by mapping from dev_t( which the kernel stored in the indoe) to the device name by keeping a simple mapping table.
    if this mechinsem doesn't exists i will have to (eventually) duplicate the kernel work(namei) and create my own mapping.
    THX
    gabriel

  • How can I edit the file name of the home page?

    How can I edit the file name of the home page?
    Gr Ammani

    I have a similar issue with regards to the filename...
    When I navigate to my website, it doesnt work unless I actually type the filename at the end of it. Example: type in "www.whitelion.com" (this is my real domain name) and it doesnt work. When I type in "www.whitelion.com/index.html" then it works.
    This is obviously inconvenient because my clients will never know to add the filename to the end of the site.
    Is there any setting or way to get the page to appear by just typing the original domain name without adding the extension?
    Thanks,
    Emelia

  • Capture href onclick and log the file name to the database table

    I need somehelp with JSP, JavaScript and Java. When a link to a .wav file is clicked, it need to play the file by calling playSound(); function of Windows Media Player, and then capture the name of the file and call a java function to send the information to mySQL database where it will be logged in the file name will be recorded in a table. I am having rough time for being able to call the java function from the jsp function. I am aware that the jsp variable, in this case the file name that was clicked, can not be called in Java but I do not know any other way to do it.
    Please Help....
    I have made a few changes to the code now. Here is my latest code. I still need some help with onClick event. It does not work as intended.
              <a href="WaMu_Recording/<%out.println(strFileName);%>
                   onclick="<%
                             mymes.logFilePlayed(strUser, strPassword2, strFileName);
                        %>;
                             playsound('<%out.print(strFileName);%>');">
                        <%
                             out.print(strFileName);
                        %>
              </a>
    The program appears to be executing the first part of the onClick, mymes.logfilePlayed(strUser, strPassword2, strFileName) as soon as the page is loaded because I can see the all of the records added to the database even before any of the href is clicked.
    onclick should execute calling of the functions logFilePlayed and playsound when the click event occurs.
    Edited by: uncleshah on May 21, 2008 5:26 AM

    Here is how it was solved:
    1) A hidden text box was created for each of the href using the following html script:
         <input type='hidden' name='<%out.print(fileViewed);%>' style="display:" value="" id='<%out.print(intNumber);%>' />
    the name was like an array. So the fields were named: fileViewed1, fileView2, fileView3.... and so on.
    2) Here is the onClick event for the href field:
    onclick="playFile(
              '<%out.print(intNumber);%>',
              '<%out.print(strFileName);%>',
              '<%out.print(fileViewed);%>'
    3) Here is the playFile function:
    <SCRIPT language="JavaScript">
         function playFile(fileNumber, strFileName, fileViewed)
              var desc =document.DisplayFiles.elements[fileViewed];
              desc.value = strFileName;
              playsound('strFileName');
    </SCRIPT>
    Note that fileNumber param is not used.
    4) Upon submit of this form. A new page was opened and here is the code for the new form.
    boolean moreFiles = true;
    String fileName;
    String somethingBack = "";
    myMessage mm = new myMessage();
    int i = 1;
    String strPara ="fileViewed" + i;
    while(moreFiles)
         fileName = request.getParameter(strPara);
         if (fileName != null) {
              if (!(fileName).equals(""))
    // this function on the server side create a record for each file played.
                   somethingBack = mm.logFilePlayed(userSess, password, fileName);
                   ++i;
                   strPara = "fileViewed" + i;
         } else {
              moreFiles = false;
              mm = null;
         } //if else
    } //while          
    This is about 10 days of work in a very short note. I hope that someone will benefit from this work.

  • Assign Logical file name for the physical file path through Program

    Hi all,
    I am having a physical file which is getting generated dynamically. It is having the date and time stamp in its name which is added at runtime.
    Now I need to assign a logical file name for the physical file path through the program.
    Is there any FM or any other method to assign the same.
    Gaurav

    I think it is not possible. becuase the date & time added at runtime. so if you check the table  PATH you can find filename and their definitions

  • Globally removing an illegal symbol from file names in the finder

    I recently discovered that my method of dating files makes use of the illegal symbol, '/'. Now I have thousands of files with that symbol in them and am having trouble transferring them to my new hard drive. Is there a was that I can globally remove that symbol from the file names via the finder?

    Hi
    download filelist.dmg
    Double click on it to open it. Drag the Filelist app' into your Application Folder, a good a place as anywhere to keep it.
    Open the FileList application, it should show as a window.
    Drag a file or a group of files onto that open window- the left hand side pane.
    ... and there you can manipulate the prefix and suffix of the files to give them new file names.
    Create a file in text edit, type something in it, save is as test.rtf, and then drag it into the FileList app and experiment with changing its name.
    When you get the hang of it, do a group of files as a batch.
    I tried to do what you wanted to do in your initial post and was successful, so just have a play around with it.
    regards roam

  • Dynamic file name of the attachment in sender mail adapter

    Hi
    I have configured a sender mail adapter which receives some attachments.
    Right now the file name of the attachment is hardcoded to "MailAttachment-1" "MailAttachment-2" using the content-description from "AF_Modules/PayloadSwapBean" module.
    I want to set it to dynamic ie. instead of "MailAttachment-1"... i want it with real name of the attach.
    please suggest a solution w/o the need to develop a custom adapter module.
    Thanks!
    Regards,
    Mariano.

    Thanks Prateek,
    Now, i can see that the name of the original file is into the content type named as  text/xml; name"name of the file.xml" when i send the email from outlook.
    If i send it from hotmail, this is not happend.
    Do you know why happend this?
    If i always would have the original name inside the content type, my problem will be solved.
    Edited by: Mariano Vidal on Feb 13, 2009 2:26 PM

  • Reading file names in the unix box

    Hello,
    I did the following to read the files from the local directory.
    String s1 = "c:\samplefiles"
    File dir = new File(s1);
    if(dir.isDirectory())
    String listoffiles [] = dir.list();
    for(int i = 0; i <listoffiles.length ; i++)
    System.out.println(listoffiles);
    else
    System.out.println("Its not a directory");
    How can i read and print the file names in the unix box?
    Thank You.
    Kumar

    Thank You for the reply.
    In my custom page, i am trying to include a search page which includes date parameters based on which the pdf files in the unix box should be displayed in the page as a list. (The pdf file names start with the date).
    Once the user clicks the file names displayed in the page, i need to open the pdf. This part i can handle but to search the file names based on the parameter names and display in the page as the list is a bit confusing.
    Thank You.

  • Changing of the physical file name of the file after archiving

    Hi all,
    We are in process of archiving  and  completed the process successfully and archived to o:\PRODSID\<filename>.
    When refresh   is happening from Prod to Quality   the archived data will come as O:\PRODSID\<filename> and the archived files will not be accessible since quality system  is not able to find the path with O:\PRODSID\<filename>.
    Is there anyway i can change the physical file name  of the archived files to correct path O:\QUALITYSID\<filename>, i need to change only the SID  only    from PRD to QUALITY.
    Thanks,
    Subhash.G

    Hi Subash,
    Do you want change the Physical File name or the Path from PROD to SID.
    Path :- in the transaction called FILE, double click on Logical Path Definition , select the Logical File and double click on "Assignment on Physical Path to Logical Path" and you can change FILENAME also here
    Thanks,
    Sravanthi

  • How to pass the local file name to the workflow in TC OAWD

    Hi everybody!
    I have to pass the local file name of the image as a parameter to a workflow in TC OAWD.
    By debugging I found the FM which starts the workflow -  'ARCHIV_PROCESS_FAXINPUT' . It has two importing parameters : FRONTENDPATH and BASICFILENAME, but they are not used by calling the FM.
    Do you have an idea if there is a DDIC table, which contains the local file name or another way to solve the issue.
    Thank you in advance.

    Hi,
    Not sure of what you want.
    Have a look at v$session view. Machine column is maybe what you're looking for.
    If you want to retrieve the local host executing remote desktop, it's actually not possible natievely, since it's still remote host that is connecting to the database.
    Hope it helps.

Maybe you are looking for

  • Delta CIF activation for the sales orders

    HI, I am running in the background all teh master data models between R3 and APO, and updating the stocks for the new items as well. Should I run (generate and activate delta) periodically the sales order integration model? Thanks a lot

  • Pen Tool Troubles

    I should probably start by saying that I am a novice PS user.  Yesterday I was using the pen tool, for a school assignment, to trace around parts of a picture in order to make a vector illustration.  It was working fine for a while, but now when I cl

  • To know the name of the job

    Hi all,    Could u say me how to get the name of the job that is being used in the program if if the name of the report is known?

  • Customer payment run

    hi, 1 i know that f-28 is to post incoming payment from customer. normally we run F110 to make payment for vendor. may i know F110 is a payment run to make payment to customer or receive payment from customer? 2 what is the difference for f-28 and f1

  • Love Nuance VSuite 4.0 but how can I get it to capitalize the first word...

    In a sentence? Such a great tool, but now have to go back and capitalize every first word in a sentence. It capitalizes names and places appropriately. Is incredibly accurate. Any help would be appreciated. Thanks.