Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

File renaming toy.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • File renaming toy.

    This is a very simple dedicated toy that renames a list of MP4 files directly copied from a camera SD card to a directory. My latest action camera writes file names in order but hard to read integer file names. This makes them easier to work with when post processing individual files. This is built with PBCC but if you remove the "waitkey$" and use a MsgBox with a "Done" style message, you can build it in PBWIN as well. It is designed to only work in the current directory and normally you copy this small exe into the directory where you have copied the camera MP4 file and run it.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
        #compile exe "rnlist.exe"
    
        GLOBAL fcnt as DWORD
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION PBmain as LONG
    
        flist$ = GetFileList(GetCurrentDir,".mp4")
    
        waitkey$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    FUNCTION GetFileList(pth$,patn$) as STRING
    
        pth$ = lcase$(pth$)
        patn$ = lcase$(patn$)
    
      ' --------------
      ' Get first file
      ' --------------
        fname$ = lcase$(Dir$(pth$))
        If fname$ = "" Then
          Exit Function
        End If
        If lcase$(right$(fname$,4)) = patn$ Then
    
          nname$ = "vid"+right$("0000"+format$(fcnt),3)+".mp4"
          Name fname$ as nname$
    
          StdOut nname$
          ! add fcnt, 1
        End If
    
      ' -------------------
      ' Get following files
      ' -------------------
        Do
          fname$ = lcase$(Dir$)
          If fname$ <> "" Then
            If lcase$(right$(fname$,4)) = patn$ Then
    
              nname$ = "vid"+right$("0000"+format$(fcnt),3)+".mp4"
              Name fname$ as nname$
    
              StdOut nname$
              ! add fcnt, 1
            End If
          Else
            Exit Do
          End If
        nxt1:
        Loop
    
        FUNCTION = filelist$
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
        DECLARE FUNCTION CurrentDir LIB "KERNEL32.DLL" ALIAS "GetCurrentDirectoryA"_
                         (BYVAL blen AS DWORD, ByVal buff AS DWORD) AS DWORD
    
     FUNCTION GetCurrentDir() as STRING
    
        LOCAL bcnt as DWORD
        LOCAL ptxt as DWORD
    
        bcnt = 260
        cdir$ = space$(bcnt)
        ptxt  = StrPtr(cdir$)
        bcnt  = CurrentDir(bcnt, ptxt)
        FUNCTION = left$(cdir$,bcnt)+"\"
    
     End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com

  • #2
    Same thing simplified and probably a lot quicker

    Code:
    #COMPILE EXE "rnlist.exe"
    #DIM ALL
    FUNCTION PBMAIN AS LONG
        LOCAL fname$,nname$
        LOCAL fcnt AS LONG
        fname$ = DIR$("*.mp4")  'DIR$ is Case insensitive and uses the Current Directory by Default
        WHILE fname$ >""
        nname$ = "vid"& FORMAT$(fcnt,"000") &".mp4"
              NAME fname AS nname$
              STDOUT nname$
              INCR fcnt
              fname$ = DIR$
        WEND
        WAITKEY$
    END FUNCTION

    Comment

    Working...
    X