Results 1 to 15 of 15

Thread: [RESOLVED] Overwrite files

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Resolved [RESOLVED] Overwrite files

    Hi all, i got a problem about overwriting a exist file now. the background is i open a file , then i do some conversion to the data of the file, after finish all conversion, i must overwrite the file .

    Eg: the exist file path is
    C:\Documents and Settings\USER\Desktop\EM017.D03 after i did the conversion job,
    i have tried to save the file with the same path name, but the compiler always show error. i tried to save it using another name, it works. So can you give me some ideas? thanks a lot!!!

  2. #2

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Overwrite files

    You probably never closed the file before trying to write to it.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    no , i do have closed the file. the error message is "File/Path access error"

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Overwrite files

    Can you post some code and tell us which line is giving the error?

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    VB Code:
    1. If Mid$(data1(4), 11, 5) <> "Y" Then
    2.     filenames = Mid$(data1(2), 8, 80) & Chr(92) & extractfilename
    3. Else
    4.     filenames = Mid$(data1(1), 7, 80) & Chr(92) & extractfilename
    5. End If
    6. Dim nFileNum As Integer                  
    7. nFileNum = FreeFile
    8. Open filenames For Binary As #nFileNum      'this line has error
    9. Put #nFileNum, 1, code_ascii
    10.  
    11. Close #nFileNum

    because i need to identify, once the Mid$(data1(4), 11, 5)<>"y", the code will work, but the code doesn't work when it equals to "y", it will show error.
    so can you help me? or do you need some more explination? thanks a lot.
    Last edited by zachs; Jan 11th, 2007 at 04:33 AM.

  7. #7
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Overwrite files

    You are comparing 11,5 or a starting in the 11 position for a length of 5 with "Y"
    Will the "Y" be in the first position of the 11th position... or the 11,12,12,14,15...or the 15th position
    meaning, fix your compare
    If Mid$(data1(4), 11, 1) <> "Y" Then...or If Mid$(data1(4), 15,1) <> "Y" Then
    And Ucase or Lcase "y" ?

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    hi sessi4ml,
    because i am working with the .ini file now. the "data1(4)" is the data in the ini file, the content is "overwrite=Y"/"overwrite=N" , so it means the user wanna overwrite the exist file or not after the conversion function to the data in the file. if "overwrite=Y", then i will overwrite the file after conversion, if "overwrite=N", then after conversion i will save the file into another path.
    so when i put "N" the code will work fine, and a new converted file is generated, but once i put "Y", the error message "path/file access error" come out, and after i click debug button, the line "Put #nFileNum, 1, code_ascii" will be highlighted.
    btw, the "code_ascii" is the data after i convert the file.
    Can you help me, please?

  9. #9

  10. #10

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    but how can i do that??? is there a such kind of build-in function? thanks

  11. #11
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Overwrite files

    Zach, we all look at different parts of code. I am looking at..Mid$(data1(4), 11, 5)
    When you:
    Debug.pring Mid$(data1(4), 11, 5)
    What is there? What are you comparing with "Y"

  12. #12

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    Quote Originally Posted by zachs
    hi sessi4ml,
    because i am working with the .ini file now. the "data1(4)" is the data in the ini file, the content is "overwrite=Y"/"overwrite=N" , so it means the user wanna overwrite the exist file or not after the conversion function to the data in the file. if "overwrite=Y", then i will overwrite the file after conversion, if "overwrite=N", then after conversion i will save the file into another path.
    so when i put "N" in the .ini file, the code works fine, and a new converted file is generated, but once i put "Y", the error message "path/file access error" come out, and after i click debug button, the line "Put #nFileNum, 1, code_ascii" will be highlighted.
    btw, the "code_ascii" is the data after i convert the file.
    Can you help me, please?
    btw, i have change to "Mid$(data1(4), 11, 1)"

  13. #13
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Overwrite files

    OKay, so where are we? Still not working?
    Are you comparing upper case with upper case?
    Is the file being written out?

  14. #14

    Thread Starter
    Member
    Join Date
    Dec 2006
    Posts
    38

    Re: Overwrite files

    yes, i have already noticed about the case. but it still doesn't work.

    so another guy has given me a idea--- i save the converted file to another name in the same folder withe the original file, then i delete away the original file, lastly, i rename the converted file to the same name with the original file. do u think is it can be done?

    what is the function to delete a file in a folder? thanks a lot.

  15. #15
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Overwrite files

    Kill App.Path + "\filename"

Posting Permissions

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



Click Here to Expand Forum to Full Width