Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
How to find and add the file name of each file in a folder to a meta tag -
<link rel"canonical" href="https://cure4incurables.in" />
(I am not a software engineer, so please give step by step instructions - I have implemented what is given here: Windows PowerShell Scripting Tutorial For Beginners - Varonis[^] )?


What I have tried:

I saw the matter here: Replace string value in a file with filename[^] but don't know how to implement it as the PowerShell is accepting only one line Commands (the Get-ChildItem -Path C:\Users\SKY\Desktop\cure.in command however did help me see all the files of that folder)
Posted
Updated 3-May-21 7:57am
v4

Quote:
please give step by step instructions
This forum is titled Quick Answers for a reason. We can try to help with code you have written, but there is not time or space to teach you in such a manner.
 
Share this answer
 
Comments
[no name] 3-May-21 3:52am    
@Richard MacCutchan OK, I opened Windows Power shell as an admin, should I put all the code I found at https://www.codeproject.com/Questions/1258369/Replace-string-value-in-a-file-with-filename with a space for each next line (and everything together)? Please answer.
Richard MacCutchan 3-May-21 4:15am    
Sorry, no idea. What is that code supposed to do, and how does it match your requirements?
[no name] 3-May-21 4:24am    
@Richard MacCutchan Yes it is exactly what I want. I want to replace a string with the file name of each file for multiple files in a folder
Richard MacCutchan 3-May-21 4:38am    
That code replaces a string in the contents of the file. And I am not sure what you mean by "to replace a string with the file name of each file for multiple files".
[no name] 3-May-21 4:51am    
@Richard MacCutchan I want to know how to get/extract the file names of multiple files using the "$file.BaseName" command and add it to the Meta tag I mentioned in the beginning (which can be seen right on top) in each file for multiple files of a folder, just after the "url". How to do that?
$files = Get-ChildItem -path C:\Users\SKY\Desktop
foreach ($file in $files)
{Name"
    $content = Get-Content $file
    if ($content -match "FNAME")
    {
        $content = $content -replace "FNAME", $file.BaseName
        Set-Content $file $content
    }
}
 
Share this answer
 
v2
Comments
[no name] 4-May-21 9:23am    
One can replace the "BaseName" with "FullName" to get the extension of each file (.htm or .html or .txt) but that adds even the full "path" which of course can be removed using the "find" and "replace" of Notepad++ (in my meta tag given in my question right at the top, I added "FNAME" to the URL https://cure4incurables.in at the end before running the script mentioned just above)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900