Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Renaming files if matches in list

$
0
0

Hey everyone,

I am having trouble with a task I have been set and hoped someone here could help me please.

Basically we have a folder with files and a spreadsheet with a column that contains part of the file name, a second column that contains the second part of the current name and a column that contains what the file should be renamed to.

I have got as far as checking if the file name exists in the first column and second but I don’t know how to get the script to rename the file to what is in the 3rd column. Is this possible?

What I’ve got so far:

$a = import-excel "path" $b = $a | select column1,column2,column3 $c = gci "location of files to be renamed" $c | foreach-object {if (($_.name.substring(0,6) -match $b.column1)-and($_.name.substring(6) -match $b.column2)) {rename file to column3 <---- bit I can't work out}} 

If anyone can please help me with this or point out where I’ve gone wrong any help is very much appreciated

submitted by /u/R0cketM0nster
[link] [comments]

The post Renaming files if matches in list appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images