SOLVED
For each subfolder, that contains images *.jpg need to create textfile list of images names (whithout extensions). Textfiles should be named same as its directory
For example you have same directory scheme:
C:\scriptfolder\ - Parentfolder for filelist_script.ps1
C:\scriptfolder\subfolder1\ - contains some jpg-files
C:\scriptfolder\subfolder2\ - contains some jpg-files
C:\scriptfolder\subfolderN\ - contains some jpg-files
Result of script work will be:
C:\scriptfolder\subfolder1\subfolder1.txt
"subfolder1.txt" - List of all images(.jpg) in "subfolder1"
C:\scriptfolder\subfolder2\subfolder2.txt
"subfolder2.txt" - List of all images(.jpg) in "subfolder2"
C:\scriptfolder\subfolderN\subfolderN.txt
"subfolderN.txt" - LList of all images(.jpg) in "subfolderN"
SOLUTION:
$gl = Get-Location
$folderlist = Get-ChildItem -path $gl\ -Recurse -Directory -Name
foreach ($folder in $folderlist) {
Get-ChildItem $gl\$folder\*.jpg -File |
Foreach-Object {$_.BaseName} |
Out-file -path $gl\$folder\$folder.txt -Force;
}
Using "BaseName" parametr excludes file-extensions from shown data.
Change it to "Name", if you need to get files names whith extension.
Your question isn't very well asked, it is hard to understand exactly what you are asking. By the looks of it you want to get a list of directories containing a single _ and then every .jpg file inside those folders appending it to a text file. This is pretty simple:
There are a few issues in your code:
The usage of -Name here returns only the folder name, not the full path. If you are changed to that directory in PowerShell then it won't be an issue but there is no need for that flag.
-Includeneeds to be changed to-FilterHere you are piping the names of the folders (not the path just the name) to an object loop where you are simply running Out-File on the same variable which holds however many jpg files that are located in the current directory. You are just overwriting the same file with the same data multiple times here.