Page 1 of 1

[Implemented] file and directory funktions

Posted: Wed Jan 02, 2002 4:40 pm
by BackupUser
Restored from previous forum. Originally posted by Ralf.

i would be good if Purebasic would have some more funktions or
statements to handle files and directories, which can copy whole folders(directories) with subdirectories or all files in a directory.
Like XCOPY C:\TEST\*.* /S/E D:\sic\*.* or to delete whole directories
or all files in a directory.

Posted: Wed Jan 02, 2002 4:58 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Hi Ralf,
here some code to copy a directory.
If i recall it right this code is Fred's code that he wrote some ages ago...

;Here is a recursive example to scan all files
;and copy files to a destination directory
;(including sub directories)... -> Fred's code? "." And DirectoryEntryName() ".."
a$ = SourceDirectory$+DirectoryEntryName()+"\"
b$ = DestinationDirectory$+DirectoryEntryName()+"\"
CopyDirectory(a$, b$, Start+1)
UseDirectory(Start)
EndIf
Else
If Type = 1
CopyFile(SourceDirectory$+DirectoryEntryName(), DestinationDirectory$+DirectoryEntryName())
EndIf
EndIf
Until Type = 0
EndIf

EndProcedure
[/code]
Don't know if it works...
Hope this helps.


Have a nice day...
Franco

Posted: Wed Jan 02, 2002 7:24 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

It's looks like my code (I hope ) and it works..

Fred - AlphaSND

Posted: Thu Jan 03, 2002 12:42 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
It's looks like my code (I hope ) and it works..

Fred - AlphaSND
Hello Fred and Franco, both you (Fred) and Mr Skunk pasted variants of this code which I used as the basis of writing my iFind program which is on the PB resource site.

Ralf, download iFind and have a look at how I used it. There are routines to load in entire subdirectories or just find files anywhere to load into a listbox. I'm writing a corporate version now which still uses the same recursive engine and returns 32,00o files into the list in under a minute (Faster than Windows built in search most times)

Regards

Fangles

Posted: Thu Jan 03, 2002 3:10 pm
by BackupUser
Restored from previous forum. Originally posted by Ralf.

hello,
i tried the following procedure but nothing happend !

OpenConsole()
PrintN("Bitte UrsprungsVerzeichnis eingeben : ")
SourceDir$= Input()
SourceDirectory$ = SourceDir$
PrintN("hello sourcedir ... : ")
Print(SourceDirectory$)
PrintN("Bitte ZielVerzeichnis eingeben : ")
DestDir$= Input()
DestinationDirectory$ = DestDir$
PrintN("hello sourcedir ... : ")
Print(DestinationDirectory$)
PrintN("")

Delay (4000)
Procedure CopyDirectory(SourceDirectory$, DestinationDirectory$, Start)
If ExamineDirectory(Start, SourceDirectory$, "*.*")
CreateDirectory(DestinationDirectory$)
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."
a$ = SourceDirectory$+DirectoryEntryName()+"\"
b$ = DestinationDirectory$+DirectoryEntryName()+"\"
CopyDirectory(a$, b$, Start+1)
UseDirectory(Start)
EndIf
Else
If Type = 1
CopyFile(SourceDirectory$+DirectoryEntryName(), DestinationDirectory$+DirectoryEntryName())
EndIf
EndIf
Until Type = 0
EndIf
EndProcedure

Posted: Thu Jan 03, 2002 3:18 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

Hi,

you don't seem to call the procedure! Do that and something will happend.. i.e. add the following line to your code:

CopyDirectory(SourceDirectory$, DestinationDirectory$, Start)

The above line will start the execution of the procedure CopyDirectory()!

Posted: Fri Jan 04, 2002 8:34 am
by BackupUser
Restored from previous forum. Originally posted by Ralf.

O.K. Thanks now it worked.