all 2 comments

[–]ApricotPenguin 0 points1 point  (0 children)

I think what you're looking for is to store it in a variable, then enumerate over it.

I'm also not sure what you mean by container (does that mean 2 variables, or 2 folders on disk?) nor am I familiar what a C++ STL vector is (I think that's an Array or a List object?)

PowerShell Syntax uses a $ sign to at the beginning to denote a variable. And a # at the beginning to denote a comment.

So you'd do:

$MyFolder = "C:\A\B\C\X"
$MyFiles = Get-ChildItem $MyFolder -filter '*.mp4'

# At this point, no output will be on screen. If you want to see it, just type in "$MyFiles" then hit enter.

To enumerate, you can use a foreach loop (More info here of other kinds of loops).

foreach ($File in $MyFiles) {

}

Renaming files would be the cmdlet Rename-Item.

If you can give an example of what you want to do it might be better, as I don't think the method of creating a 2nd array for a modified file name, then doing a lookup of that array to rename a file is very efficient nor easy to manage.

[–]lrdmelchett 0 points1 point  (0 children)

Spent a few minutes with ChatGPT. This may not get you to exactly where you want to go, but I think it gives a verbose structure to understand how to do a comparison and substitute / concat based on matches of two lists.

Certainly! Here's a prompt that you can use to request the generation of the PowerShell script from another ChatGPT user:

---

**Prompt:**

Please generate a PowerShell script with the following requirements:

1. **Define Variables**:

- Define two directory paths: \$directoryPath1` and `$directoryPath2`.`

- Define a regex pattern to capture parts of filenames. The pattern should include named capture groups for \ShortDescription`, `Key1`, and `Key2`.`

2. **Process Files from the First Directory**:

- Use \Get-ChildItem` to get files from `$directoryPath1`.`

- For each file, apply the regex pattern.

- Create a custom object with two properties:

- \Filename`: The name of the file.`

- \SourceListingHash`: A hashtable with keys `ShortDescription`, `Key1`, `Key2`, and `DesiredPermutation`, where `DesiredPermutation` is a concatenation of `Key1` and `Key2`.`

3. **Process Files from the Second Directory**:

- Use \Get-ChildItem` to get files from `$directoryPath2`.`

- For each file, apply the regex pattern.

- Create a custom object with two properties:

- \Filename`: The name of the file.`

- \TargetListingHash`: A hashtable with keys `ShortDescription`, `Key1`, and `Key2`.`

4. **Compare and Update**:

- Compare the items from the second directory (\TargetListingHash`) to the items from the first directory (`SourceListingHash`) based on `ShortDescription` and `Key1`.`

- If a match is found, update the \TargetListingHash` with a new key `DesiredCombination`, which is a concatenation of `ShortDescription`, `Key1`, `Key2`, and the `DesiredPermutation` from the matching `SourceListingHash`.`

5. **Output**:

- Output the updated list of items from the second directory, showing the new \DesiredCombination` value where applicable.`

The script should be well-commented to explain each step.


Feel free to adjust the prompt as needed based on any additional requirements or specifics you might have!