在Google Colab中移动文件

Kat*_*ina 6 linux command-line command-line-interface google-colaboratory

我在目录中有一堆文件,命名如下:

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

我想使用其中的一部分从Colab笔记本将它们移动到另一个目录:

!mv cat.{0..499}.jpg /content/train
Run Code Online (Sandbox Code Playgroud)

我有一个错误:

mv: cannot stat 'cat.{0..499}.jpg': No such file or directory
Run Code Online (Sandbox Code Playgroud)

有什么想法怎么做的,原因是什么?

Avo*_*ano 7

这也为我工作:

shutil.move("path/to/current/file", "path/to/new/destination/for/file")
Run Code Online (Sandbox Code Playgroud)

所以:

shutil.move("/content/cat.10171.jpg", "/content/train") 
Run Code Online (Sandbox Code Playgroud)


小智 7

!mv "/content/P14-Convolutional-Neural-Networks.zip" "/content/drive/My Drive/U/sen?ales/colab/"
Run Code Online (Sandbox Code Playgroud)

您必须使用""以使其可读


AEM*_*AEM 5

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"
Run Code Online (Sandbox Code Playgroud)

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

!mv "/content/drive/My Drive/*.jpg" "/content/train"
Run Code Online (Sandbox Code Playgroud)

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


Rob*_*een 3

尝试这个

!bash -c 'mv cat.{0..499}.jpg /content/train'
Run Code Online (Sandbox Code Playgroud)