[Implemented] file and directory funktions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] file and directory funktions

Post 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.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

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

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post 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()!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Ralf.

O.K. Thanks now it worked.
Post Reply