googlecolab / colabtools

Python libraries for Google Colaboratory
Apache License 2.0
2.19k stars 720 forks source link

Target upload directory in the `google.colab.files.upload` function #4225

Open kubinka0505 opened 10 months ago

kubinka0505 commented 10 months ago

Describe the solution you'd like

I would like the output directory parameter in the google.colab.files.upload function to be implemented, something like:

from google.colab import files

# No other modules required
# Directories made automatically (Optional yet wanted)
files = files.upload(output = "test/123", makedirs = True)

Describe alternatives you've considered

from google.colab import files

# Relying on other modules
import os

# Optional yet wanted
target_dir = "test/123"
os.makedirs(target_dir, exist_ok = True)

# Upload
files = list(files.upload())

# Move
for file_old in files:
    file_name = os.path.basename(file_old)
    file_new = os.path.join(target_dir, file_name)
    os.rename(file_old, file_new)
    files[files.index(file_old)] = file_new

possible duplicate of #1598

blois commented 10 months ago

Consider using upload_file instead, which allows you to specify the file path to be written to-

https://github.com/googlecolab/colabtools/blob/edee64af59b2e03e8b7185c3fa723c5d3cca5d90/google/colab/files.py#L33

kubinka0505 commented 10 months ago

Consider using upload_file instead, which allows you to specify the file path to be written to-

https://github.com/googlecolab/colabtools/blob/edee64af59b2e03e8b7185c3fa723c5d3cca5d90/google/colab/files.py#L33

It doesn't allow for multiple files... or does it?

cperry-goog commented 10 months ago

tracking the feature request for multiple files internally at b/318011890