How to move all files with specific extension from

2020-02-19 07:00发布

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?

9条回答
我只想做你的唯一
2楼-- · 2020-02-19 07:26

I know this is superlate, but just in case it helps anyone.

Used this to search all sub-folders for a .MKV file and move them to the current directory the batch file resides in.

FOR /D /r %%F in ("*") DO (
    pushd %CD%
    cd %%F
        FOR %%X in (*.mkv) DO (
            move "%%X" "%CD%"
        )
    popd
)
查看更多
家丑人穷心不美
3楼-- · 2020-02-19 07:26
MOVE "C:\FOLDER 1\PDF FILES\*.pdf" "C:\FOLDER 1"
MOVE "C:\FOLDER 1\DB FILES\*.db" "C:\FOLDER 1"

After the move command, you have the source folder followed by the destination where the files will be moved to. The * in front of each file extension is a wildcard function that will select all of the specified filetype existing within that directory.

Also, if you can create a .bat file with these commands if you want to. To do this, paste your commands into notepad and save it as .bat instead of .txt

Then, you can double-click the file and it will execute the commands within the file each time you do. This is useful if you have any repetitive tasks that require this.

查看更多
我命由我不由天
4楼-- · 2020-02-19 07:28

Just taking a wild stab in the dark here, but if I remember correctly DOS can handle globs and the equivalent of mv is MOVE, so:

MOVE C:\FOLDER1\*\*.PDF C:\FOLDER1\

查看更多
forever°为你锁心
5楼-- · 2020-02-19 07:31
@echo on

for /r "F:\All_drawings\newdrg\" %%x in (*.tiff) do move "%%x" "F:\Alldrawings"

pause

{moves all files from the newdrg folder and its "sub-folders" to the target folder Alldrawings, this command is for batch file operation for command line use single "%" in both the places}.

查看更多
劫难
6楼-- · 2020-02-19 07:32

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:

command prompts

This shows that a wildcard does not work in paths, only for files in a single directory (e.g. C:\folder*.files). The command prompt does not operate recursively when it encounters a wildcard.

查看更多
劫难
7楼-- · 2020-02-19 07:33

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
查看更多
登录 后发表回答