|
-
Jan 11th, 2007, 02:24 AM
#1
Thread Starter
Member
[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!!!
-
Jan 11th, 2007, 03:03 AM
#2
Fanatic Member
Re: Overwrite files
What is the error?
Is the file open?
Do you have rights to open the file as output?
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
-
Jan 11th, 2007, 03:06 AM
#3
Re: Overwrite files
You probably never closed the file before trying to write to it.
-
Jan 11th, 2007, 03:48 AM
#4
Thread Starter
Member
Re: Overwrite files
no , i do have closed the file. the error message is "File/Path access error"
-
Jan 11th, 2007, 04:21 AM
#5
Re: Overwrite files
Can you post some code and tell us which line is giving the error?
-
Jan 11th, 2007, 04:27 AM
#6
Thread Starter
Member
Re: Overwrite files
VB Code:
If Mid$(data1(4), 11, 5) <> "Y" Then
filenames = Mid$(data1(2), 8, 80) & Chr(92) & extractfilename
Else
filenames = Mid$(data1(1), 7, 80) & Chr(92) & extractfilename
End If
Dim nFileNum As Integer
nFileNum = FreeFile
Open filenames For Binary As #nFileNum 'this line has error
Put #nFileNum, 1, code_ascii
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.
-
Jan 11th, 2007, 10:39 AM
#7
Fanatic Member
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" ?
-
Jan 11th, 2007, 08:53 PM
#8
Thread Starter
Member
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?
-
Jan 11th, 2007, 10:38 PM
#9
Re: Overwrite files
Try writing the data to a new file, Kill-ing the old file, and then renaming the new file with the old name.
-
Jan 11th, 2007, 10:42 PM
#10
Thread Starter
Member
Re: Overwrite files
but how can i do that??? is there a such kind of build-in function? thanks
-
Jan 12th, 2007, 12:58 AM
#11
Fanatic Member
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"
-
Jan 12th, 2007, 01:03 AM
#12
Thread Starter
Member
Re: Overwrite files
 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)"
-
Jan 12th, 2007, 01:12 AM
#13
Fanatic Member
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?
-
Jan 12th, 2007, 01:43 AM
#14
Thread Starter
Member
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.
-
Jan 12th, 2007, 02:25 AM
#15
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|