/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Kopering of en fil.
Fra : Michael K. Therkilds~


Dato : 25-11-02 22:46

Er der nogen som ved hvordan man kopiere. Det er muligt at filen allerede
eksistere det nye sted, men den skal bare overskrives uden at brugeren
behøves at vide det!



 
 
Niels Borg (26-11-2002)
Kommentar
Fra : Niels Borg


Dato : 26-11-02 00:11

Hej Michael
Du kan bruge denne kommando

Dim fso As New FileSystemObject
fso.CopyFile "fil der skal kopieres", "destination"

Default for CopyFile er overwrite, så brugeren bliver derfor ikke spurgt om
man vil overskrive.

Go' arbejdslyst
Niels

"Michael K. Therkildsen" <Michael@K-Therkildsen.dk> wrote in message
news:VSwE9.40038$HU.2774292@news010.worldonline.dk...
> Er der nogen som ved hvordan man kopiere. Det er muligt at filen allerede
> eksistere det nye sted, men den skal bare overskrives uden at brugeren
> behøves at vide det!
>
>




Michael K. Therkilds~ (26-11-2002)
Kommentar
Fra : Michael K. Therkilds~


Dato : 26-11-02 08:56

Dette virker ikke jeg får beskeden "compile error: User-defined type not
defined"

??????

"Niels Borg" <niels.borg@tdcadsl.dk> wrote in message
news:3de2ae0c$0$213$edfadb0f@dread13.news.tele.dk...
> Hej Michael
> Du kan bruge denne kommando
>
> Dim fso As New FileSystemObject
> fso.CopyFile "fil der skal kopieres", "destination"
>
> Default for CopyFile er overwrite, så brugeren bliver derfor ikke spurgt
om
> man vil overskrive.
>
> Go' arbejdslyst
> Niels
>
> "Michael K. Therkildsen" <Michael@K-Therkildsen.dk> wrote in message
> news:VSwE9.40038$HU.2774292@news010.worldonline.dk...
> > Er der nogen som ved hvordan man kopiere. Det er muligt at filen
allerede
> > eksistere det nye sted, men den skal bare overskrives uden at brugeren
> > behøves at vide det!
> >
> >
>
>
>



Jan Damkjær Dahl (26-11-2002)
Kommentar
Fra : Jan Damkjær Dahl


Dato : 26-11-02 16:26

det er fordi du skal lave en preferance til den i dit vb projekt

ellers kan du gøre sådan her

Dim fso
fso.CopyFile "fil der skal kopieres", "destination"

altså lade være at definere fso, men jeg vil nu foretrække at lave
referancen.

gå i menuen Projekt -> References
vælg Microsoft scripting runtime i listen

så får du også en del hjælp når du skriver fso.

jeg vil også foretrække det sådan her

Dim fso As New FileSystemObject
fso.CopyFile "fil der skal kopieres", "destination",true

Så vil den tvinge en overskrivning igennem. så vidt jeg i hvertfald.




"Michael K. Therkildsen" <mkt@bryggerigruppen.dk> skrev i en meddelelse
news:3de329a3$0$155$edfadb0f@dread15.news.tele.dk...
> Dette virker ikke jeg får beskeden "compile error: User-defined type not
> defined"
>
> ??????
>
> "Niels Borg" <niels.borg@tdcadsl.dk> wrote in message
> news:3de2ae0c$0$213$edfadb0f@dread13.news.tele.dk...
> > Hej Michael
> > Du kan bruge denne kommando
> >
> > Dim fso As New FileSystemObject
> > fso.CopyFile "fil der skal kopieres", "destination"
> >
> > Default for CopyFile er overwrite, så brugeren bliver derfor ikke spurgt
> om
> > man vil overskrive.
> >
> > Go' arbejdslyst
> > Niels
> >
> > "Michael K. Therkildsen" <Michael@K-Therkildsen.dk> wrote in message
> > news:VSwE9.40038$HU.2774292@news010.worldonline.dk...
> > > Er der nogen som ved hvordan man kopiere. Det er muligt at filen
> allerede
> > > eksistere det nye sted, men den skal bare overskrives uden at brugeren
> > > behøves at vide det!
> > >
> > >
> >
> >
> >
>
>



Tomas Christiansen (26-11-2002)
Kommentar
Fra : Tomas Christiansen


Dato : 26-11-02 22:55

Jan Damkjær Dahl skrev:
> ellers kan du gøre sådan her
>
> Dim fso
> fso.CopyFile "fil der skal kopieres", "destination"
>
> altså lade være at definere fso...

Interessant version af VB, som du må have! Den kan selv gætte sig til
hvilket ojbekt du ønsker at få instantieret ved blot at skrive 'Dim
fso'!

Er det ikke noget værre vrøvl, du dér fik skrevet?

-------
Tomas


Niels Borg (26-11-2002)
Kommentar
Fra : Niels Borg


