Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




File Help [please Move]


1. How can I create and write to a text file? I tried
Code:
FSO.OpenTextFile(DBPath & "Stations" & StationName & ".txt", ForWriting, True).Write Text1 & ";" & Text2MsgBox "Radio station added successfully."
and it says Object Required Error 424.2. How can I make my menu show all of the files in the folder? (Caption=filename) and when clicked I want it to fill in the fields Text1 and Text2 with the ones stored in the text file as Text1;Text2.Please help me! =]




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Getting File Properties,delete And Move File Keyword
Hi,

q1

how do i get the properties of a file..

lets say the name of the file is test1.xls, how do i get info such as the modified date,created date,size of file..

q2

i tried to delete a file using this command

fso.deletefile "c: est1.xls"

i also used

fso.movefile "c: est1.xls", "d: est1.xls" to move file to a different location

both statement returned an error saying access denied..not sure whats the real cause
thankxx in advance..

VB6: How To Move The File Pointer In A Random Access File?
I have this function to see if a number already exists in a random access file:


Code:
Public Function NumberExists(ByVal Number As Long) As Boolean
Dim i As Long
'code to begin the loop at the start of the file (how do I do this?)
Do While Not EOF(3)
i = i + 1
Get #3, i, T
If Number = T.Number Then
NumberExists = True
Exit Function
Else
NumberExists = False
End If
Loop
End Function


and this code in a Sub to run the function:


Code:
ExistingNumber = NumberExists(Number)

If ExistingNumber = False Then
Counter = Counter + 1
T.RecNo = Counter
T.Number = Number
T.Question = Question
T.Answer = Answer
Put #3, , T
Else
'nothing
End If



The file stays open all the time, so I can write in the Sub that calls the Function, and it can read in the Function.

Problem is, that the function only works with the first search. It doesn't find the number, because nothing is written so far. In the Sub the record is written, which is ok.
However, when it uses the function to look up the second number, the 'file pointer' is at the end of the file, so it exits the function.

How can I do my search each time from the start of the file?

How To Move File Pointer Back To The Beginning Of File
If I open a file for INPUT and read a certain number of lines from it (or even if I reach EOF), then is there a way to move the file pointer back to the beginning of the file so I can research for something else? I do not really want to close the file and then re-open it to force the filepointer to be back at the top.

Thanks



Edited by - uncletr on 6/25/2004 5:56:58 AM

File Opening Errors - How To Move On When A File Does Not Exist
I have written code that collects a bunch of variables which are then used to open a file with them in its filepath. I need however to create an error method for a case when the file does not exist (and should not).

I have used the opening method:

