14

I have I bunch of files in a directory, named like this:

cat.10171.jpg cat.12421.jpg cat.3421.jpg

I want to move part of them to another directory using this from Colab notebook:

!mv cat.{0..499}.jpg /content/train

I have an error:

mv: cannot stat 'cat.{0..499}.jpg': No such file or directory

Any ideas how to do this and what is the reason?

Kate Lyapina
  • 364
  • 1
  • 2
  • 9

5 Answers5

19

This also worked for me:

shutil.move("path/to/current/file", "path/to/new/destination/for/file")

So:

shutil.move("/content/cat.10171.jpg", "/content/train") 
Avocano
  • 359
  • 3
  • 11
8

I have an idea , you don't need to move them to colab because after some hours , Colab will restart automatic and all data will removed , so what's solution for that ? Simply, you can copy them to colab from Drive but How can i do that ? Here's solution for that :

!cp "/content/drive/My Drive/*.jpg" "/content/train"

BUt if you still want to move them not copy , Here's solution for that :

!mv "/content/drive/My Drive/*.jpg" "/content/train"

Conclusion , " cp " for copy and " mv " for move

AEM
  • 1,354
  • 8
  • 20
  • 30
6
!mv "/content/P14-Convolutional-Neural-Networks.zip" "/content/drive/My Drive/U/señales/colab/"

you have to use "" to make it readable

camille
  • 16,432
  • 18
  • 38
  • 60
user12801937
  • 61
  • 1
  • 1
3

Try this

!bash -c 'mv cat.{0..499}.jpg /content/train'
Robin Green
  • 32,079
  • 16
  • 104
  • 187
0
!bash -c 'cp /content/gdrive/My\ Drive/Colab\ Notebooks/dataset/brain_tumor_dataset/train/Y{41..120}.JPG /content/gdrive/My\ Drive/Colab\ Notebooks/dataset/brain_tumor_dataset/train/yes/' 
SHR
  • 7,940
  • 9
  • 38
  • 57
vibha
  • 1
  • 1
    Welcome to Stack Overflow. Code-only answers are discouraged on Stack Overflow because they don't explain how it solves the problem. Please edit your answer to explain what this code does and how it answers the question, so that it is useful to the OP as well as other users with similar issues. – FluffyKitten Aug 27 '20 at 02:17