I have a C:\Dev folder, where I have cloned multiple Mercurial repositories. How do I get a list of those, so I can then clone them on a different PC?
You will probably have to write a batch script to do that and then use the hg paths default in each directory.
Put the something along those line in a new .bat file and then run it in your C:\Dev directory :
FOR /D %%G in ("*") DO hg -r %%G paths default
It is been a long time since I didn't wrote a batch file and I don't have a Windows machine to test it on, so it may need some modifications in order to work.
Good luck !
Related
I have some files in a USB drive which need to be copied to multiple computers. These files contain an executable which will use the other config files.
My issue is, for Windows 10 PCs, while the temp_folder gets created, none of the files get copied.
For windows 7 I was able to create a batch file which copied the files to the local drive and ran the executable using the config files.
The batch file contents were as below :
mkdir C:\temp_installer
copy ".\file_name" "C:\temp_installer"
<rest of the code>
I have tried using xcopy and robocopy, but still see the batch file run and just stop at creating the folder. The same issue isn't observed in Windows 7.
Has someone tried this or can someone tell me what I might be doing wrong?
This would be a better option, we do not need to be concerened about permission issues on the root of C:
#echo off
cd /d "%~dp0"
set "inst_dir=%temp%\temp_installer"
mkdir "%inst_dir%">nul 2>&1
for %%i in (*) do if not "%%i"=="%~nx0" copy /Y "%%i "%inst_dir%"
:# When completed, we can call execute the files from "%inst_dir%"
The for loop is not needed to be honest, I am only doing it to not copy the .bat/.cmd file itself to the folder as there would be no need for it there.
Or even simpler, without having to do all the above, you could just use robocopy
#echo off
cd /d "%~dp0"
robocopy /MIR .\ "%temp%\temp_installer"
Powershell is your friend here, try this:
Copy-Item E:\Document\ C:\Temp\Document\ -R
Works great for me and it even creates destination directory, also Copy-Item has alias cp and copy.
If you running some sort of script, you might have issues with Execution-Policy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6
We have a file share that has a directory containing all of our build version direcotries named like this
WebApp_20140702.1 first number being date second number being the build count for that date
these are then contained in the following directory
\\server\share\product\
What i need to do from a virtual machine is create a batch file that can check the target location on my vm ie. c:\product\ see if it has the latest version from the network share either by comparing the file names or dates, then copy the new version and delete the old if necessary.
So far i can copy the folder over using xcopy but that's about the extent of my dos/batch file knowledge iv had a look around for a while but haven't been able to see anything that i can use
This is what i have so far, as you can see though i dont know how to do the comparison between the two directories as explained above.
xcopy "\\server\share\webapp" "c:\users\username\desktop\webapp" /E /K
I did try to use just /D at the end and just copying the directories from \\server\share\product\ that had a later date than the target but it ended up just copying the whole directory.
EDIT : to make my self clear
i need to find out if i have the latest sub directory but no matter what i do it always copies all the sub directories from \\server\share\product\
ie. the \\server\share\WebApp directory will have the following sub dirs
..\WebApp_20140628.1\
..\WebApp_20140628.2\
..\WebApp_20140703.1\
and my vm will have the directory
c:\product\WebApp_20140628.2\
Now i need to be able to go into the file share see that it has a more up to date subdirectory i need to copy that directory to my vm and then delete the older one from my vm so i would then have
c:\product\WebApp_20140703.1\
OK i eventually found another question that wanted to do a similar thing and the answer worked exactly as i wanted it
Question can be found here: How to get the most recent file using a batch script in windows
i had to use xcopy instead of the copy used in the answer for the above question. here is my solution as well in case anyone needs something similar
(z is the mapped version of the network share i talk about in my question)
pushd "z:\WebApp\"
for /f "tokens=*" %%a in ('dir/b /od') do set newest=%%a
xcopy /e /k "%newest%" "c:\product\"
popd
im not sure if i actually need the popd command as i believe it just goes back to the directory set in the pushd command
so far I have used Tortoise SVN to commit and update folders under version control. When I commit I check "all" in the GUI dialog so that deletions as well as additions are committed.
Now I have more and more folders under version control and I would like to have a batch file for committing and updating all of them.
So far I have experimented with the command line and found this:
svn add . --force
svn commit -m"Adding missing files"
This adds new files but does not reflect any deletions.
Could you please help me with the batch files? It would make my work a lot easier but I am really too unexperienced with SVN/batch files to do this on my own...
I use Win7x64 and Tortoise SVN 1.7.12 with the command line extension.
Thank you!
I think I figured something out using gammay's and this input:
cd "C:\Users\User\Desktop"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\?"`) do svn add "%%i %%j"
for /f "usebackq tokens=2*" %%i in (`svn status ^| findstr /r "^\!"`) do svn delete "%%i %%j"
svn commit -m "Commit via Batch"
And
cd "C:\Users\User\Desktop"
svn update
and repeatedly for different paths!
Thank you :)
Firstly, which svn command line tools do you use? You can use CollabNet for 'svn' commands.
Secondly, to delete files, you need to checkout existing files from svn, then use svn delete and then svn commit.
Your question is not clear - if this doesn't answer your question, please provide a few more details.
Edited to answer asker's requirement (in comments below):
OK. What you want is a script which will find the new files in the folder and add them to SVN automatically and find deleted files in folder and delete them from SVN too. I can tell you this is a dangerous as undesired files can get added/deleted.
Still, if you want to go ahead with this script this is what the script can do:
Run svn status which displays missing (deleted) files and unknown (to be added) files
! FileA [Missing - deleted]
? FileD [Unknown - to be added]
Parse the output to find the ! files and run svn delete on these files
svn delete FileA
Parse the output to find the ? files and run svn add on these files
svn add FileD
svn commit
This commits the above deleted & added files and also any modifications.
If you do not want to commit modifications, commit individual added/deleted files
I'd like to write a small build helper tool that shall read some properties of the current Git working directory, like the last commit hash, whether there's modified files and so on. I found that it is easier to use the installed Git binaries instead of reading the .git directory with its compressed files in an unknown format. But my tools must be as portable as possible. It's intended for .NET applications, so the only requirement should be .NET 2.0 or newer.
Now how can I find the path where Git is installed? There's a default one that is used if the user has just clicked through the Git installer. But it may be different. And when I see all the programme files in git/bin, I really don't want that to be in my %PATH% (which other tools like TortoiseGit don't seem to require, too). I haven't found any path clues in the registry.
What algorithm could I use to find Git, that is not a full file system scan? (Did I already say it needs to be fast?)
If you are inside of (or if you can open) your git bash shell, you can use pwd -W
$ cd / && pwd -W
C:/Program Files (x86)/Git
(I know, this is probably not what you want, and it's quite elementary, but I spent some time to find this, and perhaps it's useful for other people).
I'm using the following batch file to find out where Git for Windows has been installed:
#echo off
setlocal enabledelayedexpansion
rem Read the Git for Windows installation path from the Registry.
for %%k in (HKCU HKLM) do (
for %%w in (\ \Wow6432Node\) do (
for /f "skip=2 delims=: tokens=1*" %%a in ('reg query "%%k\SOFTWARE%%wMicrosoft\Windows\CurrentVersion\Uninstall\Git_is1" /v InstallLocation 2^> nul') do (
for /f "tokens=3" %%z in ("%%a") do (
set GIT=%%z:%%b
echo Found Git at "!GIT!".
goto FOUND
)
)
)
)
goto NOT_FOUND
:FOUND
rem Make sure Bash is in PATH (for running scripts).
set PATH=%GIT%bin;%PATH%
rem Do something with Git ...
:NOT_FOUND
I should be straight forward to do something similar in .NET. Just remember that you have to explicitly check the 32-bit branch of the Registry if you're on a 64-bit Windows.
Edit: Git for Windows 2.6.1 now additionally writes the CurrentVersion, InstallPath and LibexecPath values to the HKEY_LOCAL_MACHINE\Software\GitForWindows key.
If you are in Windows 8 and above here are the steps that you can follow.
go to your start screen and search for git.exe
In the search result right click on the Git Gui/ Git Bash icon and select Open File location
You will be taken to a flder where the shortcuts will be located. Right click on the shortcut nd select properties
the file location can be found in the Target field
For me it was "C:\Users\\AppData\Local\Programs\Git\cmd\git-gui.exe"
Hope it helps
You can also open Git Bash and type where git. It will return the path where Git is installed on your machine.
git --man-path gets you to [base git installation dir]\mingw64\share\man. git.exe is at [base git installation dir]\cmd.
look in the registry under: HKEY_CURRENT_USER\Software\Git-Cheetah
Ancient question, but if you're installing git through through the standard installer, one way to get where its installed is by asking the registry:
In powershell:
(Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\GitForWindows).InstallPath
This returns:
C:\Program Files\Git
I'm trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this:
If file is in both source and destination and they are different, source file will be copied
If file is in both source and destination and they are the same, nothing will be copied
If file is only in the source, source file will be copied
If file is only in the destination, destination file will be deleted.
I'm still new to shell scripting and I'm not sure how I could implement this. Any ideas? Windows batch scripts would be better, but shell scripts that run on Cygwin are also fine.
Take a look at rsync tool - it was designed to minimize traffic during files synchronization.
Also, probably "cp" with "-u" argument will be useful:
-u, --update
copy only when the SOURCE file is newer than the destination file or when the destination file is missing
For windows batch scripting xcopy (native to windows) or robocopy (a free download in windows) both work extremely well.
An example xcopy script (in a .bat file):
#echo off
:: /L = list only.
:: /v=Verify, /y=No prompting /s=subdirs /z=Network mode (supports bad)
:: /i=Tells xcopy dest is folder /f=Display names /d=Copy only changed
echo Backing up projects...
xcopy e:\projects h:\projects /V /Y /S /Z /I /F /D
It will even support orphaned files (if you delete something from your source you no longer need a copy in the backup). Xcopy is typically fine for your needs until you deal with sync between NTFS and Fat32 file systems - the later only has a 2 second resolution and problems with daily savings time so you occasionally run into issues: (a) on time change day you might not get a backup of a changed file - depends on change-regularity of course or you might get a backup of all files even though none have changed (b) because of time resolution some files may backup even though they haven't changed.