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.
Related
I have a question, I have the following paths:
C:\Vendita\folder1\files and subfolders
C:\Vendita\folder3\files and subfolders
C:\Vendita\folder3\files and subfolders
I want to delete (using win shell commands), for each subfolder (C:\Vendita\folder1,C:\Vendita\folder2,C:\Vendita\folder2...) all files and subfolders, but keeping folder1, folder2 ecc...
I try this:
for %D in (C:\Vendita\) do del *.* /s /q
but it deletes all files and keeps all subfolders.
Can you explain me what is wrong?
Thank you
Why don't you use rmdir? Your command only removes files with a certain filename.
I read Windows batch command to move all folders in a directory with exceptions but this did not work with wildcards. I want to move all folders (!), not files, inside a folder into 2010.
I have 2010-01, 2010-02, 2010-03, ... but also 2011-01, ...
How can I move (!) all folders including files inside 2010. For files this works perfectly with
move *2010* 2010
where the second 2010 is the destination folder.
Probably robocopy is the right tool for you. You can use the following command to move all directories and files from the directory source_dir into target_dir, preserving the directory structure:
c:\robocopy source_dir target_dir /S /MOVE
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 was wondering if there is a quick and dirty command that can copy all files in a directory and it's subdirectory to another folder. The destination folder will have no subdirectories just all the source files.
Also as an added bit of fun, in case there is a file name conflict, not to overwrite but to rename the destination file with something unique, maybe append _1 to the filename?
This will copy the files and prompt if there is a filename conflict.
The third party tool XXcopy has the ability to flatten a directory tree and handle filename conflicts.
#echo off
for /r "d:\folder" %%a in (*) do copy "%%a" "E:\target folder"
To copy for instance all files from the current folder and its sub directories to the parent folder of the current folder you can use:
for /r . %a in (*) do copy %a ..
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.