Windows bat move folder

Команда MOVE — переименование или перемещение файлов и каталогов

Команда MOVE используется для перемещения или переименования файлов и каталогов. Формат командной строки:

Перемещение одного или более файлов:

MOVE [/Y | /-Y] [диск:][путь]имя_файла1[. ] назначение

MOVE [/Y | /-Y] [диск:][путь]имя_папки новое_имя_папки

Параметры командной строки:

[диск:][путь]имя_файла1 — Определяет местоположение файла или файлов, которые необходимо переместить.

Назначение — Определяет новое местоположение файла. Назначение может состоять из буквы диска (с последующим двоеточием), имени папки или их комбинации. При перемещении только одного файла, можно указать и его новое имя, если хотите выполнить его одновременное переименование при перемещении.

[диск:][путь]имя_папки — Определяет папку, которую необходимо переименовать.

новое_имя_папки — Определяет новое имя папки.

/Y — Перезаписывать существующие файлы назначения без предупреждения.

/-Y — Предупреждать при перезаписи существующего файла назначения.

Ключ /Y может присутствовать в значении переменной среды окружения COPYCMD . Оно может перекрываться ключом /-Y в командной строке. По умолчанию используется предупреждение о перезаписи, если только команда MOVE не выполняется как часть пакетного файла.

move /? — отобразить подсказку по использованию команды.

move folder1 folder2 — переименовать папку с именем folder1 в folder2 в текущем каталоге.

move E:\test\folder1 E:\test\folder2 — переименование с указанием абсолютных путей.

move C:\file1.txt D:\ — переместить файл file1.txt с диска C: на диск D:

move c:\test\file1.txt D:\folder2\file2.txt — перенести файл file1.txt из каталога test диска C: в каталог folder2 диска D: под именем file2.txt

move C:\Folder1\*.* D:\Folder2\ — переместить все файлы из каталога Folder1 диска C: в каталог Folder2 диска D:

Реализация в ОС Windows данной команды не позволяет перемещать папки на другие логические диски.

move C:\folder1 C:\folder2\folder3\folder1 — переместить каталог folder1 из корня диска C: в подкаталог \folder2\folder3

При перемещении папки в несуществующий каталог он не будет создан автоматически и команда завершится ошибкой. Команда move не работает с файлами, имеющими атрибуты «скрытый » и «системный».

Move files and directories to another location

This tutorial explains how to move files or directories to another location on a Windows system.

Move files to another directory

Example: to move file ‘data.docx’ to the folder ‘d:\backup\folder’

You can also rename the file while moving it to the new location

We can’t move multiple files with single command. i.e the below command would not work.

This would give the error The syntax of the command is incorrect .

However we can use wildcards to move files in bulk. For example, if you want to move all text files from current folder to a new location you can use the below command.

To move all files starting with letter ‘A’, you can use below command.

Move directories

Example: To move the directory ‘data’ to ‘D:\data\folder1\’

1. Can we move multiple directories using wild cards like the way we do it with files?
No, wild cards does not work for directories. You get the below error

Читайте также:  Linux secondary ip address

2. How to specify the directories/files which have white spaces in the names?
You need to enclose the name of the file/directory in double quotes.

Errors

If you do not have write privileges on source file/directory or on the destination folder, you would get error as below.

Could some one point out why windows command line could not execute

move file1 file2 destinationDirectory ?

Because with the syntax the command is expecting, you told it to move file1 to file2 (which already isn’t going to work) and then gave it an argument of destination Directory, which it then has no idea what to do with, cause it isn’t a valid argument, in addition to the command you issues failing.

very helpful, I am missing one piece, I am trying to move all files from a “Camera Uploads” folder (dropbox) to another folder… not sure how to do a move involving all files inside a directory with a space… any ideas… “C:\Dropbox\Camera Uploads\*.*” doesn’t work… thanks!

i think this would do the trick
“C:\Dropbox\Camera Uploads\*”

hi,
can anyone suggest, how can I achieve below, via DOS command ?
I want to move all files and folders from source folder to destination folder.
e.g. C:\source\file1.txt
C:\source\file1.txt
C:\source\subsource\file1.txt

I want to move everything form C:\source form C:\destination ( like CUT from C:\source and PASTE into C:\Destination)

Thanks in advance.

If you want to copy all files from C :\ to destination you can use

move c:\> Source folder\*.* c:\destination folder

-move Just files not folders

if you to copy folder and files you can use XCOPY Command c:\xcopy *.* C:\ Destination folder

move -y “C:\source\file1.txt ” “C:\source\subsource\file1.txt”
pause

Can I use wildcard * to recognize the source and subsource directory in command line?

is there any window service which did the same work as you mentioned above. i.e transferring a file from one folder to another specified folder by a specific time interval in the background automatically. if you have some link regarding this please do share

There’s a pretty good wirte up on task scheduling on the windows club, check it out: http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7

Please suggest me how to move folders like 0123-03-000000001 to “Done” folder through batch file.

can I use batch file to execute command?
Thank you

wow! lots of examples for windows move command. Thanks for sharing.

Id like to create a script to move files of a size between let say 200 – 500MB from a specific location to another location.

Anyone know how to do this ? 🙂

Hey I would like to know how to move a folder or move files to a folder while naming the folder to Program Files and on the Desktop

I have a batch scrip that creates a sql dump then copies it to another server. I’m looking to move it so it is deleted from the directory originally created in. I tried the MOVE command but it doesn’t do anything. The script that works with just copying it is below anyone have any thoughts on how to modify this?

REM Export all databases into file C:\DB Backups\backup\docuware.[year][month][day].sql
“C:\Program Files (x86)\DocuWare\Internal Database V2\bin\mysqldump.exe” –all-databases –result-file=”C:\DB Backups\docuware.%TIMESTAMP%.sql” –user=admin –password=Toshiba1

