0

I'm trying to write a small python script to fix the capture date of my videos. I'm on Windows and I want to use the "SendTo" feature.

So far I'm just trying to get a list of video files based on the command line arguments:

import argparse
import os

vidExtension = "mp4"

def getVideoFiles(fileFolders):
    files=[]
    folders=[]

    # Create list of folders and files from command line arguments
    for arg in fileFolders:
        curpath = os.path.normpath(arg)
        print(curpath, os.path.isdir(curpath))
        if os.path.isdir(curpath):
            folders.append(curpath)
        elif os.path.isfile(curpath):
            if curpath.lower().endswith(vidExtension):
                files.append(curpath)
        else:
            print("Unrecognized arg: " + arg + "\n    normpath: " + curpath)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Process video files')
    parser.add_argument('foldersFiles', type=ascii, nargs='+',
                    help='Folders/Files to process')
    args = parser.parse_args()
    print(args.foldersFiles)

    getVideoFiles(args.foldersFiles)

When launching the script (right clic SendTo...), here is the output I get:

args.foldersFiles:  ["'D:\\\\Synchro NAS\\\\Images\\\\Photos Num\\xe9riques\\\\A Trier\\\\2020\\\\z Videos\\\\temp'", "'D:\\\\Synchro NAS\\\\Images\\\\Photos Num\\xe9riques\\\\A Trier\\\\2020\\\\z Videos\\\\00047.mp4'"]
'D:\Synchro NAS\Images\Photos Num\xe9riques\A Trier\2020\z Videos\temp' isdir:  False isfile:  False
Unrecognized arg: 'D:\\Synchro NAS\\Images\\Photos Num\xe9riques\\A Trier\\2020\\z Videos\\temp'
    normpath: 'D:\Synchro NAS\Images\Photos Num\xe9riques\A Trier\2020\z Videos\temp'
'D:\Synchro NAS\Images\Photos Num\xe9riques\A Trier\2020\z Videos\00047.mp4' isdir:  False isfile:  False
Unrecognized arg: 'D:\\Synchro NAS\\Images\\Photos Num\xe9riques\\A Trier\\2020\\z Videos\\00047.mp4'
    normpath: 'D:\Synchro NAS\Images\Photos Num\xe9riques\A Trier\2020\z Videos\00047.mp4'

Files and folders are not recognized. I used os.path.normpath to normalize the paths but it doesn't work...

An important notice is that I have accentuation in the path string: The real path is: D:\Synchro NAS\Images\Photos Numériques\A Trier\2020\z Videos

Could someone help me please :)!

1 Answer 1

1

In add_argument call the type argument is set to ascii which calls the ascii function to convert the incoming string to a representation of itself (similar to repr()), which escapes backslashes and non-ascii characters.

This representation can't be processed as path correctly.

Solution: Omit the type=ascii in the call.

Sign up to request clarification or add additional context in comments.

Comments

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.