You state that the following code creates a file named "Archive" in the archive folder:

for file in copyPath.rglob("*V1.2*"):
    shutil.move(file,Path(file.parent,"Archive"))

shutil.move only moves your files into a directory if the directory already exists. Otherwise, it'll move (rename) your file. I guess that Path(file.parent, "Archive") is not a directory, so every file matching the condition is moved into a file called "Archive", each file overwriting the previous one.

The fix should be simple:

for file in copyPath.rglob("*V1.2*"):
    target = Path(file.parent, "Archive")
    if target.is_file():
        raise ValueError(f"Invalid directory: {target} is a file!")  # safety check to avoid overwriting files and data loss

    if not target.is_dir():
        target.mkdir(parents=True)  # <- this should solve your problem

    shutil.move(file, target)
Answer from Green 绿色 on Stack Overflow
Discussions

glob.glob vs Path.glob
glob.glob returns meager ol' strings whereas Path.glob returns you easy to work with path objects. More on reddit.com
🌐 r/learnpython
7
3
January 8, 2023
glob and rglob can be slow for large directories or lots of files
Hello! While gleefully using cloudpathlib, I needed a recursive iteration of files in a directory. This directory is large (6238 files), so my first approach - a recursive iterdir() + is_file() - t... More on github.com
🌐 github.com
October 7, 2022
Path.rglob performance issues in deeply nested directories compared to glob.glob(recursive=True)
With a 1000-deep nested directory, glob.glob and Path.glob both took under 1 second. Path.rglob took close to 1.5 minutes. More on github.com
🌐 github.com
7
March 11, 2023
purpose of .glob(r'**/*.jpg') and Path module?
You should read the documentation of pathlib https://docs.python.org/3/library/pathlib.html#basic-use Pathlib is representation of path to files and directories in python. glob is a method to search pattern in a path See the pattern language documentation https://docs.python.org/3/library/pathlib.html#pathlib-pattern-language So train_dir is actually reference to a folder named train and it's under path folder. If path is /xyz Then train_dir is /xyz/train More on reddit.com
🌐 r/learnpython
7
0
November 15, 2025
🌐
Real Python
realpython.com › lessons › listing-conditionally-rglob
Listing Conditionally Using .rglob() (Video) – Real Python
In this example, you can see the same items as before are listed, such as realpython, rename_files.py, and request.py. This shows that the call to glob method with pattern two asterisks, forward slash R and a single asterisk is equivalent to the .rglob() method with the R and single asterisk.
Published: June 11, 2024
🌐
GitHub
github.com › drivendataorg › cloudpathlib › issues › 274
glob and rglob can be slow for large directories or lots of files · Issue #274 · drivendataorg/cloudpathlib
October 7, 2022 - In my mind, shortcutting these common "list everything" recursive calls to glob and rglob to a much faster version with _list_dir may be the best path forward. No new API, direct speedups, relatively simple implementation. The downside is the runtime different between a glob with more complex logic and a simple recursive one may be substantial (which could be confusing).
🌐
GitHub
github.com › python › cpython › issues › 102613
Path.rglob performance issues in deeply nested directories compared to glob.glob(recursive=True) · Issue #102613 · python/cpython
March 11, 2023 - Bug report Pathlib.rglob can be orders of magnitudes slower than glob.glob(recursive=True) With a 1000-deep nested directory, glob.glob and Path.glob both took under 1 second. Path.rglob took close to 1.5 minutes. import glob import os f...
Author: python
🌐
GitHub
facelessuser.github.io › wcmatch › pathlib
wcmatch.pathlib - Wildcard Match Documentation
match mimics Python's pathlib version of match. Python's match uses a right to left evaluation that behaves like rglob but as a matcher instead of a globbing function. Wildcard Match emulates this behavior as well. What this means is that when provided with a path some/path/name, the patterns ...
🌐
Computer Science Atlas
csatlas.com › python-list-directory
Python 3: List the Contents of a Directory, Including Recursively — Computer Science Atlas
March 27, 2021 - Since rglob is the same as calling glob with **/, we could also just use glob to achieve the same result: from pathlib import Path for p in Path( '.' ).glob( '**/*.html' ): print( p ) On any version of Python 3, we can use the built-in os library to list directory contents.
Find elsewhere
🌐
Switowski
switowski.com › blog › pathlib
Pathlib for Path Manipulations - Sebastian Witowski
July 17, 2023 - def os_walk_files(): python_files = [] for root, dirs, files in os.walk("."): for filename in files: if filename.endswith(".py"): python_files.append(root + filename) return python_files · But it's much easier to use the glob module instead. That way we just need one line of code: import glob def glob_find_files(): glob.glob("./**/*.py", recursive=True) pathlib comes with a similar function called rglob().
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
In Path.glob() and rglob(), a trailing slash may be added to the pattern to match only directories.
🌐
PyPI
pypi.org › project › rglob
rglob · PyPI
Lightweight recursive search for ... — globs, content grep, stat/dup helpers, JSON-stable outputs, typed agent API, optional MCP server. ... ____ ____ _ _ | _ \ / ___| | | ___ | |__ | |_) | | _ | |/ _ \| '_ \ | _ <| |_| | | | (_) | |_) | |_| \_\\____| |_|\___/|_.__/ / / / / / Lightweight recursive search for Python, CLIs, and coding agents. Modern Python has pathlib.Path.rglob, and external ...
🌐
Rednafi
rednafi.com › home › python › no really, python's pathlib is great
No really, Python's pathlib is great | Redowan's Reflections
June 30, 2026 - By default, both Path.glob and Path.rglob returns a generator object. Calling list on them gives you the desired result. Notice how rglob method can discover the desired files without you having to mention the directory structure with wildcards explicitly.
🌐
GitHub
gist.github.com › devlights › 7f2f4c7a46e835ba3c6ceb7f8f78f91f
[Python] pathlib の glob と rglob のサンプル · GitHub
[Python] pathlib の glob と rglob のサンプル. GitHub Gist: instantly share code, notes, and snippets.
🌐
Astral
docs.astral.sh › ruff › rules › glob
glob (PTH207) | Ruff - Astral Docs
import glob import os glob.glob(os.path.join("my_path", "requirements*.txt")) ... While using pathlib can improve the readability and type safety of your code, it can be less performant than the lower-level alternatives that work directly with strings, especially on older versions of Python.
🌐
Roadmap
roadmap.sh › python › glob
Python glob Module: File Pattern Matching Explained
March 3, 2026 - Both Path.glob() and Path.rglob() return Path objects rather than strings. This gives you cleaner path handling, simpler joins, and better readability when chaining file operations.
🌐
Chris-piekarski
chris-piekarski.github.io › python-rglob
rglob
Lightweight recursive glob helpers for Python — find files, count lines, sum sizes. This is a small labor-of-love package. Modern Python has pathlib.Path.rglob and tools like fd/ripgrep exist; rglob is small, easy to read, and ships with friendly helpers for the two things you usually want next: count lines and sum sizes.
🌐
Real Python
realpython.com › lessons › listing-conditionally-glob
Listing Conditionally Using .glob() (Video) – Real Python
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas. ... 00:05 The .glob() method of a path object behaves in much the same way as the .rglob method, but does not perform recursion by default.
Published: June 11, 2024
🌐
Reddit
reddit.com › r/learnpython › purpose of .glob(r'**/*.jpg') and path module?
r/learnpython on Reddit: purpose of .glob(r'**/*.jpg') and Path module?
November 15, 2025 -