REM Change working directory to the location of the DB dump file.
C:
CD \DB Backups

Читайте также:  Made to measure windows

COPY “C:\DB Backups\” “E:\DW_PROD\Database Backups\Toshiba Tamarac Internal”

HI, Please provide how to move directory in to anoterh locatp

Hi, could you please help! I keep getting a The filename, directory name, or volume label syntax is incorrect error.
MOVE /-y “\\XYZ-nas\active matters\ABC\Morning\D1\processed\PDF\008\Morning_0086126__*.pdf” “\\XYZ-nas\active matters\ABC\Morning\D1\processed\Loose\07. Rathburnadette Email\top\Inbox\FW: BGD (unknown)\”

Hi,
Can anyone help me to move the files from multiple folders to multiple folders?
Example: I have folders like folder1 and in folder1 I have file1 and file and folder2 in folder2 I have file 3 and file and the destination folders are folder 3 and folder4.
we need to move the folder1 files to folder3 and folder2 files to folder4 at a time not one by one.

i have about 200,000 files that i want to write a program to move them (by key word in file name ) to different folders

move all files with any of these words in the file name (shtf,prepper,prepping,survival,bushcraft) to folder shtf

thats an example…. sas, small basic, dos prompt any hints? tks

Any way to perform a bulk move of files based on a string found inside the file? e.g. this does not work for me
move findstr “StringToFind” *.xml D:\PROD\ExceptionFolder

Hi
I want to move files from one directory to another only the latest file names are like this filename20190904.csv. I want to move these from one folder to other and replace the files with latest. And also want to exclude one file from source folder. any help would be appreciated

Including how to move across a network drive would be useful

Move all the files and folders with CMD (BAT File)

I want to move all the files and folders inside the folder «C:\Foldertest\» into the folder «C:\Foldertest\target».

And whenever I run this command, it does this for all files and folders except for the «C:\Foldertest\target» folder.

1 Answer 1

RoboCopy would be the preferred method:

  • Note the trailing backslash in the source folder
    • Failing to include this would copy C:\FolderTest , rather than it’s contents
  • /E : Copy subdirectories, including empty ones
  • /ZB : Use restartable mode; if access denied use backup mode
    • Requires user to be added to Backup Operators group, else change to /Z
  • /MOVE : Move files and dirs (delete from source after copying)
  • /MOT : Monitor source; run again in X minutes, if changed
    • You could also utilize /MON:1
      • /MON : Monitor source; run again when more than X changes seen

Batch moving files to another folder/directory in Windows?

I am getting an error message to the effect of unable to move files to a single file. I am not trying to do this. What I am trying to do is move files from one folder to another folder (staging) and then deleting the original folder.

If you can show me a better way to do this since I am not doing this correctly.

Here is my .cmd file:

4 Answers 4

Personally, I would prefer XCOPY here since it has more options that may be useful, especially if you change the batch file, and then remove the old directory and files using a switch.

I would also dump the quotes unless there is an actual space in the file location or name. In your last move, you actually dropped a quote, and that would probably produce an error. Your last statement is also incorrect: You only put the quotes around the WHOLE command before switches, not portions of it. I added the switches I consider potentially useful: You can see what each does by doing an xcopy /? at a command prompt. I would also question whether your, in your last copy, if abc.htm is really in the root directory. check that, and edit accordingly, if necessary. Lastly, make sure you edit the user portion to reflect your username. I don’t know anything more about your last line since that is application-specific.

There are two solutions that suggest themselves to what you want to do. If you want to copy only the .js, .css, .htm, etc. files, go with the first solution. If you really want everything in the source folders, go for the second. Note that both give you the opportunity to make sure everything’s ok before deleting the source files. Also, it assumes that the target directory already exists.

How to move all files with specific extension from all subdirectories to their parent using CMD?

Folder c:\folder1 contains subfolder1 , subfolder2 , etc..

These subdirectories hold .pdf and .db files.

How can all the .pdf files be moved to c:\folder1 using the Windows command interpreter?

11 Answers 11

This worked for me:

In a .bat / .cmd file:

For direct input into a Command Prompt window (not PowerShell):

This command will copy recursively all *.pdf files from the source (and all of its subdirectories) to the target directory.

To exclude files in subdirectories omit the /r switch.

The outer for loop lists the sub-directories in the working directory, the inner for loop lists the sub-directories to move to the destination path:

This works best if DestinationPath is not a subfolder of the working directory, as it will try to move DestinationPath into itself.

To confirm the command before running it wholesale, start out just echoing the final move commands like so:

and copy/paste one of the results to run it and confirm it worked the way you expected. Then remove the echo and get moving.

There is another way to do this in Windows Explorer (GUI, not command prompt):

  • Navigate to the top-level directory
  • In the search box in the top-right, type *.pdf and hit search
  • Select all the files and drag them to the top-level folder
  • Respond to any prompts about overwriting files

10 directories. I think this is particularly useful when you have a lot of locations, even with a small # of files. – StayOnTarget Jun 5 ’19 at 21:12

I don’t think there’s a wildcard that will work on subfolders, so you want to use a loop to go through each subfolder and move *.pdf;

FOR /R [your root folder path] %%G IN (*.pdf) DO move %%G [new path]

The command after DO is inherently in its own quotes. If you anticipate spaces in your source or destination, use double quotes to encapsulate them, e.g.:

FOR /R «source folder with spaces» %%G IN (*.pdf) DO move «%%G» «dest path with spaces»

NOTE the quotes around %%G, these are required for the move command to resolve the path.

**EDIT: In response to the accepted answer, From command prompts on Windows XP and Windows 7, respectively:

Оцените статью