Code: Workbooks.Open ("E:Folder1Folder2" & Var1 & " " & Var2 & " Name 1 " & Var3 & ".xls"

for variables Var1, Var2, Var3.


Can this return a boolean value somehow? If it cannot find a file, can I use some output in an IF statement?

M_B



Edited by - M_B on 1/28/2004 3:28:58 AM

If File A File Exist Kill, If Not Move On
if file C:kcomp_.xls is in place kill it.
If the file is not in place then skip the step>???

Move A File
How would i move a file, say from temp to C:WindowsDesktop ?
Thanks
Dan_

Move File
Hi all,

I have problem to loop through the folder.

Example
I have a Folder name: "Test" Under "Test" folder i have files in it.

Test
file.dat
file.dat
file.pgp
file.pgp

If i want to decrypt files that have .pgp and move them to "Test1" folder How do I decrypt file that contain .pgp?

Thanks

Move A File From One DB To Another
Is there a way to put a drop box, or check box on a form that if you select it, it will move the information from that form to a seperate database? What I am doing is one DB has information that is pulled up by a form, if that information is completed I would like to choose an option that removes that info from the current database and puts it in a Database called 'History". Is this possible, and if so, can I get a few suggestions on how to do it.
-- Jon

Move File
How would I move the program to a new location while it is running?

Move A File [VB6]
Given a file [C:Filescurrent.zip], I need to move that file (current.zip) to another folder [C:FilesHistory]
How can I do that? Thanks,

Move File
Hi all is there any method to move file in vb?
I don't want to "copyfile" just move a file.
Peace,
naitsabes

Move File
Once my text file is read and processed by my program how can i move it to an "archive" directory?.

i.e see code below - reads from

c: estincoming

after its been read and processed into excel spreadsheet i need to move it to

c: ext incomingarchive

any ideas?



VB Code:
Set AppXls = CreateObject("excel.application")   Set MyWB = AppXls.Workbooks.Add   x = 0   File1.Path = "c: estincoming" ' Only look in c: estincoming"   File1.Pattern = "*.*" ' Look at all files''''''then at bottom of program...         End If       Next    Next    MyWB.SaveAs "c: estoutgoing
ew.xls"     MyWB.Close False   ' was saved, if i want to prompt the user for it set True instead of False !   AppXls.Quit   Set AppXls = Nothing   End Sub

Move A File
how do I let move a file from a directory to another??
Es. from c:document in c:prova

Move File
Hi,
i Have some files in one folder...i want to that files to another folder...using vb....how can i move that....anybody know about it....plz tell me...

thankyou in advance....

regards
Murugan.

Move File
hi,
I have 2 folders....one foldser contains some files...i want to move that files another folder....how can i move it....using function
plz tell me...

thankyou
regards,
murugan.

Move File
Hello everyone,
I need to know how to move a file to another folder.
Not copy a file, but move a file.

Thanks

HELP!!!!!!! How Do I Move A File
Okay I have added the code and taken out the one line. It works great for the first file, but the second file gives me error number 53 File not Found. What am I doing wrong??

File Move
Hi
    I have a program which generates 7 or 8 PDF'S a day (which is growing by the day) what i need is to take the files from the directory on the network and move them to my machine, so its from F: est to E: est, i have tried the FO_MOVE FUNCTION but for some reason i am getting the error CANNOT MOVE FILE: CANNOT READ FROM THE SOURCE FILE OR DISK

Can anyone shed any light

Thanks

Move A File
hi,
i wont to be able to move a file to another directory.
the file is on the desktop, and i wanna move it to another folder on the hardrive.
i tried using the api MoveFileEx but i get stuck...!

ta

Move To The Start Of File
Hi,

I open a file in vb with the command Open InputFile For Input As LanFileNum.

after I read the all file, I want to get back to the start of it, without
open it again.
can I do it?

Thank you,
Lili

Move File Needs To Overwrite Also [VB6]
In my code I need to move a file from one folder to another, this is how I currently do it [and it works great except for...]


Code:
'Move Zip File to History Folder
Name sLogPath As sHistoryPath + "" + stodayLog
So the only problem I have is if the file already exists I get an error, what I want is for it to overwrite (or delete the old copy then perform this option)
So questions - should I use a different method (like what?) or should I delete the file if it exist before doing my Move? (how would I do that?)
Thanks,

Move File If In Folder
Hello, i need to make an app that checks a certain folder for files. Its checking for .doc files in my case. But its okay if it just checks for any file.
If it finds a file it should then move it to another directory.
But what i dont know is how to let it check if a file exists in a directory.
Can someone please help me with that.

Automatic FIle Move
Move files automatically instead of manually clicking a command button: The following code works great behind a command button, but how could I modify it to make it work automatically, say, every 2 minutes? Every 2 minutes the application would move the files from sFiles1 to sFiles 2 then delete the files from sFiles1 (same as it is today, though the moving would be without having to click the command button, that's all.) Please, NO api. Thanks.

sFiles1 = Dir1.Path & "*.txt"
sFiles2 = Dir2.Path & "*."
Shell ("xCopy " & sFiles1 & " " & sFiles2) 'Copy the files
Sleep 3000
Kill sFiles1

How Do I Move A File Using The Kernel?
i need the moveFile function just like this delete one

Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

Move And Rename File
This code will MOVE a file from the START to the END directory. I'd also like to rename the files by adding a Z.

Before:

test1.txt
test2.txt

After:

test1Z.txt
test2Z.txt



VB Code:
Private Sub cmdMove_Click()    On Error GoTo MyError        cmdMove.Enabled = False    MoveFiles "C:AaronStart", "C:AaronEnd", "txt"    cmdMove.Enabled = TrueMyError:   If Err.Number = 58 Then   MsgBox "File Exixts", vbOKOnly + vbExclamation   cmdMove.Enabled = True   End IfEnd Sub Private Sub MoveFiles(ByVal sSource As String, ByVal sDest As String, Optional ByVal sExt As String = "*")    Dim sFile As String    If Not Right$(sSource, 1) = "" Then sSource = sSource & ""    If Not Right$(sDest, 1) = "" Then sDest = sDest & ""    sFile = Dir(sSource & "*." & sExt)    Do While Len(sFile)        Name sSource & sFile As sDest & sFile        sFile = Dir    LoopEnd Sub

Move File Needs To Overwrite Also [VB6]
In my code I need to move a file from one folder to another, this is how I currently do it [and it works great except for...]


Code:
'Move Zip File to History Folder
Name sLogPath As sHistoryPath + "" + stodayLog


So the only problem I have is if the file already exists I get an error, what I want is for it to overwrite (or delete the old copy then perform this option)
So questions - should I use a different method (like what?) or should I delete the file if it exist before doing my Move? (how would I do that?)
Thanks,

Move Log File To Another Folder
Hi,

I have a program that runs daily and stops at a certain time each day. I would like the log file, that is created from the Program, to move to a folder called Archived at the end of the program each day, changing the name to the current date. So that in the archive folder i will have a list of files for each day, to make it easier for reference.
So i need two things really:
1) To move the file from "c:..Logs" to "c:..LogsArchived"
2) To change the name of the file to the current date.

