I need to move a directory recursively to a new location, and rename the directory. Do I just use XCOPY to move the directory, then run the RENAME command on it (or vice versa) or is there a better way?
Try xcopy /E sourcefolder destinationfolder\newname\. If the folder "newname" does not exist yet, the trailing backslash suppresses the question whether you mean a file a directory. Answering file is not what you want.
Related
I have .bat file like this:
xcopy "C:\sourcepath\sourcefoldername" "C:\resultpath\sourcefoldername" /E
It copied sourcefoldername from C:\sourcepath to C:\resultpath. However, when I run it, if there's already C:\resultpath\sourcefoldername, it asks me if I want to replace all of its contents (I need to enter A). If there's no C:\resultpath\sourcefoldername it asks me if sourcefoldername is a file or directory (I need to enter D).
Is there a way to include answers in the code so that no input from me would be required?
The "\" character at the end of the destination directory tell to xcopy that the destination is a directory (an then xcopy don't ask you).
The /Y switch tell to xcopy to override the file without ask for a confirmation.
xcopy "C:\sourcepath\sourcefoldername" "C:\resultpath\sourcefoldername\" /E /Y
Currently looking to copy and rename a file from a C:Drive source to a G:Drive destination by using a batch file. Currently have the following code:
robocopy C:\Users\abronk04\Desktop\Test G:\Users\abronk04\Desktop\Backup /e /purge
ren G:\Users\abronk04\Desktop\Backup accessbackup.jpg backup.jpg
The file will successfully copy, but there is no rename. Do I need to specify a file I am looking to rename? My batch file will copy an entire folder to another destination, unsure if that is the problem here...
I think you ren syntax is not correct.
Maybe try the following after copying the directory
pushd G:\Users\abronk04\Desktop\Backup
ren accessbackup.jpg backup.jpg
popd
This way you will temporarily change your working directory to the sink-path and then change it back
XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" ".\"
is the command right now. Which tell that the directory to copy files is at same level where the sln is.
My Question is: I want to copy the files to a directory which is one level above the solution directory. How the command should be?
If you are trying to change the destination dir, and make it one level up, try putting two dots instead of one:
XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" "..\"
I have a file, lets call it EXAMPLE.DBF
The location of this file is C:\EXAMPLE.DBF
Now I would like to copy this file into multiple folders at another location.
These folders are dated Sub-directories so they are named 20140101 - 20141231 and their location would be in d:\bootd\hello\20140101 - 20141231
Not only that but a file named EXAMPLE.DBF already exists in the folders...so it will ask to Copy and Replace.
I will need c:\EXAMPLE to copy and replace the existing EXAMPLE.DBF in 365 folders (20140101-20141231) in a different location.
If anyone could help me out with this I will be truly grateful.
Directly from the prompt,
for /d %a in (d:\bootd\hello\2014*) do copy /y C:\EXAMPLE.DBF %a\
Will copy C:\EXAMPLE.DBF to each directory of d:\bootd\hello\ which matches the pattern 2014* (ie. simply starts 2014), replacing any existing example.dbf in that subdirectory, if that is what you want to do.
To suppress the 1 file(s) copied messae generate for each, simply append >nul to the above line.
Just a small addition to #Magoo's answer;
in case the destination folders have spaces in their names, use double quotes like this:
for /d %a in (d:\bootd\hello\2014*) do copy /y C:\EXAMPLE.DBF "%a\"
and as pointed out by #ian0411, in case source folder has spaces in its name, use double quotes like this:
for /d %a in (d:\bootd\hello\2014*) do copy /y "C:\EXAMPLE.DBF" %a\
I want to create a batch file that moves all the files in this directory to its father directory. Like for example if I have a directory " Something " that contains files :
...New Folder/Something
And I want to move the files in " Something " to New folder.
Is there such a command?
Thanks a bunch :)
Presuming you're talking about Windows batch files, move *.* ..\ should do the trick.
Edit: For example, if you opened cmd, you could input:
cd C:\New Folder\Something
move *.* ..\
which would move all files in C:\New Folder\Something into its 'father' directory.
It is possible only if you don't have subdirectories, because move doesn't walk the subdirectories.
You can use xcopy with /E, however it will not delete the copied files and directories. Then you should use del ., but to delete the subdirectories you should call rd for each one, and that is not possible in batch files.