Hi All
I am still trying to rename a file grammatically, I am trying a sub found in Code Snippets that apparently works for other people. CODE SNIPPET
SCENARIO: User uploads file not named in lowercase.
I have this [file File.DirRootExternal&"/ABT/","IMPSITELIST.CSV"] and need to rename it to lowercase for those functions that are case sensitive.
I am calling the Sub RenameFile and all appears OK, except that the file is not renamed to lowercase.
I am probably missing something simple any clues much appreciated
Regards Roger
I am still trying to rename a file grammatically, I am trying a sub found in Code Snippets that apparently works for other people. CODE SNIPPET
SCENARIO: User uploads file not named in lowercase.
I have this [file File.DirRootExternal&"/ABT/","IMPSITELIST.CSV"] and need to rename it to lowercase for those functions that are case sensitive.
I am calling the Sub RenameFile and all appears OK, except that the file is not renamed to lowercase.
I am probably missing something simple any clues much appreciated
Regards Roger
B4X:
Sub Globals
Private OldName As String
Private NewName As String
End Sub
Sub BtnTest_click
'Looks for file and renames it to lowercase even if already in lowercase as file.exists is case insensitive.
If File.Exists(File.DirRootExternal&"/ABT/","impsitelist.csv") = True Then 'Only run if file found "Name Case Insensitive"
Table.Initialize
Table = MF_File.ListFiles(File.DirRootExternal & "/ABT/", "*.*", True, False) 'Make list of all files
If Table.Size > 0 Then 'Only run if there is at least 1 file
For i = 0 To Table.Size -1
OldName = Table.Get(i)
NewName = OldName.ToLowerCase
If NewName = "impsitelist.csv" Then
Private Success As Boolean
Success=RenameFile(File.DirRootExternal&"/ABT/"&OldName, File.DirRootExternal&"/ABT/"&NewName)
If Success Then Exit
End If
Next
End If
End If
End Sub
Sub RenameFile(OriginalFileName As String, NewFileName As String) As Boolean
Dim Result As Int
Dim StdOut, StdErr As StringBuilder
StdOut.Initialize
StdErr.Initialize
Dim Ph As Phone
Result = Ph.Shell("mv " & OriginalFileName & " " & NewFileName, Null, StdOut, StdErr)
If Result = 0 Then
Return True
Else
Return False
End If
End Sub