Thanks for any help.

Angel16

Move File From FTP Instead Of Copy
I have this FTP source code from the internet, and it really works and help me download data from FTP.
But after a while i see that the contains of the folder in the FTP site is increasing with the data i downloaded.
This is because when i download the data from the FTP,it just copy the data, not move it.
I really dont know what to modify because the code is really advanced compare to me who still a beginner.
Can someone help me identify which line i have to change so that after this it will move the data,not copy.
I may not paste all the complete coding such as the declaration, i will paste them separately according to its sub.


Code:
Private Sub FtpEnumDirectory(strDirectory As String)
'On Error Resume Next
'ClearBag
Dim hFind As Long
Dim nLastError As Long
Dim dError As Long
Dim ptr As Long
Dim pData As WIN32_FIND_DATA

If Len(strDirectory) > 0 Then rcd (strDirectory)
pData.cFileName = String(MAX_PATH, 0)
hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
nLastError = Err.LastDllError

If hFind = 0 Then
If (nLastError = ERROR_NO_MORE_FILES) Then
MsgBox "This directory is empty!"
Else
ErrorOut nLastError, "FtpFindFirstFile"
End If
Exit Sub
End If

dError = NO_ERROR
Dim bRet As Boolean
Dim strItemName As String

EnumItemAttributeBag.Add pData.dwFileAttributes
strItemName = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
EnumItemNameBag.Add strItemName
Do
pData.cFileName = String(MAX_PATH, 0)
bRet = InternetFindNextFile(hFind, pData)
If Not bRet Then
dError = Err.LastDllError
If dError = ERROR_NO_MORE_FILES Then
Exit Do
Else
ErrorOut dError, "InternetFindNextFile"
InternetCloseHandle (hFind)
Exit Sub
End If
Else
EnumItemAttributeBag.Add pData.dwFileAttributes
strItemName = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
EnumItemNameBag.Add strItemName
End If
Loop

InternetCloseHandle (hFind)
End Sub



