Can we use robocopy to copy files instead of folders - windows

I need to copy a particular file from one location to another., Is it possible to use robocopy to do same.

Whilst Robocopy can be persuaded to copy a single file it is much simpler to use copy or xcopy.

Yes, either wrap it in an an exec or use the Robocopy that is wrapped as part of the msbuild extension pack see:http://www.msbuildextensionpack.com/help/4.0.3.0/index.html
You want to use the MSBuild.ExtensionPack.FileSystem.RoboCopy task.
Makes copying much quicker.

I was trying to figure this problem out. I finally found my own solution and maybe it will help.
I noticed that the syntax used to select the entire directory could be used to select a single file.
ROBOCOPY "*" "Directory source" "Directory Output unc path or non"
The above code will copy everything from the directory source folder to the directory output path.
Let's say you only wanted to copy 1 file from the directory source named "test.txt"
In order to do that use the following code:
ROBOCOPY "*test.txt" "Directory source" "Directory Output unc path or non"
Thats about it. It works really well and will only copy the file name you want.
Alternatively you can use
ROBOCOPY "*.txt" "Directory source" "Directory Output unc path or non"
to copy out all text documents from the directory source.
Similarly this will also work with any .ext
.zip .exe .txt .pdf etc..
I signed up to answer this question with a better method. Let me know if I succeeded.

Related

Syntax issue with copying zip file from one folder to another with robocopy

I would like to use robocopy to simply copy a zip file called Sample.zip to a local folder called HERE.
This is currently my code:
ROBOCOPY C:\Users\%username%\Desktop\HERE Z:\Sample.zip
I just get an error saying invalid directory.
What is the issue with my syntax here?
While I respect that you want to use robocopy and iminiki's answer, I won't recommend it. robocopy is mainly used to copy directory structures and/or files remotely although robocopy means Robust File Copy. I use copy in my batch files for best practice:
copy "Z:\Sample.zip" "C:\Users\%username%\Desktop\HERE"
which copies Sample.zip file from Z: to C:\Users\%username%\Desktop\HERE. Note that quoting both paths is quite important and a very good practice; do it always.
You should try separating the file from the origin directory. Try this one:
ROBOCOPY Z:\ C:\Users\%username%\Desktop\HERE Sample.zip

"Can't read file" when trying to Exclude directory in batch file

I've been stuck on this for awhile and could use some help.
I'm trying to copy a large folder from a mapped network drive (A:) onto my local PC. I also need to exclude a subdirectory on that drive path called "Images". My current code (backup.bat) is below:
cd %HOMEPATH%\Desktop\%mydate%
xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:"A:\PROGRA~2\QuadTech\INSPEC~1\Images\"
Error I keep getting:
I've tried shortening the path with "dir /x" and I am sure the path name is correct. Also note that I need quotations as there are spaces in the PATH name.
Why am I getting errors when trying to Exclude this directory??
ANSWERED
I now have my Exclude statement point to my desktop where it reads a list of strings in a txt file.
xcopy "A:\PROGRA~2\QuadTech" 121\ /e /EXCLUDE:C:\Users\QuadTech\Desktop\excldelist.txt
Txt file contents:
\Images\
This is happening because the /EXCLUDE option does not specify files to exclude.
It specifies files containing lists of files to exclude.
More info by typing xcopy /?, though I am sure you know that.
(I know, I missed it too in the beginning; sometimes it is just a matter of having a second pair of eyes.)

Batch file to recursively find files named a specific name and move to a directory

So, I was hit with the Cryptowall 3.0 ransomware virus. After decryption I am still left with a large amount of DECRYPT_HELP files in .txt, .html, .png and Windows Shortcut formats.
I need a batch script to recursively find the files containing the name "DECRYPT_HELP" regardless of its' extension and move those files into a directory which I will delete.
I am a Linux guy, so I can't FIND and GREP my way through this. Any assistance would be appreciated.
You can find the files using
dir /s *decrypt_help*
dangerous command follows
del /s *decrypt_help*
will delete all of those files. use with extreme caution

batch code to transfer all files and folder from location(s)

I am looking for a batch code that will transfer all files inside folders. Then it will transfer them into the location.
D:\Transfered Files\
And it will keep the exact folder/file names.
For example I want everything transfered from
C:\Users\
C:\Program Files\
I have tried this and it works:
xcopy source destination /Y
Just save this in a batch file of course change the directories as you see fit.
Also note that the '/Y' parameter says that if files exist in the destination overwrite them. If you remove it, it will ask you about each file separately.
If you think this isn't good enough you can use robocopy:
robocopy source destination
Again you need to change the source and the destination directories and put the line in batch file.
I have used both and both works 100%. I have a windows 7 home premium 64x.

creating a batch file

I would like to creat a batch file that will recognise folders date moidified in a network drive and then copy them to another network drive
while I was searching I found way to do that to files, but I need it for folders
I didn't find a way to do that
Sadly, you didn't say which method you'd found. If that method selects the files using a DIR.../a-d... structure for instance, then omit the - before the d and directories matching the selected pattern rather than files would be processed.
To create a batch file just get notepad++ and save as a .bat, is that what you meant? or did you want a certain type of Batch file, because I didn't think there was another type unless you count Command prompt and Notepad++ different?
Forfiles may be helpful, or robocopy
This will create a mirror backup in the destination folder. If files are deleted in the source then they will also be deleted in the destination.
#echo off
robocopy "\\172.172.172.10\folder" "\\172.172.172.2\destination" /mir

Resources