I have folder C:\Folder. In this folder I have thousands of subfolders. I want to target only those ending in cv. In these subfolders I have a file and another subfolder. C:\Folder\SubFoldercv\cv. I would like to move all the files in those subfolders to the second subfolder using CMD in Windows 10.
(So from C:\Folder\SubFoldercv to C:\Folder\SubFoldercv\cv).
Use for /D to find the directories ending with cv, and use robocopy to copy (or robocopy /mov to move) all files from a folder to another:
#echo off
FOR /D %%G IN ("C:\Folder\*cv") DO robocopy /mov "%%~G" "%%~G\cv" "*"
I'm currently not on a windows machine so I'm not able to test it but it should do the trick and move all files to the cv subfolder for all folders ending on cv.
If you want to use it on the command-line, use:
FOR /D %G IN ("*cv") DO robocopy /mov "%~G" "%~G\cv" "*"
instead.
EDIT: After the OP tested it, he has confirmed that it works.
How to do?
subfolderHolder = uploads
FOR /D %%i IN ("%MoveDirSource%\*\%subfolderHolder%\*") DO ROBOCOPY /MOV /E "%%i" "%MoveDirDestination%\%%~nxi"
but the wild card is not working
Related
I have a folder of music files that I have added/updated ID3 tags (the source folder). I also have another folder containing some of these files (the destination folder), and I want to overwrite/update these by copying only files from the source folder that exists in the destination folder.
I tried using this xcopy command, which does the job it seems as it copies only files that exist in destination folder. But upon inspection, the relevant files in the destination folder are still the old ones which do not have ID3 tags. I cannot figure out why the copied files did not overwrite the old files:
cd /d "C:\Users\lenovo\Desktop\source"
for %x in (*) do xcopy "%x" "C:\Users\lenovo\Desktop\destination" /L /U /Y /I
xcopy /? says about the /L switch:
/L Displays files that would be copied.
However, by https://ss64.com/nt/xcopy.html:
/L List only - Display files that would be copied.
The latter is right!
Removing the /L option weirdly fixed the problem. The files were now correctly copied:
cd /d "C:\Users\lenovo\Desktop\source"
for %x in (*) do xcopy "%x" "C:\Users\lenovo\Desktop\destination" /U /Y /I
I am trying to create a .cmd script to archive my project folders in SharePoint using robocopy. The issue that I am having is that there are many folders in the source dir that I do not want to archive.
#set sourcepath=\\foo\bar\p_*
I prepended my project folders with 'p_' so I could set my source variable to /foo/bar/p_*. This way I would pick up each folder and all of it's files without grabbing all of the other 'non-project' folders. Obviously this did not work.
Is there a way to pull this off without having to build a folder list that I need to manage every time a project folder is added?
Your input is appreciated
You can get the list of directories with a command.
dir /A:D /B /r p_*
Then you can use a FOR loop to start robocopy for each directory.
SETLOCAL
SET SOURCEDIR=\\source\...
SET DESTINATIONDIR=\\dest\...
CD %SOURCEDIR%
FOR /F %%G IN ('dir /A:D /B /r p_*') DO robocopy "%SOURCEDIR%\%%G" "%DESTINATIONDIR%\%%G" /e
Using Robocopy to merge two user home directories shares from two different servers to a new server, but can't use /purge to mirror deletes because it will delete the other servers stuff.
I need a way to enumerate the folder names from the users$ share on each server, and add it to both path statements in the command below, so I can purge at the Users subfolder level.
Robocopy command:
robocopy "\CurrentServer1\users$" "F:\Users" /E /B /COPY:DATSOU /R:1 /W:1 /MT /LOG:"C:\RobocopyLogs\MirrorUsers1.txt"
Can a batch or vbscript do that?
Thanks in advance for any help you can provide.
You could merge both source folders into a staging folder, then mirror that staging folder to the destination folder:
mkdir C:\staging
robocopy \\server1\src C:\staging /e /b ...
robocopy \\server2\src C:\staging /e /b ...
robocopy C:\staging C:\dst /mir /b ...
rmdir /s /q C:\staging
I want to copy only directories (it's files and sub directories) within the current directory from a command prompt.
I've already copied all the files in the current directory using this command.
copy * d:\copyfolder
I've tried these for individual folders. To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils* D:\Backup\utils /s /i
But couldn't find a way to copy only directories.
From the command line this should work to copy all folders with subdirectories and files:
for /d %a in (*) do xcopy "%a\*.*" "d:\copyfolder\%a\" /s/h/e/k/f/c
I've tried these for individual folders.
To copy a folder:
XCOPY C:\utils D:\Backup\utils /i
To copy a folder including all subfolders.
XCOPY C:\utils\* D:\Backup\utils /s /i
But this command can help, not overwriting any files.
XCOPY C:\utils\* D:\Backup\utils /s /i /d
I need to do a .bat copy of a .sh, I don't know much Windows cmd.
On Linux I could do
mv ...
or
rsync -a SOURCE/ DEST/ --remove-sent-files --ignore-existing --whole-file
but Windows "move" can't do the same
maybe there is a windows simple alternative, simpler and more performant than
for /R c:\sourceFolder\ %%G in (*) do ( move /Y "%%G" c:\destinationFolder\ )
Linux mv seems to update directories pointer, but the above Windows command will do hard stuff? I guess it's not a good idea for the big folders I need to frequently move
Robocopy did wonders for me:
robocopy c:\cache c:\cache-2012 ?????-2012*.hash /S /MOV
I used it to move all files with certain mask out of c:\cache and its numerous subdirectories.
The move command can move directories as well as files.
cd /d C:\sourceFolder
rem move the files
for %%i in (*) do move "%%i" C:\destinationFolder
rem move the directories
for /d %%i in (*) do move "%%i" C:\destinationFolder
I know this is an old thread, but since it does not have a correct answer I figured I'd tie it off.
The old DOS command to accomplish this is:
move <source directory> <destination directory>
So in the OP question:
move C:\sourceFolder c:\destinationFolder
The folder and everything in the folder (including sub-directories) will be moved.
XCOPY should do the trick, I use it it in batch files all the time
something like, if you're just trying to target .sh files
XCOPY /E /H /Y /C "%SOURCEDIR%\*.sh" "%TARGETDIR%"
Let me know if you have more questions
#echo off
setlocal
set DIR=
set OUTPUTDIR=C:\Documents and Settings\<username>\Desktop\sandbox1\output
for /R %DIR% %%a in (*.jpg) do xcopy "%%a" "%OUTPUTDIR%"
For recursive move in windows, a simple move command is ok. Here is the example, I think it would be helpful.
move D:\Dbbackup\*.dmp* D:\Dbbackup\year\month\
Where .dmp is the extension of the file that would be moved to the location recursive folder Dbbackup , then year, then month.