Meaning of . (period) when copying in a batch file - batch-file

I'm looking through some batch files out of curiosity/for the purpose of learning and I'm seeing one thing I haven't been able to quite make sense of. I'm sure it's something simple, but I don't want to simply run this file, for obvious reasons.
Similar to the following lines:
copy /Y "\git\MyProject\bin\Release\MyLib-1.dll" .
copy /Y "\git\MyProject\bin\Release\MyLib-2.dll" .
copy /Y "\git\MyProject\bin\Release\MyLib-3.dll" .
I know what /Y does from reading online, but what is the . doing? My first assumption was that it meant to copy the file to the current directory, but I was under the impression that's what the %cd% variable is for so I'm not quite sure.

The period refers to the current directory, from which the batch file was called. So, in this case, the 3 DLL library files will be copied to the current directory that called this batch script.
The /Y parameter will force them to be overwritten, if they already exist in the current directory.

It means the current directory, so in your copy-commands it means that you are copying the files to the current directory

Related

How to get a real time progress bar for copying a large file (2.2 GB) with a batch file?

I'm making a batch script, but I don't know on how to make a real time progress bar for copying a large file.
Could you help me out?
I'd rather use the standard COPY in batch file, not XCOPY or ROBOCOPY.
My current code is (not all of it):
copy %userprofile%\desktop\target.ipsw %TMP%\downgrade\target.ipsw
The Esentutl /y option allows copyng (single) file files with progress bar like this :
For the sake of your directories, this is what the code will look like:
esentutl /y "%userprofile%\desktop\target.ipsw" /d "%TMP%\downgrade\target.ipsw" /o
Please keep in mind that there are a few limitations to the esentutl command:
You can only copy one file at a time.
The /y syntax was presented in windows vista.
You cannot overwrite files. (You will have to have batch check the destination beforehand and if needed, delete the previous file)

Move all the contents of a folder with a .bat

I using the following syntax to move all the files inside a folder, to another folder
set OGGI=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
move C:\DOCUMENTALE\dms_in\*.* C:\DOCUMENTALE\dms_backup\%OGGI%\
This syntax is working with files, but which syntax I have to use if I would move also folders?
The problem is that this path C:\DOCUMENTALE\dms_in\ contains folders automatically generated. I don't know how many folders there are in or which names they have.
I did some attempt but I didn't figure it out
Thanks
An solution to this is to use the command ROBOCOPY instead. It is arguable more flexible.
ROBOCOPY <source> <destination> /MOV /E
/MOV will move the file/folder in question instead of the default copy.
/E will allow you to mirror the directory structure of the target folder if there are any folders within the folder including empty ones
Note: you may need to use quotation marks for the source and destination if either path contains spaces.
Another neat feature of Robocopy is that it will show you what is it doing; what is being copied and too where, how long it takes etc. And if it goes wrong due to paths for example, it will tell you.
You can also browse ss64.com for more help and examples to fit your needs.

Robocopy directory and its contents

I feel like this should be straightforward, but I've been struggling with this for long enough that it's making me pull my hair out. I'm writing a couple batch files to do automated file syncing and some cleanup between a few different drives. When copying a directory I use the following command.
robocopy %datestr% %2 /E
What this line of code does is take the contents of the path specified by %datestr% and copies it to the path specified by %2. I need it to copy the directory itself (and its contents, of course) to the path specified by %2. I looked at the Robocopy docs and I can't seem to find a simple way to do this.
EDIT: I fixed the problem I was having, but it feels more like a hack than a fix. Appending the source folder to the destination path 'copies' it, as such:
robocopy %datestr% "%2/%datestr%" /E
I don't love the fact that this isn't truly 'copying' it, but just making a new directory with the same name. For what I'm using this it will work fine, but I still feel as if there must be a better way to do so.

Copy file to several multiple folders - Batch files

How can I copy file to multiple folders using batch files.
I success to copy one file to one folder.
Regards,
Ramzy
Like this? Seriously, just add a line for each folder.
copy C:\file.txt C:\dir1\
copy C:\file.txt C:\dir2\
copy C:\file.txt C:\dir3\
copy C:\file.txt C:\dir4\
Yes, this is an old thread, but still, i spotted some code that definitely needs an improvement!
Here is a much better movement code!
copy C:\Folder file is in (Here you can specify certain extension/keyword) C:\destination\
move /-y "SOURCE FOLDER AND DRIVE(specific keyword/extension)*" "DEST FOLDER AND DRIVE"
That way you dont have to write endless lines of code!
-Logan

How to say no to all "do you want to overwrite" prompts in a batch file copy?

By default, copying from the command prompt will prompt you to overwrite files that already exist in the target location.
You can add "/Y" to say "Yes to all" replacements.
But how can you say "No to all" ?
In other words, I want to copy everything from one directory that does not already exist in the target.
The closest thing I see is the XCOPY argument to only copy things after a specific mod-datetime.
Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?
echo "No" | copy/-Y c:\source c:\Dest\
You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.
Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.
Here's a workaround. If you want to copy everything from A that does not already exist in B:
Copy A to a new directory C.
Copy B to C, overwriting anything that overlaps with A.
Copy C to B.
I use XCOPY with the following parameters for copying .NET assemblies:
/D /Y /R /H
/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.
/R - Overwrites read-only files.
/H - Copies hidden and system files also.
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so...
xcopy {Source} {Destination} /E /D
Will copy without overwriting to pickup those files that are new or maybe failed before for some reason.
Just try it, it works.
I expect xxcopy has an option for that.
Bingo:
http://www.xxcopy.com/xxcopy27.htm#tag_231
2.3 By comparison with the file in destination
The switches in this group select files based on the
comparison between the files in the source and those in
the destination. They are often used for periodic backup
and directory synchronization purposes. These switches
were originally created as variations of directory backup.
They are also convenient for selecting files for deletion.
2.3.1 by Presence/Absence
The /BB and /U switches are the two switches which select
files by the pure presence or absence as the criteria.
Other switches in the this group (Group 2.3) are also
affected by the file in the destination, but for a
particular characteristics for comparison's sake.
/BB Selects files that are present in source but not in destination.
/U Selects files that are present in both source and destination.
-Adam
this works fine
no | cp -rf c:\source c:\Dest\
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
Try this:
robocopy "source" "destination" /e /b /copyall /xo /it
Copy that line into notepad and save as a .bat file. Run the file and it will copy everything from the source to the destination. When you run it again it will not replace files that are identical. when you change or a file changes it will replace the file at the destination.
test it out. I created a .txt file with a few works, ran the script, change the wording on the .txt file and ran the script again, it replace only the change file from the source.
/e=Copies subdirectories. Note that this option includes empty directories
/b=Copies files in Backup mode
/copyall=Copies all file information
/xo=Excludes older files. (this is what prevents it from copy the same file over and over)
/it=Includes "tweaked" files. (this will allow the copy and replace of modified files)
Thanks for this. I am using the command line utility AzCopy (v 3.1.0.93) to move ~1 million files from my local PC to my Azure blob storage. I've got some duplicates and cannot babysit the copy to answer each prompt and don't want to re-upload the same file.
The AzCopy utility offers a /Y command to suppress the confirmation prompts but ends up telling it to overwrite the destination file. Going this route I was able to get it to NOT re-upload the file. However, it does seem like a bit of a hack since it is not actually answering the prompt with "No", instead I get the error "No input is received when user needed to make a choice among several given options." but does not upload the file.
Here is the command I used: echo n | AzCopy /Source:"{file path}" /Dest:"{blob storage URL}" /DestKey:{key}
Hope this helps the next guy.
Depending on the size and number of files being copied, you could copy the destination directory over the source first with "yes to all", then do the original copy you were doing, also with "yes to all" set. That should give you the same results.
We used "robocopy" through "invoke-command" to copy a huge amount of VMs in our environment. We've discovered that "robocopy" unexpectedly exits sometimes and the whole proccess goes to down. So we've decided to use "xcopy". Now we're checking it's work and to "create" "Not for all" option we use that function (powershell):
function gen_long_no([string]$path) {
$result = ""; Get-ChildItem $path -Recurse | ? { if ($_.PSIsContainer -eq $false) { $result += "n" } };
return $result
}
Maybe helps somebody.
Adding the switches for subdirectories and verification work just fine.
echo n | xcopy/-Y/s/e/v c:\source*.* c:\Dest\

Resources