Read directory contents into a file

Just starting out? Need help? Post your questions and find answers here.
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.

How can put the contains of a directory in to a file.
In DOS i do it like this : DIR C:\TEST\*.* > C:\TESTOUT\CONTENTS.TXT
IN QBASIC like THIS : SHELL "DIR C:\TEST\*.* > ....."
But now i want to do that in PUREBASIC without any DOS command. ?
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 Paul.

Look in the documentation under FileSystem.
There is an example there called FileSyetem.pb that reads in a directory and the files it contains.

Just modify the code to read the directory file names into an array and then save them back disk into a new file.
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 Paul.

Or skip the array and do this:

Code: Select all

If ExamineDirectory(0, "c:\test\", "*.*")
  If CreateFile(0,"c:\testout\contents.txt")
    Repeat 
      type=NextDirectoryEntry()
      If type=1
        WriteStringN(DirectoryEntryName() )
      EndIf
    Until type=0
    CloseFile(0) 
  EndIf 
EndIf
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 Paul.

Actually thats a good idea TronDoc...

The snippet.zip file is now a single zip with each snippet in its own folder. Just remember to unzip using the "Use Folders" (-d) option, or everything will unzip into your root folder.
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.

Thanks.
works great.
Post Reply