Code:
Private Sub rcd(pszDir As String)
'On Error Resume Next
If pszDir = "" Then
MsgBox "Please enter the directory to CD"
Exit Sub
Else
Dim sPathFromRoot As String
Dim bRet As Boolean
If InStr(1, pszDir, txtServer.Text) Then
sPathFromRoot = Mid(pszDir, Len(txtServer.Text) + 1, Len(pszDir) - Len(txtServer.Text))
Else
sPathFromRoot = pszDir
End If
If sPathFromRoot = "" Then sPathFromRoot = "/"
bRet = FtpSetCurrentDirectory(hConnection, sPathFromRoot)
If bRet = False Then ErrorOut Err.LastDllError, "rcd"
End If
End Sub



Code:
Public Function OpenSession()
stbMain.Panels(1).Text = "Status: Opening Session..."
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
If hOpen = 0 Then ErrorOut Err.LastDllError, "InternetOpen"
End Function
Public Function Connect()
stbMain.Panels(1).Text = "Status: Connecting to NEWTON FTP..."
If Not bActiveSession And hOpen <> 0 Then
If txtServer.Text = "" Then
MsgBox "Please enter a server name!"
Exit Function
End If
Dim nFlag As Long
If chkPassive.Value Then
nFlag = INTERNET_FLAG_PASSIVE
Else
nFlag = 0
End If
hConnection = InternetConnect(hOpen, txtServer.Text, INTERNET_INVALID_PORT_NUMBER, _
txtUser, txtPassword, INTERNET_SERVICE_FTP, nFlag, 0)
If hConnection = 0 Then
bActiveSession = False
ErrorOut Err.LastDllError, "InternetConnect"
Else
bActiveSession = True
'EnableUI (CBool(hOpen))
'FillTreeViewControl (txtServer.Text)
FtpEnumDirectory ("/usr25/keepdata/week.1/")
If EnumItemNameBag.Count = 0 Then Exit Function
'FillTreeViewControl (txtServer.Text)
End If
End If
End Function



Code:
Dim tahun
Dim bulan
Dim hari
Dim realhari As Date
tahun = Format(Now, "yyyy")
bulan = Format(Now, "MM")
hari = Format(Now, "dd")
arini = Format(Now, "dd/MM/yyyy")
realhari = DateAdd("d", 0, arini)
realday = Format(realhari, "dd")
stbMain.Panels(1).Text = "Status: Downloading data..."
Dim bRet As Boolean
Dim szFileRemote As String, szFileRemote1 As String, szDirRemote As String, szFileLocal As String
Dim szTempString As String
Dim nPos As Long, nTemp As Long
If bActiveSession Then
szDirRemote = "133.111.11.466"
'szFileRemote1 = '
szFileRemote = "sort" & tahun & bulan & realday & ".txt" '----ni idea Kak Ila..marvellous!!!!!Kak ila hebat!!
'szFileRemote = "jbbz05.txt"
szFileLocal = "\epjnt1usersSystemDataTransferMPINSDataTran"
rcd szDirRemote
bRet = FtpGetFile(hConnection, szFileRemote, szFileLocal & "/" & szFileRemote, False, _
INTERNET_FLAG_RELOAD, dwType, 0)
End If
End Function

Move To First Line Of A File
Hi,

Can anybody help me to find the way that move to the first line or BOF of a file? Since i need to read through this file many times, repeatly open and close should slow the perfermance. Maybe create a local DB table is a option. But i think it is last choice.


HTML Code:
Open strMatchFile For Input As #2
Do While Not EOF(2)
Line Input #2, strLine
....
Loop
close #2


Thanks for help

Robert

In FTP Client Move The File
Hi,
Sorry i want to move file in FTP Client.....its have two folders...i want to move one folder files to another folder.....in FTP....
anybody know about it tell me...
Thanks in Advance....


regards,
murugan..

FSO - Move/override A File
Hi,
I'm using FSO to move a file from one place to another. This works great as long as the file doesn't exist in the destination folder as well. If it does I get an error.

Code:
Dim FSO As Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject

With FSO
.MoveFile "C:Folder1 emp1.txt", "C:Foler2"
End With

Set FSO = Nothing