Question 1: What is the explaination of this expression r'**/*.jpg' like what **/* is showing? what is r?

Question 2: How Path module works and what is stored in train_dir? an object or something else?

from pathlib import Path
import os.path
# Create list with the  filepaths for training and testing
train_dir = Path(os.path.join(path,'train'))
train_filepaths = list(train_dir.glob(r'**/*.jpg'))
🌐
DEV Community
dev.to › guionardo › fast-folder-iteration-in-python-3g1f
Fast folder iteration in python - DEV Community
January 21, 2022 - import pathlib folder='some_folder/another_folder' for path in pathlib.Path(folder).rglob('*'): if path.is_file(): yield str(path) ... Creating sample files + Creating folder ./test_files + Creating files LEVELS=6 FOLDER_COUNT=6 FILE_COUNT_BY_FOLDER=20 + Created 933120 files in 0:02:08.928680 * Running iterators: GlobFolderIterator IGlobFolderIterator OSWalkFolderIterator ScanDirIterator PathLibFolderIterator
🌐
PyTutorial
pytutorial.com › python-pathlib-rglob-explained
PyTutorial | Python Pathlib rglob() Explained
March 19, 2025 - One of its most useful methods is rglob(). This method allows you to recursively search for files and directories. It is similar to glob(), but it searches through all subdirectories.