+ Reply to Thread
Results 1 to 2 of 2

Name x as y Deletes file

  1. #1
    Brad
    Guest

    Name x as y Deletes file

    Thanks for taking the time to read my question

    Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg"

    The line above seems to delete my files. I don't know why, and wish it
    wouldn't.

    Any ideas on what I am doing wrong? If this would work, my function would
    be perfect

    My function is supposed to change files names *.JPG to *.jpg

    Thanks,

    Brad

    Function below
    ---------------------------------

    Function ImageNameDoc()
    Dim strFileName, ReNamestrFileName As String


    On Error GoTo ImageNameDoc_Err:

    strFileName = Dir("C:\LNUPictures\Images\*.jpg")
    ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName

    Open "C:\LNUPictures\ImageNames.txt" For Output As #1

    Do While strFileName <> ""
    'Rename to .jpg from .JPG
    If Right(strFileName, 4) = ".JPG" Then
    Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg"
    FileCopy Right(ReNamestrFileName, 4) & ".jpg",
    Right(ReNamestrFileName, 4) & ".jpg"
    Kill Right(ReNamestrFileName, 4) & "1.jpg"
    End If

    If Right(strFileName, 8) = "zoom.jpg" Then
    Print #1, strFileName
    End If
    If UserForm1.ProgressBar1.Value + Yb < 100 Then
    UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb
    Else
    UserForm1.ProgressBar1 = 100
    End If
    strFileName = Dir
    ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName
    Loop

    Close #1

    ImageNameDoc_Exit:
    Exit Function

    ImageNameDoc_Err:
    MsgBox Err.Number & ", " & Err.Description
    Close #1

    End Function

  2. #2
    Brad
    Guest

    RE: Name x as y Deletes file

    The problem was not with Name but rather with my Right() statement. That was
    the wrong one.

    This code works,

    Brad

    Function ImageNameDoc()
    Dim strFileName, ReNamestrFileName, NameFrom, NameTo, NameNew As String


    On Error GoTo ImageNameDoc_Err:

    'strFileName = Dir("O:\LNUPictures\Images\*.jpg")
    strFileName = Dir("C:\LNUPictures\Images\*.jpg")
    ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName


    'Open "O:\LNUPictures\ImageNames.txt" For Output As #1
    Open "C:\LNUPictures\ImageNames.txt" For Output As #1

    Do While strFileName <> ""
    'Rename to .jpg from .JPG
    If Right(strFileName, 4) = ".JPG" Then
    NameFrom = Left(ReNamestrFileName, Len(ReNamestrFileName) - 4) & ".JPG"
    'Right(ReNamestrFileName, 4) & ".JPG"
    NameTo = Left(ReNamestrFileName, Len(ReNamestrFileName) - 4) & ".jpg"
    'Right(ReNamestrFileName, 4) & "1.jpg"
    Name NameFrom As NameTo
    End If

    If Right(strFileName, 8) = "zoom.jpg" Then
    Print #1, strFileName
    End If
    If UserForm1.ProgressBar1.Value + Yb < 100 Then
    UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb
    Else
    UserForm1.ProgressBar1 = 100
    End If
    strFileName = Dir
    ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName
    Loop

    Close #1

    ImageNameDoc_Exit:
    Exit Function

    ImageNameDoc_Err:
    MsgBox Err.Number & ", " & Err.Description
    Close #1

    End Function

    "Brad" wrote:

    > Thanks for taking the time to read my question
    >
    > Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg"
    >
    > The line above seems to delete my files. I don't know why, and wish it
    > wouldn't.
    >
    > Any ideas on what I am doing wrong? If this would work, my function would
    > be perfect
    >
    > My function is supposed to change files names *.JPG to *.jpg
    >
    > Thanks,
    >
    > Brad
    >
    > Function below
    > ---------------------------------
    >
    > Function ImageNameDoc()
    > Dim strFileName, ReNamestrFileName As String
    >
    >
    > On Error GoTo ImageNameDoc_Err:
    >
    > strFileName = Dir("C:\LNUPictures\Images\*.jpg")
    > ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName
    >
    > Open "C:\LNUPictures\ImageNames.txt" For Output As #1
    >
    > Do While strFileName <> ""
    > 'Rename to .jpg from .JPG
    > If Right(strFileName, 4) = ".JPG" Then
    > Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg"
    > FileCopy Right(ReNamestrFileName, 4) & ".jpg",
    > Right(ReNamestrFileName, 4) & ".jpg"
    > Kill Right(ReNamestrFileName, 4) & "1.jpg"
    > End If
    >
    > If Right(strFileName, 8) = "zoom.jpg" Then
    > Print #1, strFileName
    > End If
    > If UserForm1.ProgressBar1.Value + Yb < 100 Then
    > UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb
    > Else
    > UserForm1.ProgressBar1 = 100
    > End If
    > strFileName = Dir
    > ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName
    > Loop
    >
    > Close #1
    >
    > ImageNameDoc_Exit:
    > Exit Function
    >
    > ImageNameDoc_Err:
    > MsgBox Err.Number & ", " & Err.Description
    > Close #1
    >
    > End Function


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1