#🔒 Automatically moving lots of files around

20 messages · Page 1 of 1 (latest)

little stirrup
#

I need help organizing files. To best organize them, I put folders, within folders, within folders, and so on....

Anyone have advice? It's mostly classes that I split up so much.

Can I use Python or PowerShell to make this easier? or Both? I am VERY bad with operating systems.

clever ledgeBOT
#

@little stirrup

Python help channel opened

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.

tepid jasper
little stirrup
#

can something be done to automate total rearrangements of files or at least make it easier than dragging and dropping a million times

tepid jasper
#

pathlib would probably be very helpful

little stirrup
#

I am not sure if thats possible, and if it is, I dont know if thats a CMD, PowerShell, or Python thing

tepid jasper
#

!docs pathlib.Path

clever ledgeBOT
#

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.

little stirrup
#

huh

#

what can it do?

tepid jasper
#
root_dir = pathlib.Path("/my/directory/")

for txt_path in root_dir.glob("*.txt"):
    # iterate over all txt files in `root_dir`...
little stirrup
#

ohh and this would be in an IDE?

tepid jasper
#

IDEs are just text editors for code. you don't have to write it in an IDE.

little stirrup
#

that exact code you gave, what would it do? its iterating over something

little stirrup
covert gazelle
tepid jasper
#
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

clever ledgeBOT
#
Python help channel closed for inactivity

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.