renaming a bunch of file

Discussion in 'Windows 7 Help and Support' started by pawii, Apr 7, 2014.

  1. pawii

    pawii New Member

    Joined:
    Apr 7, 2014
    Messages:
    3
    Likes Received:
    0
    i had 200 file arranged in a serial order
    i want to rename them by deleting the first 2 character of every file name
    how can i do it??
     
  2. BurrWalnut

    BurrWalnut Extraordinary Member

    Joined:
    Nov 14, 2008
    Messages:
    97
    Likes Received:
    13
    pawii likes this.
  3. Gavin Oscur

    Gavin Oscur Well-Known Member

    Joined:
    Apr 5, 2014
    Messages:
    78
    Likes Received:
    3
    Try Power shell

    And Run this in your desired directory

    gci *.txt | rename-item -newname { [string]($_.name).substring(1) }

    Explanation: - gci *.txt collects all *.txt-files in the actual directory.
    - rename-item -newname renames the piped results from the gci-command with the string that is generated in {}
    - string.substring(1) takes the filename starting after the first character

    When you want to remove the first Two characters, just replace the (1) after 'substring' with (2). In power shell, the whole filename is treated as a string(-object), points included.

    If you find this answer helpful, then like this post
     

Share This Page

Loading...