CopyDirectory & DeleteDirectory

Just starting out? Need help? Post your questions and find answers here.
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

CopyDirectory & DeleteDirectory

Post by ZX80 »

Hello!
Sorry for post without code, but I just wanted to ask:

Could mr. Fred extend commands such as DeleteDirectory and CopyDirectory
(with recursion flag) to stop the process at any time?

Explanation:
There are many directories to remove. But each of them contain a lot of small files. Therefore, the process of deleting at least one directory takes a lot of time. Thus, if a stop signal was sent, then in fact a stop will occur only after completion of the process over the current directory. Not immediately. It looks as if the program is not responding (hung).

The process is performed in an additional thread. Forcing it to end is the wrong way. I wanted to be able to correctly terminate the
above commands ahead of schedule.
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: CopyDirectory & DeleteDirectory

Post by CELTIC88 »

just an example :)

Code: Select all

Global COntroleScanFile

Procedure File(*ppath)
  Repertoire$ = PeekS(*ppath)
  irertun = 1
  pbh = ExamineDirectory(#PB_Any, Repertoire$, "*.*")  
  If pbh
    While NextDirectoryEntry(pbh)
      Select COntroleScanFile
        Case 1 ; pause
          Debug "[Pause]"
          While COntroleScanFile = 1
            Delay(100)
          Wend
        Case 2 ; end
          Debug "[END]"
          irertun = 0
          Break
      EndSelect
      filename$ = DirectoryEntryName(pbh)
      If filename$ <> "." And filename$ <> ".."
        If DirectoryEntryType(pbh) = #PB_DirectoryEntry_File
          Debug "file : " + filename$
        Else
          Debug "dir : " +Repertoire$+ filename$+"\"
          filename$ = Repertoire$+ filename$+"\"
          irertun = File(@filename$)
          If irertun = 0 :Break:EndIf
        EndIf
      EndIf
    Wend
    FinishDirectory(pbh)
  EndIf
  ProcedureReturn irertun
EndProcedure

Procedure ScaneFile(path.s)
  *pcommand = AllocateMemory(StringByteLength(path) + 2)
  PokeS(*pcommand,path)
  CreateThread(@File(), *pcommand)
  ProcedureReturn *pcommand
EndProcedure

ScaneFile("c:\")
MessageRequester("","")
COntrolScanFile = 1 ;pause
MessageRequester("","")
COntrolScanFile = 0 ;continue
MessageRequester("","")
COntrolScanFile = 2 ;close scan
MessageRequester("","")
interested in Cybersecurity..
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

Re: CopyDirectory & DeleteDirectory

Post by ZX80 »

CELTIC88, thank you. AND sorry for delay with reply.

Here you can see solution of this problem:

Code: Select all

;copying
Procedure CopyDir(PathSrc.s, PathDest.s, *Break.Integer)
  Protected ID, Name.s, Src.s, Dest.s
  ID = ExamineDirectory(#PB_Any, PathSrc, "*.*")
  If ID
    While NextDirectoryEntry(ID)
      If *Break And *Break\i<>0
        Break
      EndIf
      Name=DirectoryEntryName(ID)
      If Name<>"." And Name<>".."
        Src=PathSrc+Name
        Dest=PathDest+Name
        If DirectoryEntryType(ID) = #PB_DirectoryEntry_Directory
          Src+"\"
          Dest+"\"
           If FileSize(Dest)=-2 Or CreateDirectory(Dest)
             Debug "folder  "+Dest
             CopyDir(Src, Dest, *Break)
           Else
             Debug "Can't create folder "+Dest
           EndIf
        Else
           If CopyFile(Src, Dest)
             Debug "file   "+Dest
           Else
             Debug "Can't copy file "+Dest
           EndIf
        EndIf
      EndIf
    Wend
    FinishDirectory(ID)
  EndIf
EndProcedure

Br=0
CopyDir("C:\123\", "C:\123_(copy)\", @Br)
with deleting in the same way.
This code was kindly provided by User_Russian. Thank a lot to him.

[offtop start]
CELTIC88, your new avatar much better than old. :D
[/offtop end]
Post Reply