numbering files

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.

in Qbasic i wrote a programm to increase filenames with numbers.
I get a file called "G_95I" sometimes several times a day.
i want to give it a number like "G_95I00.001, G_95I00.002, etc".
The procedure should check if the filename exists it should increase
it to the next higher number.`
I started the programm but now i am stuck:

OpenConsole()
QuellVerzeichnis$="C:\DB95-EIN" ;Directory of incoming file - filename ether "G_95I" or "L_95I"
FileNameGK$="G_95I"
FileNameLK$="L_95I"
Muster_G$="G_95I*.*"
Muster_L$="L_95I*.*"
DestDirectory$="C:\DB95-SAV" ;Directory for saved, numbered file
WorkDirectory$="C:\DB95-EXP" ;Working Dir - file will be deleted after use

Procedure check_eingang_G (Muster_G$)
If ExamineDirectory ("C:\DB95-SIC","G_95I","*.*")
VerarbDatei$ = Muster_G$ + 1
EndIf
End Procedure

IncomingFile$="C:\DB95-EIN\G_95I" ; checks whether incoming file isn't touched yet
If ReadFile(0,IncomingFile$)
UseFile(0)
PrintN("File is already there ")
Delay(10000)
Else
PrintN("File status ok !")
SLEEP_(4000)
check_eingang_G ()
EndIf
CloseFile(0)
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 PB.

> The procedure should check if the filename exists it should increase
> it to the next higher number.`

I've never liked the "incremental number" approach. I prefer to use the time
and date in the filename, so that you ALWAYS get a unique filename, and don't
have to check for the existence of a previous file. Well, not unless two files
arrive within a one-second period!

I'd suggest that you try this approach instead... but it's up to you.

Code: Select all

; Assume that "C\:G_95I" is the file that always arrives.
; Once arrived, rename it to time format of: G_95I (hh-mm-ss dd-mm-yyyy)
If FileSize("C:\G_95I")-1 ; It's arrived, so now we must rename it.
  b$=" (" ; Prepare b$ to hold new filename for arrived file.
  GetLocalTime_(time.SYSTEMTIME) ; Get time on this PC.
  a$=Str(time\wHour) : If Len(a$)=1 : a$="0"+a$ : EndIf : b$=b$+a$+"-"
  a$=Str(time\wMinute) : If Len(a$)=1 : a$="0"+a$ : EndIf : b$=b$+a$+"-"
  a$=Str(time\wSecond) : If Len(a$)=1 : a$="0"+a$ : EndIf : b$=b$+a$+" "
  a$=Str(time\wDay) : If Len(a$)=1 : a$="0"+a$ : EndIf : b$=b$+a$+"-"
  a$=Str(time\wMonth) : If Len(a$)=1 : a$="0"+a$ : EndIf : b$=b$+a$+"-"
  b$=b$+Str(time\wYear)+")"
  RenameFile("C:\G_95I","C:\G_95I"+b$) ; Rename it!
EndIf

PB - Registered PureBasic Coder

Edited by - PB on 19 February 2002 11:33:28
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.

Sounds good.
I will try that and let you know.
Thanks a lot.

I tried it and it worked great but i need it still numbered,
because the product "G_95I.hh.mm.ss.day.month.year" should
have the DOS-Format 8.3 "G_95nn.nnn" because the next process
will be started by a DOS-Programm, which i have to use still
a unknown amount of time.


Edited by - ralf on 19 February 2002 14:51:54
Post Reply