I want to move few files and folder available under a source folder to a destination Folder.
I am using :
move /y "%src%\" "%dest%".
This command is just moving files from the source but not the folders.
I need your suggestions. thanks in advance, i will appreciate your efforts.
the command move has no option to move recursively. So you can try to copy recursively with xcopy /s /y and after this delete recursively the source directory with del /s /q. Finally rd /s /q to delete the folders because del will only delete the files.
In my computer, with using command "move /Y src dest", the command works. Windows doesn't support the "move" command if the source folder and destination folder are in different volume. You can have a try.
Related
I need to be able to create a bat script to do 3 things:
Search for multiple specific filenames in a directory.
Find the most recently generated version based on each filename specified.
Copy that most file to a new dir.
I am very new to coding in general, so any assistance would be much appreciated.
So far all I have been able to do is figure out how to copy files from one location to another using the below:
xcopy /s c:\source\differentfilename1.csv d:\target\
xcopy /s c:\source\differentfilename2.txt d:\target
xcopy /s c:\source\differentfilename3.html d:\target
So far I have tried the following and its not copying the files over:
ECHO
CD D:\Data\
MKDIR D:\Data\CopyFilesHere
for /R %file in (Filename1.*) DO XCOPY "%file" D:\Data\CopyFilesHere
for /R %file in (Filename2.*) DO XCOPY "%file" D:\Data\CopyFilesHere
for /R %file in (Filename3.*) DO XCOPY "%file" D:\Data\CopyFilesHere
I have since noted there are subfolders I need to search through also.
i have a batch script that i want it to copy everything inside a specific folder to another but it only copy files it doesn't copy the sub folders.
thanks in advance
Here is how im copying the inside of the folder:
xcopy /s %FILETOZIP% %TEMPDIR%
Using XCOPY, the parameters should be at the end:
XCOPY source [destination] [options]
If any folders are empty and you want to include them, you will need the /E parameter instead.
Try the following to capture the entire directory structure:
xcopy %FILETOZIP% %TEMPDIR% /s /e
I want to use a batch file to synchronize 2 folders on Windows, and I'm using the xcopy command like this
xcopy /s /d <Original Folder> <Destination Folder>
It's working perfectly because I just want to overwrite only the modified ones, but I have 1 tiny problem, when I delete a file from the original folder, that file remains in the destination folder when i run the batch file, breaking the synching I want to achieve... I think this can't be done with xcopy, but I don't know which command I should use in case I delete a file in the original folder.
EDIT: This programs is for people who don't understant a lot of PC's so i don't want to install anything in their pc's. Just want a plain batch file to keep the 2 folders synchronized
SOLUTION: Thanks to Kuba Wyrostek I got to this command
robocopy <Original Folder> <Destination Folder> /e /purge
Thank you all for your time
xcopy has no such option. Your alternatives are:
rsync - http://rsync.samba.org
robocopy - http://technet.microsoft.com/en-us/library/cc733145.aspx
To refine your answer, you can simply do:
robocopy <Original Folder> <Destination Folder> /mir
/mir mirrors a directory tree (equivalent to /e plus /purge).
The XCOPY command for copying the updates from one folder to another is as follows:
C:\> XCOPY C:/SOURCE D:/DESTINATION /E /D /C /Y
The flags used in the above example have the following meanings:
/E causes all folders and sub-folders to be copied
/D causes a DATE comparison to be made, only copying items that are newer than the DESTINATION item. If the DESTINATION is older, or does not contain the file, then it will be copied.
/C tells XCOPY to continue if it encounters an error - typically errors occur with read-only files, or files that have protected permissions
/Y tells XCOPY to suppress prompting you for confirmation, which is necessary if you intend to create an automation script or scheduled task
I know this is old, but I have a question. Can this not be done with the correct xcopy commands.
Folder 1: c:\workingFolder\"contents here"
Folder 2: d:\workingFolderSync\"contents here"
Batch file below
xcopy "c:\workingFolder\*.*" "d:\workingFolderSync\" /i /s /d /y
xcopy "d:\workingFolderSync\*.*" "c:\workingFolder\" /i /s /d /y
pause
( I usually remove the pause after i test and know the batch works. )
But this will only copy contents from the folder to the other if its newer.
Then it looks in the destination folder and copies contents from destination back to source if it is newer. This reproduces what syncing does, except for the in real time monitoring of modified files. Creating a proper task schedule can actually implement running this command at specific times to almost perfectly reproduce syncing. You can also run this before modification on a machine and after modification on a machine. Even doing the same thing on a second machine if your using a network drive to sync.
Your method will have two main problems:
Files deleted from one folder will be reinstated by the copy left in the other folder the next time you run your xcopy
Renaming files can cause chaotic results.
So this is what I have so far. The problem I'm having is it archives the file to 7zip and when I try to tell it to move this file it says it's not there. I'm not sure if there's an easier way to move, zip, and rename a file and move it again to another folder.
#Echo Off
xcopy "\\READYSHARE\USB_Storage\Address Book\Address Book" "C:\Users\Service Department\Desktop\Zip"
7za a –tzip "C:\Users\Service Department\Desktop\ZIpped" "C:\Users\Service Department\Desktop\Zip" /s /e
pause
It is always advisable to read the documentation of the commands to use before creating a batch file.
xcopy (Microsoft Windows XP documenation, easier to read) or xcopy (Microsoft TechNet article)
Documentation for 7-Zip standalone command line tool 7za is installed together with 7-Zip in program files folder of 7-Zip. The file to view is 7-zip.chm, a Windows help file.
The switches /s and /e belong to command xcopy, but are appended to call of 7za. /s is for copying also subdirectories, but not empty subdirectories. /e is for copying also subdirectories including empty subdirectories. It is possible to specify both, but usually just /e needs to be specified to copy a directory tree completely using xcopy.
To recursively archive all files and folders of a folder with 7za the switch -r must be used according to 7-Zip documentation.
#echo off
%SystemRoot%\System32\xcopy.exe "\\READYSHARE\USB_Storage\Address Book\Address Book" "%USERPROFILE%\Desktop\Zip" /E /I
"%ProgramFiles%\7-Zip\7za.exe" a –tzip "%USERPROFILE%\Desktop\Zipped.zip" -r "%USERPROFILE%\Desktop\Zip"
pause
I have not executed this batch file, but it should work if path to 7za.exe is correct on your computer.
It's been a long time since I've created any batch files.
What I'm trying to do is delete an entire folder, and then copy another folder (and it's sub folders and files) to the location where I deleted the original file (this is a backup process).
I've run into three problems:
the batch file prompts me when it runs the delete operation and this needs to happen "behind the scenes" so I can't be prompted.
the del "c:\my folder location\myfoldertodelete" only deletes the files within that folder
the copy "c:\my other folder location\myotherfolder" "c:\my folder location\" only copies the files within that folder, not the sub directories.
I assume I need xcopy or something but I've never used that. If anyone can help me jump through these three hoops, I'd greatly appreciate it.
edit: (updating with the copy command that isn't working
C:\Users\Chris>copy /s "C:\Users\Chris\Documents\Visual Studio 2010\Projects
\new project" "D:\VS 2010 projects\Projects\"
The syntax of the command is incorrect.
echo y | rd /s c:\directory.to.be.removed
copy /s c:\source c:\destination
echo y | rd /s C:\Users\user1\Documents\Dest
echo d | xcopy /s /y "C:\Users\user1\Documents\Src" "C:\Users\user1\Documents\Dest"
where:
"C:\Users\user1\Documents\Src" is the Source directory and
"C:\Users\user1\Documents\Dest" is the Destination directory.