0
# Caminho para o arquivo de origem
caminho_origem = 'C:\\TesteScript/'  # Substitua pelo caminho real do arquivo de origem

# Caminho para a pasta de destino compartilhada na rede
caminho_destino = r'\\RAFAEL-DESK\Users\rafa-\Desktop\TesteScript'  # Substitua pelo caminho real da pasta de destino
while True:
    # Lista todos os arquivos na pasta de origem
    for arquivo in os.listdir(caminho_origem):
        caminho_arquivo_origem = os.path.join(caminho_origem, arquivo)
        
        # Verifica se o caminho é de um arquivo (não é um diretório)
        if os.path.isfile(caminho_arquivo_origem):
            ser_imagem = is_image(caminho_arquivo_origem)
            if ser_imagem is True:
                # Monta o caminho para o arquivo de destino na pasta compartilhada
                caminho_arquivo_destino = os.path.join(caminho_destino, arquivo)
                
                try:
                    # Move o arquivo da pasta de origem para a pasta de destino
                    shutil.move(caminho_arquivo_origem, caminho_arquivo_destino)
                    print(f'Arquivo {arquivo} movido com sucesso para {caminho_destino}')
                except FileNotFoundError:
                    print(f'O arquivo {arquivo} não foi encontrado.')
                except PermissionError:
                    print(f'Permissão negada para mover o arquivo {arquivo}.')
                except Exception as e:
                    print(f"Ocorreu um erro ao mover o arquivo {arquivo}: {str(e)}")

And it gives me the following error

An error occurred when moving file 11.jpg: [Errno 22] Invalid argument: '\\RAFAEL-DESK\Users\rafa-\Desktop\TesteScript/11.jpg'

Can someone help me?

I'm trying to move files from a local folder to a network shared folder via Python

5
  • You're using both "\" and "/" in your directory path Commented Oct 11, 2023 at 18:55
  • @SurajShourie While it may be confusing, it shouldn't cause a problem. Windows treats them equivalently. Commented Oct 11, 2023 at 19:46
  • Does it help if you include a drive letter in caminho_destino? Commented Oct 11, 2023 at 19:46
  • Related, maybe duplicate: stackoverflow.com/questions/18621577/… Commented Oct 11, 2023 at 19:47
  • when you use string with prefix r then it treasts \\ as two \ (not single \ ) and this can make problem Commented Oct 11, 2023 at 19:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.