I am trying, withouth much luck, to create a bat or cmd file that would change a "corrupt" hintpath of my third party dll's so that it referes to my fixed dll path (the P-drive). The script would have to:
1) loop through all folders under my main projects folder finding all files with the .csproj ending
2) loop through each file and replace every instance of "< HintPath >c:\xx\yy\q.dll< /HintPath >" to "< HintPath >P:\q.dll< /HintPath >"
thanks,
regards,
styrmir
If possible, I would highly suggest to use PowerShell to perform this task. Here is what it would take to do what you are after:
Get-ChildItem -Recurse -Filter *.csproj -Path YOUR_TARGET_ROOT_DIRECTORY_HERE |
ForEach-Object {
(Get-Content $_.FullName) |
ForEach-Object {
$_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')
} |
Set-Content $_.FullName -WhatIf
}
Note: I have included a -WhatIf switch that prevents the script to make any change and just outputs the actions it would perform to the console window. Please remove it to make the script functional.
UPDATE
To replace every possible HintPath reference to q.dll within C:, at every possible directory depth, you may replace this line:
$_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')
with this one:
$_ -replace '\<HintPath\>C:\\.*\\q.dll\</HintPath\>', '<HintPath>P:\q.dll</HintPath>'
Related
Is there a way to turn off optimization in Visual Studio for all translation units in a folder?
For a specific file one can use something like mentioned here.
Some workarounds that come to my mind (all not perfect, i.e. too much manual work):
include a header in each cpp which can easily toggle optimization
use some script to prepend turning off optimization for each file
I used the power shell script to complete your requirements, you need to change the file path in the code to the path of .cpp in your project, the sample code is as follows
$cpps = (Get-ChildItem -Path "C:\Users\Admin\Desktop\asdasds\Project44\Project44" -Filter *.cpp).fullname
$line = '#pragma optimize( "", {off} )'
$cpps| ForEach-Object {
$line + "`n" + (Get-Content -path $_ -Raw) | Set-Content -Path $_
}
RESULT:
Hope it helps.
I am trying to search for an email address on my harddisk. I know that it should be something like:
b************m#e******.com
and this is why I came up with this regex:
b.{12}m#e.{6}.com
I found that findstr could be useful for this job and tried:
findstr /R b.{12}m#e.{6}\.com c:\*.*
but it doesn't find anything even if I added a file with an email that should match that regex of mine, this one for example: b8726ngs.poinm#e123456.com
You could try doing this with the following PowerShell command instead (note depending on where you start this could take a long time to run):
Get-ChildItem *.txt -Recurse -File | Where-Object { (Get-Content $_.FullName) -match "b.{12}m#e.{6}.com" }
You will get red error messages for areas of the disk that you don't have permission to access. Run PowerShell as Administrator for the widest possible search.
Add a file path to Get-ChildItem in order to set a base directory if you wish, otherwise it will start in the directory you are currently in.
Explanation of parameters:
-Recurse searches the current directory and all sub-directories.
-File returns only files (not directories).
Get-Content $_.FullName gets the contents of each file.
-match performs the regex comparison.
There are regex and then there are regex. Looks like findstr is not very powerful.
findstr /R "b............m#e......\.com" *.*
This is only on the findstr part not working.
Do this with appropriate precautions, e.g. inside a directory which only contains readable files.
I need your help with a script that i am building.I need it to:`
To find a VM and see if it is turned off or on.
If it is off then turn it on and copy a folder with the content to replace the old folder in the VM machine.
$vmName = 'Target'
$folderName = 'C:\Folder'
Get-VM -Name $vmName | where{$_.PowerState -ne 'PoweredOn'} | Start-VM -Confirm:$false
sleep 30
Copy-VMGuestFile -LocalToGuest -Source $folderName -Destination $folderName -Confirm:$false
My problem is that the folder and its content is copy to the destination but it will not replace the folder and its content from the destination VM.
Regrades,
Michel Vaillancourt
Looks like -Force clobbers existing files on the target, but will not mirror the source contents, at least with PowerCLI 5.8 R1. So files that exist on target but not source before the copy will remain on the target after the copy. Not sure if this is by design. Invoke-VMScript could delete the target folder before Copy-VMGuestFile runs.
Why not use Robocopy or some other tool after the VM is up?
1- Start-VM, wait 1 or 2 minutes.
2- Loop until "Test-Path $folderName" is true.
3- Copy folder.
Stack,
We have many files in our library that were never used in subsequent projects. We are now at a development phase where we can do some good housekeeping and carefully remove unused library code. I am trying to optimize my grep command, it's current implementation is quite slow.
grep --include=*.cpp --recursive --files-with-matches <library function name> <network path to subsequent projects>
The main reason is that the projects path is expansive and the bulk of the time is spent just navigating the directory tree and applying the file mask. This grep command is called many times on the same set of project files.
Rather than navigating the directory tree every call, I would like to grep to reference a static filelist stored on my local disk.
Something akin to this:
grep --from-filelist=c:\MyProjectFileList.txt
The MyProjectFileList.txt would be:
\\server1\myproject1\main.cpp
\\server1\myproject1\func1.cpp
\\server1\myproject2\main.cpp
\\server1\myproject2\method.cpp
Grep would apply the pattern-expression to contents of each of those files. Grep output would be the fully qualified path of the project file that is uses a specific library function.
Grep commands for specific library functions that return no project files are extraneous and can be deleted.
How do you force grep to scan files from an external filelist stored in a text file?
(Thereby removing directory scanning.)
Try around a little using the 'xargs' command and pipes ("|").
Try the following:
while read line; do echo -e "$line"; done < list_of_files.txt | xargs -0 grep **YOUR_GREP_ARGS_HERE**
or in a Windows environment with Powershell installed try...
Get-Content List_of_files.txt | Foreach-Object {grep $_ GREP_ARGS_HERE}
I googled for windows args and found this:
FOR /F %k in (filelist.txt) DO grep yourgrepargs %k
(but I use linux, no idea if it works)
How would I replace one pattern with another for every file with extension .cc and .h recursively? Not sure if I need to prevent it from going into .svn directories.
first attempt
#!/bin/bash
for file in `find . -name '*.cc' -or -name '*.h'`; do \
sed -e s/$1/$2/g -i temp $file
done
If your project is managed under linux platform, You can do sth like that inside the bash:
for file in `find . -name '*.cpp' -or -name '*.h'`; do \
cat $file | sed s/$1/$2/g > tmp
mv tmp $file
done
Each svn file has '*-base' extension so all of them will be unchanged. This script will only affect to *h and *cc files.
You can search and replace using regular expressions through certain files in Eclipse project explorer, for example. I'm sure there are lots of tools that can do this, but Elipse comes to mind first.
To do this you need to invoke the "Search" dialog, place your pattern in the search field, specify extensions with a wildcard and press "Replace",