There is a need to recursively run svn upgrade in certain directory in filesystem, ignoring non-svn subdirectories:
C:\a>svn upgrade
C:\a\b>svn upgrade
<skip non-svn dir>
C:\a\b\c>svn upgrade
...
This means we need to run svn upgrade command in every folder that has .svn inside it. How this can be done in win32? Found for d in find . -name .svn -type d; do svn upgrade $d/..; done routine for posix OS.
svn upgrade needs to be run at the top level of each working copy - you don't want to recurse into a WC 3 levels deep and then run it there, as you'll hose the WC. Reason: SVN pre-1.7 had a .svn directory in each directory of the working copy, while 1.7+ uses a single .svn in the root of the WC.
So, your recursion has to guarantee that you'll touch the top levels first - then as you go deeper if you find a .svn directory, you know it's a separate WC and not a child of another.
Batch is dead, use PowerShell. Put this in a .ps1 file (or the PowerShell ISE) and run it:
function upgrade-svndirs {
param (
[string]$PathToUpgrade
)
$Dirs = get-childitem $PathToUpgrade|where-object{$_.PSIsContainer};
foreach ($dir in $dirs) {
$DirName = $dir.FullName;
$isWC = Get-ChildItem $DirName -Filter ".svn" -Force;
if ($isWC) {
svn upgrade "$DirName";
}
upgrade-svndirs -PathToUpgrade $DirName;
}
}
upgrade-svndirs C:\a;
Related
If I start a PowerShell as a regular user (not admin) and run
cd Desktop
mkdir test
cd test
git init
cd ..
I then cant delete the folder via PowerShell. I have tried the following commands as admin and as the current user.
rm -r test # -> no access permission
rmdir test # -> no access permission
del -r test # -> no access permission
del test # -> no access permission
It prints
+ CategoryInfo : PermissionDenied: (.git:DirectoryInfo) [Remove-Item], IOException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
But I don't understand why I can't remove folders with a .git folder in them.
In order to remove [a directory that contains] hidden items, PowerShell's Remove-Item cmdlet requires passing the -Force switch:
Remove-Item -Recurse -Force test
The shortest form of this command (for interactive rather than scripting use), using the platform-neutral ri alias and PowerShell's so-called elastic syntax, where it is sufficient to specify a prefix of a parameter name (such as -r for -Recurse), as long as that prefix is unambiguous):
ri -r -fo test
Note how a two-letter prefix is required for -Force, because -f alone is ambiguous: it could also refer to the -Filter parameter.
git init creates a .git subdirectory that is assigned the Hidden attribute on Windows (on Unix-like platforms, the fact that the name starts with . alone makes the directory a hidden one).
On Windows, rm, del, rmdir are simply built-in aliases of Remove-Item, the single cmdlet used to remove both files and directories (removal of the latter requiring -Recurse if the directory is not empty).
(On Unix-like platforms, only del is defined as an aliases, so as not to shadow the platform-native rm and rmdir utilities.)
ri is a platform-neutral alias derived from the name Remove-Item, and therefore preferable.
To see all aliases defined for a given command use Get-Alias -Definition $name; e.g.:
Get-Alias -Definition Remove-Item
Note: While it is arguably beneficial for PowerShell to require explicit opt-in via -Force in order to delete hidden items - so that you don't accidentally delete items whose existence you may not be aware of - the error message is suboptimal, in that the problem isn't one of permissions.
I am using Compress-Archive and want to zip the current directory into the same path. However I do not want to have to type out the entire file path both times. Is there an easy way to do this?
I am using windows 10 pro.
This works for the most part Compress-Archive . test.zip but I want it to be on the same level as the current directory so I need to put it back one spot.
Something like this is what I want:
path/test
path/test.zip
What I am getting:
path/test
path/test/test.zip
It is going inside the actual folder which is not what I want
You propably want that:
Compress-Archive * ..\test.zip
The wildcard * avoids that the name of the folder is put inside the zip.
Using .. for the output path we go one level up in the directory tree.
This command will fail if test.zip already exists. Either add parameter -update to update the archive or add -force to overwrite the archive. Both can be used even if the archive does not already exist.
If the current working directory is "t", it can be included using the following command. I would note that I do not think putting the destination .zip file in the directory being compressed is a good idea.
Compress-Archive -Path $(Get-ChildItem -Recurse -Exclude t.zip) -DestinationPath .\t.zip -Force
It is shorter if you are willing to use aliases and cryptic switches.
Compress-Archive $(gci -r -e t.zip) .\t.zip -Force
If I have misinterpreted your situation, please leave a comment or improve the information provided by editing the question.
I am searching through folders in order to find the one that has the contents that I desire.
$path = dir "C:\windows\ccmcache\*\Office.en-us" -Directory
echo $path
It returns:
Directory: C:\windows\ccmcache\c
But when I run my command:
Start-Process "$path\setup.exe /uninstall ProPlus /config Uninstall.xml" -Wait
It tries to run:
C:\windows\ccmcache\c\Office.en-us\setup.exe............
Which doesn't exist! So how can I go back a step so I can run the setup.exe command out of the c folder?
Something like:
$path2 = $path\cd..
Thank you all in advance.
You can simply do:
$Path2 = Resolve-Path (Join-Path $Path '..')
Note:
Join-Path is the cross platform way of concatenating path strings
Resolve-Path will give you a fully qualified path name
^^ step is optional, since windows will traverse the .. for you, but it helps to visually see the folder it resolves to.
Does this help?
You are using Get-ChildItem to return a System.IO.DirectoryInfo object. The path you are looking for already exists there as the Parent property.
$path2 = $path.Parent.FullName
No other cmdlets are needed here. You don't even need to save it into another variable if you don't want to.
Beware that your $path could have multiple results which will have consequences later in your code. If you only cared about the first one you could add | Select -First 1 to guarantee only one result.
It can be done simply using Resolve-Path function.
suppose structure is like following
root
Folder1 Folder2
and our current working directory is Folder1 and we want to move to Folder2.
$path2 = Resolve-Path("$path\..\Folder2\fileinFolder2")
I'm not sure I completely understand what you're asking.. Do you mean how to backtrack in your file directory? That command is "cd .."
Do you mean how to call $path THEN move one level higher in the directory? If so you'll need to create a new $var that is one level higher before calling your setup.exe
I would like to recurse through all subfolders of a given folder, and for all files of a given extension (optionally wildcard), search and replace some piece of text.
There's a similar previous question here, and I'm trying to get a modified version of the top answer working for my purpose. It uses Powershell for the find and replace. However, my modified version below is not recursing. I don't remember where I found the recurse part of the first line, so maybe I'm using that incorrectly.
Get-ChildItem *.* -exclude *.ps1* -recurse |
Foreach-Object {
$c = ($_ | Get-Content)
$c = $c -replace 'foo','bar'
[IO.File]::WriteAllText($_.FullName, ($c -join "`r`n"))
}
I am running the code from the Powershell command line as a PS batch file, .ps1, hence the exclusion of that extension.
This works fine if I run it directly in a folder that has some files I want searched, but if I run it from a parent of that folder, the searching/ recursion of subfolders does not happen. It doesn't even try to, which I can tell from the fact that the command finishes running instantaneously. If I run it in my first subfolder, which has about 50 text files, there's a couple seconds delay before it finishes, indicating to me it's actually searching those files.
I've also tried this with the exclude portion removed and the behaviour is the same.
My guess is that *.* matches only items with a dot in them. Folders have no extension, so they aren't matched.
gci -rec -force -exclude *.ps1 | should do what you want.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you remove Subversion control for a folder?
Command line to delete matching files and directories recursively
I recently converted my cvs repository to svn using cvs2svn and I recently noticed that every directory has a hidden folder called .svn. My current build script copies a lot of directories from my versioned resources directories and it ends up copying the .svn files. Is there anyway to make svn not include these files when I checkout or do I need to write a script to delete all these .svn files. There are many files that have these hidden .svn directories so this would be a pain unless I could write a recursive script to do this but I don't if I can do this for my windows installer. Is there an easy way to stop svn from putting this hidden directory everywhere in my project?
I'm not sure in your specific case that you want to remove all those .svn directories. But if you do, here is a bash one-liner to do just that:
find . -name .svn -print0 | xargs -0 rm -r
You can do a thing called an SVN Export to get the files without the .svn directories
http://svnbook.red-bean.com/en/1.7/svn.ref.svn.c.export.html
I posted this yesterday over here, but here is again because I kind of put it in the wrong thread anyway...
I've got something that should make your day. Original source is here.
This is a (perfectly safe) Shell Extension that will add "Delete SVN Folders" to your right click menu in Windows. Run it on any directory containing those pesky files.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN]
#="Delete SVN Folders"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN\command]
#="cmd.exe /c \"TITLE Removing SVN Folders in %1 && COLOR 9A && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""
To make this part of your build script copy that call to cmd.exe and execute it.
find . -name '.svn' -depth -exec rm -rf '{}' \; -ls
on Win32/Win64 systems, the following command should do the job:
del /q /s .svn
Those folders are required for how subversion works with a working copy (i.e. where you've done a checkout).
One option would be for you to do an export to another location. The export would not have the .svn folders, and you could run your script on that. Documentation: svn export, TortoiseSVN Export
Another option would be to modify your script to ignore hidden directories, or build a better build tool.
And a PowerShell version
ls -Force -Recurse -Filter .svn | rm -Force -Recurse
svn export is what you want. It will give you a clean copy of the code tree without the .svn directories (note that this copy is not under version control and svn commands won't work on it once it's exported).
I utilize this method to launch code on production servers. Our build script takes an export of the code branch, tars and gzips it, uploads it to the correct server, and unzips/untars it.
If wanna do this with ruby just paste my script at the root folder you want to remove recursively: http://fabianosoriani.wordpress.com/2009/03/19/ruby-script-to-remove-svn-folders/
You could take a look at SVK, which is a layer on top of Subversion. One of the advantages is that the repository metadata for your working copy, which is normally stored in the .svn dirs, is instead kept in a single central location, so you don't have the ugly hidden .svn dir problem. It's pretty nice.
find "/YourFolder" -name ".svn" -exec rm -fdR {} \;
Check this
link
I dont know if I would delete them, but maybe modify your build script to ignore copying them would be a good idea. I use Ant to build compile and build my war and it does so ignoring .svn dirs.