#🔒 Automatically moving lots of files around
20 messages · Page 1 of 1 (latest)
@little stirrup
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
you're specifically asking how to arrange all the source code for a python project?
can something be done to automate total rearrangements of files or at least make it easier than dragging and dropping a million times
pathlib would probably be very helpful
I am not sure if thats possible, and if it is, I dont know if thats a CMD, PowerShell, or Python thing
!docs pathlib.Path
class pathlib.Path(*pathsegments)```
A subclass of [`PurePath`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath), this class represents concrete paths of the system’s path flavour (instantiating it creates either a [`PosixPath`](https://docs.python.org/3/library/pathlib.html#pathlib.PosixPath) or a [`WindowsPath`](https://docs.python.org/3/library/pathlib.html#pathlib.WindowsPath)):
```py
>>> Path('setup.py')
PosixPath('setup.py')
pathsegments is specified similarly to PurePath.
root_dir = pathlib.Path("/my/directory/")
for txt_path in root_dir.glob("*.txt"):
# iterate over all txt files in `root_dir`...
ohh and this would be in an IDE?
IDEs are just text editors for code. you don't have to write it in an IDE.
that exact code you gave, what would it do? its iterating over something
so how is it gonna run?
*.txt matches all text files
In [51]: root = pathlib.Path('./my_directory/')
In [52]: for file in root.glob("*.txt"):
...: print(file.name)
...: print(file.read_text())
...:
a.txt
"spam"
b.txt
"eggs"
c.txt
"bacon"
Automatically moving lots of files around
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.