in Education by
I'm not a coder. I have a Powershell script .ps1 that goes into all subfolders of "db" and deletes the files I want to delete in all of them. It works for what I need. The following code: Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename00.dbc -Recurse | Remove-Item -Verbose Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filename11.dbc -Recurse | Remove-Item -Verbose Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*" -Include "filename11.dbc" -Recurse | Remove-Item -Verbose Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\dbc\permanent" -Include filmename22.dbc -Recurse | Remove-Item -Verbose Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\lnc\all" -Include filmename33.lnc -Recurse | Remove-Item -Verbose Get-ChildItem "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\edt\permanent" -Include filmename44.edt -Recurse | Remove-Item -Verbose Now I want to copy 2 files in the same way in a generic way to simulate this code above but I don't know how to do it. I'm using this code to copy the files: Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2220\lnc\all\" -Recurse Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2230\lnc\all\" -Recurse Copy-Item -Path "File to copy 1.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse Copy-Item -Path "File to copy 2.lnc" -Destination "C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\2240\lnc\all\" -Recurse Can someone help me create 2 generic codes (I think one line for each copy) to copy the 2 files inside the "lnc\all" folders to any subfolder existing in the "db" folder? That is, replace the 6 codes with 2 generic ones, in case there are other folders in the "db" it works too. Thanks. I'm not a programmer, if possible send me the code in ready format (as an example, thanks) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
For the first part of your code, as explained in comments, there is no automated way to do it aside from having a reference (hash table in this case) to target the directories and it's specific files. The keys of the hash table are the target paths and the values are the files to target with the -Include parameter: $initialDir = 'C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db' $targets = @{ '\*' = 'filename11.dbc' '\*\dbc\permanent' = 'filmename00.dbc', 'filename11.dbc', 'filmename22.dbc' '\*\lnc\all' = 'filmename33.lnc' '\*\edt\permanent' = 'filmename44.edt' } foreach($key in $targets.PSBase.Keys) { $path = Join-Path $initialDir -ChildPath $key Get-ChildItem $path -Include $targets[$key] -Recurse | Remove-Item -Verbose } For the second code, it could be automated this way, note that the -Path parameter from Copy-Item can take an array of paths to copy, in that sense, since we're copying the same 2 files, you can store the paths of both in a variable. Then for the destination path, seems like this should do it: 'C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\lnc\all\' First get all the directories in that path, and the for each directory copy the files to them: $filesToCopy = @( # Use absolute paths here to be safe 'File to copy 1.lnc' 'File to copy 2.lnc' ) $destination = 'C:\Program Files (x86)\Steam\steamapps\common\Game 2022\data\database\db\*\lnc\all\' Get-ChildItem $destination -Directory | ForEach-Object { Copy-Item $filesToCopy -Destination $_.FullName }

Related questions

0 votes
    which of the following is not a basic step in creating a worksheet? a) Save the workbook b) Modify the ... d) copy the worksheet Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    I have the below (simplified) code, which uses the following source: line 1 line 2 soup = BeautifulSoup ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Write the steps to insert command button control in visual basic project Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    13. Copy command is always followed by:- O a) Cut O b) Delete O c) Paste O d) None Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    What is the command used to copy data from the local system onto HDFS?...
asked Aug 5, 2021 in Technology by JackTerrance
0 votes
    COPY command can be used to read data (1)All the options (2)From std i/o devices (3)From csv to table (4)From table back to csv...
asked May 6, 2021 in Technology by JackTerrance
0 votes
    What kind of files can be imported or exported using the COPY command (1)sstables (2)CSV (3)json (4)parquet...
asked May 6, 2021 in Education by JackTerrance
0 votes
    What kind of files can be imported or exported using the COPY command (1)sstables (2)CSV (3)json (4)parquet...
asked Apr 17, 2021 in Technology by JackTerrance
0 votes
    The output we get from a computer is called 1) Hard Copy 2)Soft Copy 3)Paper Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    MAHESH FOUND IT VERY DIFFICULT TO COPY FILES ON DOS AND REQUESTED HIS BOSS TO GET WINDOWS LOADED ON HIS SYSTEM. GIVE THE REASON WHY Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Below is my script, Please let me know if am missing something. #Script to add DNS 'A' Records ' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    On TFS 2018.2, I am building a release pipeline implying the use of : Applications configuration files ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    On TFS 2018.2, I am building a release pipeline implying the use of : Applications configuration files ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to download a collection of files, but the instructions are for the command line in Unix. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
...