How to replace first letters of a file name using Power shell or CMD

Hi guys i am having a problem on mane files that i have which are duplicated. The main reason i cant group them by name is because they have numbers in front of their name which differs Eg
01 - fileName.txt
09 - fileName.txt
02 - fileName.txt
11 - fileName.txt
i have a shed loads of them and would like to rename them by deleting the first three characters if they are numbers. I managed to create a powershell script to do that but the problem was that it would not work properly because the file would have a duplicated
name after deleting the first few chars.
can anyone help with a better script which would add a number to the end of the file name eg:
fileName1.txt
fileName2.txt
fileName3.txt
Ps all the files start with two numbers followed by a dash, however i have manually done a few which does not start with numbers and should be left alone by the script
Thank you

Here's a quick way to do it. I'm not sure what your existing code looks like but it sounds like you could incorporate this line into it.
if ($oldfilename -match "[0-9]")
$newfilename = $oldfilename.split("-")[1].trim().split(".")[0] + $oldfilename.split("-")[0].trim() + "." + $oldfilename.split("-")[1].trim().split(".")[1]
else
$newfilename = $oldfilename
01 - fileName.txt becomes fileName01.txt
fileName.txt stays fileName.txt

Similar Messages

  • How to replace the end of a file name

    I have a seriously dumb question...
    I have a row of thousands of file names (top-down, row a), these names are, for example, "photo-1.jpg" and I need to change the .jpg to .nef. How can I accomplish this?
    thanks!!

    Or just use this 'Find Replace in Selection' Automator Service (Dropbox download) without having to fuss about taking columns out to another app, fiddling with them there, and bring them back in.
    It is just a short AppleScript that, after a quick installation, will look like this in your menu:
    Select the cells where you want to make the replacement, choose 'Find Replace in Selection' from the menu, and enter the find-replace values when prompted. In your case you will see something like this:
    Hit OK and you're done.
    One-time installation is just a doubleclick on the .workflow package.
    Depending on your settings you may have to go to System Preferences > Security & Privacy and click 'Open Anyway'.
    'Install' simply moves the script to your Library > Services folder so it will show up in your Numbers menu.  It doesn't do anything to the innards of your computer.  If you want, you can check out the script first by choosing 'Open with Automator'.
    Since this (obviously) changes values in your document you might want to test it first to make sure it is working as you want.
    If you need to get rid of it then in Finder hold down the option key, choose Go in the menu and navigate to Library > Services, where you can trash it the way you would any other file or package in Finder.
    SG
    Edit: use jpg and nef rather than .jpg and .nef.

  • How to remove only the first .Period in a file name using CL.

    Hello!
    So, I've used code similar to this before to remove special characters.  It works for a period . as well, but, of course removes ALL periods.
    file=/Users/niles/Desktop/.test.txt; echo $file"${file//[\\.]/}"
    How do get a reult that only remove the first period . and leaves the rest?
    Thanks!!

    touch .test.txt .t.e.s.t.t.x.t
    # Test it.
    $ for FILE in .test.txt .t.e.s.t.t.x.t
    do
    echo ${FILE} `echo ${FILE} | sed -n 's/^.//p'`
    done
    .test.txt test.txt
    .t.e.s.t.t.x.t t.e.s.t.t.x.t
    # then change the filename.
    $ for FILE in .test.txt .t.e.s.t.t.x.t
    do
    mv ${FILE} `echo ${FILE} | sed -n 's/^.//p'`
    done
    $ ls -l t*
    -rw-r--r--  1 andya  501  0 Apr 23 21:32 t.e.s.t.t.x.t
    -rw-r--r--  1 andya  501  0 Apr 23 21:32 test.txt

  • How to replace a regular exepresion in a string in power shell

    Hi,
    Not able to replace "\X25" with "%" in powershell script.
    $new = $inst1
    $word = '\X25'
    also tried
    $word = "\X25"
    $replacement = "%"
    $newText = $new -replace $word,$replacement
    following error has been occurred:
    The regular expression pattern \X25 is not valid.
    At C:\TWClient-Build\rgx.ps1:15 char:1
    + $newText = $new -replace $word,$replacement
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (\X25:String) [], RuntimeException
        + FullyQualifiedErrorId : InvalidRegularExpression
    Thank You

    As noted in other posts, it's failing because the '\' is a reserved character and needs to be escaped.  There are other reserved characters that will also need to be escaped if you need to match them in your regular expression.
    The [regex] class offers an static Escape() method that you can use to help you escape the reserved characters when doing a literal match:
    $find = '\X25'
    $Regex = [regex]::Escape($find)
    $Regex
    \\X25
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with   - how can I change this?

    I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with %20  - how can I change this?

    Click on the below link :
    https://get.adobe.com/flashplayer/otherversions/
    Step 1: select Mac OS  X 10.6-`0.`0
    Step 2 : Safari and FIrefox
    Then click on " Download Now"  button.

  • How to replace audio track in mpg file (3,4 Gb) by mp3 fies?

    How to replace audio track in mpg file (3,4 Gb) by mp3 fies? Without loosing video quality?

    I've never used muxers under Linux, but you can try mpegdemux.
    Take a look at Elecard Xmuxer Pro, for example – but that costs $$$. Look here and you may find a good, free Windows-based tool.

  • How to find the File name using the FTP Adapter

    hi all,
    how to find the File name using the FTP Adapter with BPEL.
    Regards

    Found the solution for this.
    First In the mediator's routing rule use assign property $in.property.jca.file.FileName to $out.property.jca.file.FileName
    In the BPEL's receive activity go to the properties tab and get the property to a BPEL variable. That should do it.
    Thanks for the posts

  • How do I find out what program / file is using 100 GB of space on my Hard drive?  Once I find the problem  how do I delete the specific files to increase GB of space?

    How do I find out what program / file is using 100 GB of space on my Hard drive?  Once I find the problem  how do I delete the specific files to increase GB of space?

    Use OmniDiskSweeper
    Once you find file, it can be deleted from within OmniDiskSweeper
    Allan

  • How is it posible to get the File name, size and type from a File out the H

    How is it posible to get the File name, size and type from a File out the HttpServletRequest. I want to upload a File from a client and save it on a server with the client name. I want to conrole before saving the name, type and size of the file.How is it posible to get the File name, size and type from a File out the HttpServletRequest.
    form JSP
    <form name="form" method="post" action="procesuploading.jsp" ENCTYPE="multipart/form-data">
    File: <input type="file" name="filename"/
    Path: <input type="text" readonly="" name="path" value="c:"/
    Saveas: <input type="text" name="saveas"/>
    <input name="submit" type="submit" value="Upload" />
    </form>
    proces JSP
    <%@ page language="java" %>
    <%@ page import="java.util.*" %>
    <%@ page import="FileUploadBean" %>
    <jsp:useBean id="TheBean" scope="page" class="FileUploadBean" />
    <%
    TheBean.doUpload(request);
    %>
    BEAN
    import java.io.*;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletInputStream;
    public class FileUploadBean {
    public void doUpload(HttpServletRequest request) throws IOException
              String melding = "";
              String filename = request.getParameter("saveas");
              String path = request.getParameter("path");
              PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("test.java")));
              ServletInputStream in = request.getInputStream();
              int i = in.read();
              System.out.println("filename:"+filename);
              System.out.println("path:"+path);
              while (i != -1)
                   pw.print((char) i);
                   i = in.read();
              pw.close();
    }

    Thanks it works great.
    Here an excample from my code
    import org.apache.commons.fileupload.*;
    public class FileUploadBean extends Object implements java.io.Serializable{
    String foutmelding = "geen";
    String path;
    String filename;
    public boolean doUpload(HttpServletRequest request) throws IOException
         try
         // Create a new file upload handler
         FileUpload upload = new FileUpload();
         // Set upload parameters
         upload.setSizeMax(100000);
         upload.setSizeThreshold(100000000);
         upload.setRepositoryPath("/");
         // Parse the request
         List items = upload.parseRequest(request);
         // Process the uploaded fields
         Iterator iter = items.iterator();
         while (iter.hasNext())
         FileItem item = (FileItem) iter.next();
              if (item.isFormField())
                   String stringitem = item.getString();
         else
              String filename = "";
                   int temp = item.getName().lastIndexOf("\\");
                   filename = item.getName().substring(temp,item.getName().length());
                   File bestand = new File(path+filename);
                   if(item.getSize() > SizeMax && SizeMax != -1){foutmelding = "bestand is te groot.";return false;}
                   if(bestand.exists()){foutmelding ="bestand bestaat al";return false;}
                   FileOutputStream fOut = new FileOutputStream(bestand);     
                   BufferedOutputStream bOut = new BufferedOutputStream(fOut);
                   int bytesRead =0;
                   byte[] data = item.get();
                   bOut.write(data, 0 , data.length);     
                   bOut.close();
         catch(Exception e)
              System.out.println("er is een foutontstaan bij het opslaan de een bestand "+e);
              foutmelding = "Bestand opsturen is fout gegaan";
         return true;
         }

  • How to rename the SharePoint Document Library existing file name using Web service

    Hi,
    How to rename the SharePoint Document Library existing file name using SharePoint Web service.
    Is it possible. How could i do it?
    Thanks & Regards
    Poomani Sankaran

    Hi,
    Lists.UpdateListItems Method
    would be helpful for your requirement.
    Here is a blog with code demo for your reference:
    http://blogs.msdn.com/b/knowledgecast/archive/2009/05/20/moss-using-the-list-web-service-to-rename-a-file.aspx
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • How should we get the out put file-name same as in put file-name in file to

    Hi frnds,
    having hundreds of files in the sender system with different names, how should we get the out put file-name  in the receiver system same as the in put file-name in file to file scenario ?
    Thanks in advance.
    truly,
    snrvakiti.

    Hi,
    In Receiver File Adapter you can set under 'Adapter-Specific Message Properties'
    check Use Adapter-Specific Message Properties
    check Fail on Missing Adapter Message Properties
    Check File Name
    Have a look at this link,  [File_to_File|http://allsapnetweavernotes.blogspot.com/2008/09/how-can-i-access-filename-from-fileftp.html]
    Regards,
    P.Rajesh

  • How to get file name using File adapter Sync read

    Hi All,
    I am using SOA 10.1.3.3 and JDEV 10.1.3.3.
    I have an async bpel process.
    I have to read file name in this process... so i have used file adapter sync read operation.
    How can we get the file name with out payload using sync read.
    For normal read (Inbound Spec)we have UseHeaders="true" property.
    Is there any property for sync read to read the file name.
    Please help me
    Regards
    PavanKumar.M
    Edited by: [email protected] on Oct 27, 2009 11:23 PM

    Hi Eric,
    The info in the link provided by you is for a normal read.
    I need to read he file name using Sync read operation.
    Regards
    PavanKumar.M

  • How do I export v-card formatted files for use with either Numbers or Excel?

    How do I export v-card formatted files for use with either Numbers or Excel?

    Did you open Automator and just look around?
    Actions are listed in the left pane.
    You drag them into the workflow on the right in the order you need to process the items that you want.
    If this is a on-off requirement, just make a Workflow. If you plan to use it often, make it an Application.
    If you want to select the contacts you want to export, use a get Selected action. You'd then select the contacts in Contacts App before running the workflow.
    I'm not on a Mac to take screenshots, so you'll have to look at Automator's help or google for more info.

  • Selection of Folder/File name using the same Fun.Module

    Please let me know if there is a function module which can fetch folder name/File name  from the directory path when f4 option of selection screen field is selected. Currently I am able to get the file name using FM F4_DXFILENAME_4_DYNP but the requirment is like I have to select either folder name or the file name depending on user selection.
    Note: Please let me know if there is a single Function module which can get folder name or the file name based on the user selection.i.e, if the user want to select a folder he can select or he can select files in the folder for processing

    Hi sridhar
    try this:
    PARAMETER : TXT_FILE(100).
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR TXT_FILE.
    PERFORM GETFILE.
    start-of-selection.
    PERFORM GETDATA.
    FORM GETDATA.
      DATA : FILENAME TYPE STRING.
      FILENAME = TXT_FILE.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          FILENAME                      = FILENAME
         FILETYPE                       =  'ASC'
         HAS_FIELD_SEPARATOR           = 'X'
        HEADER_LENGTH                 = 0
        READ_BY_LINE                  = 'X'
        DAT_MODE                      = ' '
        CODEPAGE                      = ' '
        IGNORE_CERR                   = ABAP_TRUE
        REPLACEMENT                   = '#'
        CHECK_BOM                     = ' '
      IMPORTING
        FILELENGTH                    =
        HEADER                        =
        TABLES
          DATA_TAB                      = IT_UPLOAD
      EXCEPTIONS
        FILE_OPEN_ERROR               = 1
        FILE_READ_ERROR               = 2
        NO_BATCH                      = 3
        GUI_REFUSE_FILETRANSFER       = 4
        INVALID_TYPE                  = 5
        NO_AUTHORITY                  = 6
        UNKNOWN_ERROR                 = 7
        BAD_DATA_FORMAT               = 8
        HEADER_NOT_ALLOWED            = 9
        SEPARATOR_NOT_ALLOWED         = 10
        HEADER_TOO_LONG               = 11
        UNKNOWN_DP_ERROR              = 12
        ACCESS_DENIED                 = 13
        DP_OUT_OF_MEMORY              = 14
        DISK_FULL                     = 15
        DP_TIMEOUT                    = 16
        OTHERS                        = 17
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.
    FORM GETFILE.
      CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
        DEF_FILENAME           = ' '
         DEF_PATH               = '.'
        MASK                   = ' '
        MODE                   = ' '
        TITLE                  = ' '
       IMPORTING
         FILENAME               = TXT_FILE
        RC                     =
      EXCEPTIONS
        INV_WINSYS             = 1
        NO_BATCH               = 2
        SELECTION_CANCEL       = 3
        SELECTION_ERROR        = 4
        OTHERS                 = 5
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.
    <b>This is a part of my BDC program its working for me u try n reply if it works for u.</b>
    regards
    vijay

  • My power button doesnt work, jammed. How can i reset my phone if i cant use power button and home key to reset?

    my power button doesnt work, jammed. How can i reset my phone if i cant use power button and home key to reset?

    snystrom wrote:
    my power button doesnt work, jammed.
    Is this an iPhone 5?
    If so, see this -> iPhone 5 Sleep/Wake Button Replacement Program

Maybe you are looking for

  • Illustrator CS6 Freezing when opening existing files. Need Help ASAP.

    Hello There, I have the most current version on Illustrator CS6. When opening files, any file, it freezing and I have to force quit the application. I have deleted the pref file with some luck, it will only work for a short time. I have held shift+cm

  • ITunes 10.2.1 does not decode mp3 files properly

    Hello, I have recently posted the results of my MP3 decoder test, covering iTunes, Winamp, Windows Media Player and Foobar2000: http://blog.szynalski.com/2011/03/16/itunes-10-2-1-fails-to-decode-mp3-files-pro perly/ The result is that iTunes 10.2.1 (

  • Understanding photostream for a dummie

    Can someone please tell me if my understanding is correct re My Photostream? 1.  I can take photos with any digital camera or iphone camera. 2.  If my Photostream settings are set to "On" and "Automatically Download", any photos I upload into iPhoto

  • Missing file formats after cs6 beta

    I have cs5 and don't know if I'm entitled to cs6 as mine is 1 year old. I have reinstalled photoshop because I hoped it would fix some missing file formats and live CS live "...extension could not be loaded". I'm Bavari69 from a previous attempt at i

  • Is there a way to sync my I pad calendar to my phone

    I would like to sync my I pad calendar with my galaxy mobile phone, so that I can view my I pad calendar on my galaxy phone?