Skip to content

Instantly share code, notes, and snippets.

@idolpx
Last active May 29, 2024 04:18
Show Gist options
  • Save idolpx/eadd12cb15daa61d9253f325a0381778 to your computer and use it in GitHub Desktop.
Save idolpx/eadd12cb15daa61d9253f325a0381778 to your computer and use it in GitHub Desktop.

Revisions

  1. idolpx revised this gist May 29, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mvaz
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ import os, re, py7zr

    #with py7zr.SevenZipFile('sample.7z', mode='r') as z:
    # z.extractall()
    (END)

    #def extractCB(p1, p2):
    # print( '[' + p1 + '] [' + p2 + ']' )

  2. idolpx revised this gist Nov 30, 2023. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mvaz
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@

    #
    # Move files to directories 0-z based on 1st char of filename
    # https://gist.github.com/idolpx/eadd12cb15daa61d9253f325a0381778
    #
    # Jaime Idolpx
    #

    import os, re, py7zr
  3. idolpx created this gist Nov 30, 2023.
    43 changes: 43 additions & 0 deletions mvaz
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #!/usr/local/bin/python3

    #
    # Move files to directories 0-z based on 1st char of filename
    #

    import os, re, py7zr

    #with py7zr.SevenZipFile('sample.7z', mode='r') as z:
    # z.extractall()
    (END)
    #def extractCB(p1, p2):
    # print( '[' + p1 + '] [' + p2 + ']' )

    # Getting the current work directory (cwd)
    src_dir = os.getcwd() + os.sep
    dest_dir = os.getcwd() + os.sep

    def walk_through_files(path, file_extension=''):
    for (dirpath, dirnames, filenames) in os.walk(path):
    for filename in filenames:
    if filename.endswith(file_extension):
    yield [dirpath + os.sep, filename]

    for path, file in walk_through_files ( src_dir ):
    #print ( path + " + " + file )

    outdir = file[0].lower() + os.sep
    # print ( outdir )
    if ( not os.path.exists( outdir ) ):
    os.mkdir( outdir )

    # Clean up filename
    outfile = file.lower()
    outfile = re.sub(r' |\(.*\)|\'|,', '', outfile)
    outfile = re.sub(r'\.prg$', '', outfile)

    print ( path + file + " -> " + dest_dir + outdir + outfile )

    # Rename ISO file
    os.rename( path + file, outdir + outfile )

    print( 'Done!' )