How can I move a file and override if necessary using FSO?
(If possible I'd rather not delete first then move)

How To Move A File Into Another Directory?
>I am a new one in VB programming.
>How to move a file form one directory to another?
>Thank you in advance.

I should say I am a new one in VBA for Access programming. Sorry for misleading.

Serran, does your code work in VBA for Access 2000?

Waiting To Move File
Hi,
What is the best method in VB to check a file status, before trying to delete the file.

I have a program that Prints a File, then I want to delete it once's it has printed. The problem is that, windows takes control of the file and places the file in the print spooler (i.e. holding the file Open).

I use

Code:
While fileexists(filename) = True
fso.movefile "C:file.txt" "C: empFile.txt"
Loop


This loops continuiously until the file is in the correct state. Its not the best, I'm sure there must be something a bit more practical to use.

Thanks for any help

Craig.

Select And Move File
using commondialog I select a file
from anywhere on my system drives.

how do I move it to C:Mynewfolder

Private Sub cmdGetPic_Click()

'Set the properties of the text control
CommonDialog1.Filter = "Pictures(*.jpg)|*.jpg*|Gif Files(*.gif,*.gif)|*.htm*|All files(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.FileName = "YourFile"
CommonDialog1.DefaultExt = "txt"
CommonDialog1.ShowSave

'What goes here to do the move or copy
'preferably move but if not I can kill
'the file later in the event

End Sub

Need To Move A Group Of File
How can I move a group of files togheter to a new folder usign one button.
If possible, could you give me the code considering a defaulut command button command1

Move / Copy File - In Use?
Hi,
I have been given a project to complete and need some advice since I am
somewhat a novice.

I have to move some files from a folder to another folder.

But some of these files may still be in the process of being written by
another machine.

If they are being written, I just want to forget about them until the next
time I move files from that folder.

Is there a message I can trap or does someone have sample code?

Thanks!

I Need To Move A Group Of File
How can I move a group of files togheter to a new folder usign one button.
If possible, could you give me the code considering a defaulut command button command1

How To Move A File To Trashcan
Hi all

I want to move files to trash can before I actually delete the files. How can i do it or can i mark the files for deletion.

How can i do this?1

Thanks in advance
Venky

File Copy/Move
Using VB5 dragdrop between filelistbox and dirlistbox. The selected file drags and drops. But it can only be dropped and saved into the root directory not a sub directory. Any advice or help from anyone please?

Ray Outterside

Pls Help Me ,as I Am Trying To Move A File And Copy A File Using Fso
Hello,

I am trying to move a file from one directory to other using FSO but my problem is that i want to move a file to that location where the user want to move

Dim fso As New FileSystemObject

fso.MoveFile "pat3", "part"

These "pat3" variable is string type(which has the path of file that i want to move) and i am passing it when the file control box is clicked and "part" VARIABLE is that variable which i am passing it when the SECOND directory box is clicked(means to that folder where the user want to save.

FOR COPY ALSO SAME PROBLEM

Dim fso As New FileSystemObject

fso.CopyFile "pat3", "part", True

PLS HELP ME OUT
APARNA

Move A File Or Delete A File
Hello, I know how to copy a file by using "filecopy ,source, destination", however I do not know how to delete the source, once it is at it's destination. Could someone give me some simple code to delete or move the source file?

Thank you.

How Do You Move The Current File Position
I have a text file which Ineed to read one character at a time, which isn't a problem but on occassion I need to step back to the previous character and read it again. In C I use the seek() function but in vb this doesn't allow negative numbers. can anyone help?

Move A File From Current Directory
Hello, I'm trying to move a file from the directory which the compiled exe file is in. I was wondering if it is a valid move to include the app.path & "filename" command while using the filecopy and kill commands. For example, this is my attempted piece of code I was working on...

MkDir "c:Donut"
FileCopy App.Path & "stuff.txt", "c:Donutstuff.txt"
Kill App.Path & "stuff.txt"

Any who, I was just wondering how I would incorporate the app.path & "filename" command into the filecopy and kill commands.

Making Code From File. Please Don't Move This
Please don't move this to the HTML/DHTML Forum, this has nothing to do
with that, im asking for pure and standart Visual Basic code!!! please...
I mean to parse a file the file could be html, txt, whatever...

Hello,
I'm doing a program that makes reports from html templates, but in some cases I need to put in the html file an "IF", for example I took the data
from the db and if a field is empty i don't put it on the report
Example: (this is the code I made)

{IF} points=0
You don't have any points.
{ELSE}
Your points are: <b>{points}</b>
{FI}

I can parse the if, and I have an array with the conditions and the posible true or false responses, but I don't know how to put this to code,
I mean to make this if real visual basic code in the sub i'm filling the variables on the html. Is there a way to do this? there could be a lot
of if conbinations.

Thanks,
Bye.

File Reading(Move To Next Line)
hi,

I need to find some strings in a text file.For that i m using the normal file open methods.
eg:
I want to find the string "abc".When i find "abc", i need to traverse the next lines until i find "def" .

m not able to figure out how to start the next search for "def"

any idea how to go bout it??

regds,
ashay

Move A File From Folder To Subfolder
Hi All,
How can I move a file (backup.zip) from say c:ackup to c:ackup19102001 during runtime???.
Thanks in advance
R.

EASY! HELP! HELP! Move And Rename A File
I have an application that opens a text file that it recieves daily via ftp. It appends all of the data in the text file to a SQL7 db and then closes the db connection. I then need the program to move the file to a different folder and rename it with a new file name. What code can I use to handle the moving and renaming?

How To Move To The Next Question Using Sequential File
Hi i need some help as my logics have just die on me for a week ok let get down to the point I am designing a small program like a quiz the problem comes how do i move onto the next line in sequential file ok here is my code

Open (App.Path & " xtquestion.txt") For Input As Myfile
' so it open the file fine no probs
Input #Myfile, QuestionA

Input #Myfile, answerA
Input #Myfile, opA
Input #Myfile, answerB
Input #Myfile, opB
Input #Myfile, answerC
Input #Myfile, opC
Input #Myfile, answerD
Input #Myfile, o

loads all of the above fine no probs


this is where the problem starts so please help me as i said my head is a bit dead and has been dead for a week you know the feeling sometime .

Private Sub lblnext_Click()


Do While Not (EOF(1))

Line Input #1, QuestionA
txtquestion.Text = Trim$(QuestionA)
Line Input #1, opA
txtopA.Text = Trim$(opA)

Line Input #1, opB
txtopB.Text = Trim$(opB)

Line Input #1, opC
txtOpC.Text = Trim$(opC)

Line Input #1, opD
txtOpD.Text = Trim$(opD)

this is where i can't sort my self out it goes throught the loop ok but just how just how do i stop the loop so when the user is ready to move onto the next question he/she just clicks on the command button u know next for next question ...

please email me on waheedrafiq@yahoo.com please help me
i am frusrated as i know the answer but can't wirte it down u know what i mean.....


Loop

Move A Line From One Text File To Other
--Boundary_(ID_IcqQ20ltU2cXv+X9vXwrZg)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 7BIT

Hi

I am displaying one line Example Name from one text file name tip.text
in a Lable at my form.
i want that once that line from text file tip.text display then under
one command butten i can move that line from tip.txt to other file
tipfinal.text
Thanks

--Boundary_(ID_IcqQ20ltU2cXv+X9vXwrZg)
Content-type: text/html; charset=iso-8859-1
Content-transfer-encoding: 7BIT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1170" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>I am displaying one line Example Name from one text
file name tip.text<BR>in a Lable at my form.<BR>i want that once that line from
text file tip.text display then under<BR>one command butten i can move that line
from tip.txt to other
file<BR>tipfinal.text<BR>Thanks<BR></FONT></DIV></B ODY></HTML>

--Boundary_(ID_IcqQ20ltU2cXv+X9vXwrZg)--

Copyright 2005-08 www.BigResource.com, All rights reserved