Appending the Filename

Welcome Forums General PowerShell Q&A Appending the Filename

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #5685

    Points: 0
    Rank: Member

    by Lahru at 2013-03-19 08:04:10

    I hope there is a simple answer to my simple seeming question.
    I want to rename all files in a directory.
    The files that get put in this directory have seemingly random names like a hex designation.
    All files are either TIF, JPG or PDF files.
    I want to append some text to the beginning of each filename AND move it. The rename and the move can be 2 separate actions if necessary.

    So what I have is:

    I wish to end up with either:

    So the appending of additional text to the file's name while incorporating the original file name is what I am after. (Not looking to add a date.)

    I've played a bit with rename-item and Move-item, but I'm missing something because neither of these like the use of wildcards or more likely I am misusing wildcard characters.

    by MasterOfTheHat at 2013-03-19 09:12:08

    You can do both the rename and the move using Move-Item:
    Get-ChildItem C:\temp\test2\00-22-64-F4-8E-0C.TIF |
    ForEach-Object { Move-Item -Path $_.FullName -Destination "c:\temp\test\DepartmentName-$($_.Name)" }

    by Lahru at 2013-03-19 09:59:04

    Theank you very much, was able to use this with only a minor adjustment to deal with all files in the originating folder, like so
    Get-ChildItem C:\temp\test2\ | ForEach-Object { Move-Item -Path $_.FullName -Destination "c:\temp\test\DepartmentName-$($_.Name)" }

The topic ‘Appending the Filename’ is closed to new replies.