Dato : 26-11-02 10:26

Du skal naturlig vis have en reference til Microsoft Scripting Runtime
Dim fso As New FileSystemObject
fso.CopyFile "d:\table.xls", "c:\table.xls"

MVH
Niels Borg



"Michael K. Therkildsen" <mkt@bryggerigruppen.dk> wrote in message
news:3de329a3$0$155$edfadb0f@dread15.news.tele.dk...
> Dette virker ikke jeg får beskeden "compile error: User-defined type not
> defined"
>
> ??????
>
> "Niels Borg" <niels.borg@tdcadsl.dk> wrote in message
> news:3de2ae0c$0$213$edfadb0f@dread13.news.tele.dk...
> > Hej Michael
> > Du kan bruge denne kommando
> >
> > Dim fso As New FileSystemObject
> > fso.CopyFile "fil der skal kopieres", "destination"
> >
> > Default for CopyFile er overwrite, så brugeren bliver derfor ikke spurgt
> om
> > man vil overskrive.
> >
> > Go' arbejdslyst
> > Niels
> >
> > "Michael K. Therkildsen" <Michael@K-Therkildsen.dk> wrote in message
> > news:VSwE9.40038$HU.2774292@news010.worldonline.dk...
> > > Er der nogen som ved hvordan man kopiere. Det er muligt at filen
> allerede
> > > eksistere det nye sted, men den skal bare overskrives uden at brugeren
> > > behøves at vide det!
> > >
> > >
> >
> >
> >
>
>




CADmageren ApS (26-11-2002)
Kommentar
Fra : CADmageren ApS


Dato : 26-11-02 10:10

Filesystemobject er udmærket, men det kræver at VBScript er installeret,
hvilket du ikke altid kan regne med.

Nedenstående er en samling af forskellige API kald til behandling af filer.

Med venlig hilsen
www.cadmageren.dk

Michael Christofferesen

'This program needs a Dialog box, named CDBox1

' (To add the Common Dialog Box to your tools menu, go to
Project->Components (or press CTRL-T)

' and select Microsoft Common Dialog control)

Private Type FILETIME

dwLowDateTime As Long

dwHighDateTime As Long

End Type

Private Type SHFILEOPSTRUCT

hWnd As Long

wFunc As Long

pFrom As String

pTo As String

fFlags As Integer

fAborted As Boolean

hNameMaps As Long

sProgress As String

End Type

Private Type SYSTEMTIME

wYear As Integer

wMonth As Integer

wDayOfWeek As Integer

wDay As Integer

wHour As Integer

wMinute As Integer

wSecond As Integer

wMilliseconds As Integer

End Type

Private Const GENERIC_WRITE = &H40000000

Private Const OPEN_EXISTING = 3

Private Const FILE_SHARE_READ = &H1

Private Const FILE_SHARE_WRITE = &H2

Private Const FO_DELETE = &H3

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName As String, ByVal lpNewFileName As String, ByVal
bFailIfExists As Long) As Long

Private Declare Function CreateDirectory Lib "kernel32" Alias
"CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As
Long) As Long

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

Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long,
lpFileSizeHigh As Long) As Long

Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long,
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As
FILETIME) As Long

Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal
lpExistingFileName As String, ByVal lpNewFileName As String) As Long

Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA"
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal
dwShareMode As Long, lpSecurityAttributes As Long, ByVal
dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal
hTemplateFile As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
As Long

Private Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As
FILETIME, lpSystemTime As SYSTEMTIME) As Long

Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime
As FILETIME, lpLocalFileTime As FILETIME) As Long

Private Sub Form_Load()

'KPD-Team 1998

'URL: http://www.allapi.net/

'E-Mail: KPDTeam@Allapi.net

Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long

Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME

'Set the dialog's title

CDBox.DialogTitle = "Choose a file ..."

'Raise an error when the user pressed cancel

CDBox.CancelError = True

'Show the 'Open File'-dialog

CDBox.ShowOpen

'Create a new directory

CreateDirectory "C:\KPD-Team", ByVal &H0

'Copy the selected file to our new directory

CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0

'Rename the file

MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd"

'Open the file

lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE,
FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)

'Get the file's size

MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle,
lngLong)) + " bytes."

'Get the fil's time

GetFileTime lngHandle, Ft1, Ft1, Ft2

'Convert the file time to the local file time

FileTimeToLocalFileTime Ft2, Ft1

'Convert the file time to system file time

FileTimeToSystemTime Ft1, SysTime

MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" +
LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear))

'Close the file

CloseHandle lngHandle

'Delete the file

DeleteFile "C:\KPD-Team\test.kpd"

With SHDirOp

..wFunc = FO_DELETE

..pFrom = "C:\KPD-Team"

End With

'Delete the directory

SHFileOperation SHDirOp

End

End Sub





Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408925
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste