FileRename and having the same name? - Forum

Forum Navigation
You need to log in to create posts and topics.

FileRename and having the same name?

Can I use FileRename and have more then one file with the same name in the destination folder.

i.e.  1234.pdf to Name.pdf and 1234(1).pdf to Name.pdf

FileRename "[BMM.Pdf_2.Folder_Path]\[BMM.Pdf_2.Name]" "[PubDir]\Pdf\[BMM.Pdf_2.Code].pdf"

I know this sounds strange, but some have the reference code, are updated version and need to be saving.

No, there cannot be two files with the same name in a folder

salu2

luishp has reacted to this post.
luishp

Salu2

 

Thank you, windows has a work round i.e. adding (2) to the end of the file. But, Can this be done within VisualNeo?

Mike

.We get a list of files that we want to rename.
FileList "[FilePath]\*.pdf" "Files" "[FileList]"

.New file name
SetVar "[NewFileName]" "NewFileName"

.Remove from the list of files the file names that match the new name
StrRegexReplace "[NewFileName]\(\d+\)\.pdf\r|[NewFileName].pdf\r|[NewFileName]\(\d+\)\.pdf|[NewFileName].pdf" "[FileList]" "" "" "[FileList]"

StrParse "[FileList]" "[#13]" "[FileName]" "[FileCount]"

If "[FileCount]" ">" "0"
    Loop "1" "[FileCount]" "[i]"
        FileExists "[FilePath]\[NewFileName].pdf" "[Result]"
           If "[Result]" "=" "False"
               FileRename "[FilePath]\[FileName[i]]" "[FilePath]\[NewFileName].pdf"
           Else
               While "[Result]" "=" "True"
                   SetVar "[n]" "[n]+1"
                   FileExists "[FilePath]\[NewFileName]([n]).pdf" "[Result]"
                   If "[Result]" "=" "False"
                      FileRename "[FilePath]\[FileName[i]]" "[FilePath]\[NewFileName]([n]).pdf"
                   EndIf
               EndWhile
           EndIf
    EndLoop
EndIf

DeleteArray "[FileName]" "All"
ClearVariables "[FilePath],[Result],[FileList],[NewFileName],[FileCount],[i],[n]"

 

dglojnar and alangonzalez91 have reacted to this post.
dglojnaralangonzalez91