-1

I have created a python script in Google colab that copies and renames a couple of jpg file as well as creating an xml file. It works fine apart from the fact that the jpg files need to be renamed with a pipe '|' towards the end e.g. 1211415|1.jpg. In colab I can see the created files and they seem to be named as expected, but I am auto copying and downloading them with ..

shutil.copy('imageOne.jpg', imageZeroName)
shutil.copy('imageTwo.jpg', imageOneName)
files.download(imageZeroName)
files.download(imageOneName)

They then appear in my downloaded folder as 1211414_1.jpg. The pipe has been replaced by an underscore.

I noticed that the original files could not be located when they had pipes in the name. So I changed the names to imageOne.jpg and imageTwo.jpg i.e. I was using a sample with the correct naming convention like 589946681l0.jpg and received error like file does not exist.

Why is this happening and is there anyway to prevent it from doing this?

Thanks.

chucknor
  • 837
  • 2
  • 18
  • 33

1 Answers1

1

If this is on Windows, Windows doesn't support | in file paths and the module is probably replacing it to be able to create the file.

Answers to the What characters are forbidden in Windows and Linux directory names? question expand on what characters and names are invalid on windows

Numerlor
  • 799
  • 1
  • 3
  • 16
  • Ok, thanks. So sounds like there is no work around? – chucknor Jan 12 '22 at 15:03
  • No, windows will just not allow the character to exist in a file name. Though you could a similar looking character like one of the vertical box drawing chars. https://www.unicode.org/Public/security/latest/confusables.txt may help with that – Numerlor Jan 12 '22 at 15:31