Buhli
(Fresh Scripter)
2015-03-02 11:42 AM
need help form the experts again

Hello everyone, happy new year!

I have got a "small" problem.
Glenn helped me out with creating a sorter for moving and copying files in the past.

It still works well and i love it.
The problem now is, we needed to add a folder in the source direction, which we need for other stuff - "C:\etic\Kopie\ITN\"

The script still moves the files, but now it outputs the message with the new folder at the end.
Is there an option to ignore the folder in the message?

Thank you for your help again,
Buhli

Here is what i have running:

 Code:
Break On
COLOR C+
:Loop 											; loop over all

SLEEP 1

'Suche was...' ?

; -----------------------------------AG Coupons Übernahme Galileo Berlin------------------------------------------------------------

; Variablen RESET------------------------------------------------------------------------------------------------------------

Dim $FileDate										; File timestamp
Dim $FileYear										; Year of file timestamp
Dim $FileMonth										; Month of file timestamp
Dim $FileDay 										; Day of file timestamp
Dim $aMonate										; Array of month names
Dim $SPAth, $DPath, $CPath								; Source, Copy and Destination paths
Dim $File										; Name of file being processed
Dim $DstDir										; Full destination path as created


$aMonate = Split('x,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC', ',')		; name of month in Array 

$SPath = 'C:\etic\Kopie\'								; Sorce dir
$DPath = 'T:\agcoupons\galileo\berlin\'							; target dir
$CPath = 'G:\MIR92\'									; copy dir
$File = Dir($SPath + '*.*')								; Variable file

; getting the 1. file

While Not @ERROR

  If $File <> '.' And $File <> '..'							; if file is not a dir.

    
    ;'copy ' $SPath $File ?								; reading, what's going on
    
    'move ' $SPath $File ?								; reading, what's going on
    

    $FileDate  = GetFileTime($SPath + $File)	
    $FileYear  = SubStr($FileDate,1,4)
    $FileMonth = $aMonate[Val(SubStr($FileDate, 6, 2))]
    $FileDay   = Right('0'+SubStr($FileDate,9,2),2)
    $TypeFound = 0

    $DstDir = $DPath + $FileYear + '\' + $FileMonth + '\' + $FileDay			; target dir

    ; creating the target dir if not exist

    If Not Exist($DstDir)
      'MD ' $DstDir ?									; for Debugging
       MD $DstDir									; creating the target dir
    EndIf

   SLEEP 1 										; slowing down for reading

    ; move file into the target dir::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    SLEEP 1										; slowing down for reading
    Move $SPath + $File $DstDir 							; enable executing
 
  EndIf
  
  $File = Dir()										; getting next file

Loop

GOTO "Loop"


Glenn BarnasAdministrator
(KiX Supporter)
2015-03-02 07:12 PM
Re: need help form the experts again

If you want to ignore sub-directories, you can change
 Code:
  If $File <> '.' And $File <> '..'
to
 Code:
If Not GetFileAttr($File) & 16
This will prevent the loop from processing if the file is any directory, including "." or "..".

Glenn


Buhli
(Fresh Scripter)
2015-03-04 03:19 PM
Re: need help form the experts again

Hello Glenn,

thank you very much for the quick reply!
It does the work, but now the output is:
move C:\etic\Kopie\.
move C:\etic\Kopie\..

It also comes up when there is no file in the source-dir, exept the folder "ITN".

Do you have another great idea?

Thank you again,
Buhli


JochenAdministrator
(KiX Supporter)
2015-03-05 10:39 AM
Re: need help form the experts again

Hi Buhli,

had a shot at this, replaced the line with what Glenn suggested and it worked (of course)..



I guess you use a very outdated version of Kixtart. Can you confirm?


JochenAdministrator
(KiX Supporter)
2015-03-05 03:59 PM
Re: need help form the experts again

While believing Glenn is almost always a good idea, this should be the better approach:

 Code:
  if not (getfileattr($File) & 16)					    ; if file is not a dir.


works as well as the other .. so I need to dig a bit into the code I guess:


JochenAdministrator
(KiX Supporter)
2015-03-05 04:18 PM
Re: need help form the experts again

Got it ..

corrected your initial code post to use a "proper" dir statement:

 Code:
$File = Dir($SPath)

It showed the behaviour you described in your last reply while using Glenns suggestion.


So, in conclusion:
Use this one and you should be ok (I won't start the GOTO discussion today ;\) )

 Code:
Break On
COLOR C+
:Loop                                                ; loop over all

SLEEP 1

'Suche was...' ?

; -----------------------------------AG Coupons Übernahme Galileo Berlin------------------------------------------------------------

; Variablen RESET------------------------------------------------------------------------------------------------------------

Dim $FileDate                                        ; File timestamp
Dim $FileYear                                        ; Year of file timestamp
Dim $FileMonth                                       ; Month of file timestamp
Dim $FileDay                                         ; Day of file timestamp
Dim $aMonate                                         ; Array of month names
Dim $SPAth, $DPath, $CPath                           ; Source, Copy and Destination paths
Dim $File                                            ; Name of file being processed
Dim $DstDir                                          ; Full destination path as created


$aMonate = Split('x,JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC', ',')        ; name of month in Array

$SPath = 'C:\etic\Kopie\'                            ; Sorce dir
$DPath = 'T:\agcoupons\galileo\berlin\'              ; target dir
$CPath = 'G:\MIR92\'                                 ; copy dir
$File = Dir($SPath)                                  ; Variable file

; getting the 1. file

While Not @ERROR

  if not (getfileattr($File) & 16)                   ; if file is not a dir.


    ;'copy ' $SPath $File ?                          ; reading, what's going on
    'move ' $SPath $File ?                           ; reading, what's going on


    $FileDate  = GetFileTime($SPath + $File)
    $FileYear  = SubStr($FileDate,1,4)
    $FileMonth = $aMonate[Val(SubStr($FileDate, 6, 2))]
    $FileDay   = Right('0'+SubStr($FileDate,9,2),2)
    $TypeFound = 0

    $DstDir = $DPath + $FileYear + '\' + $FileMonth + '\' + $FileDay            ; target dir

    ; creating the target dir if not exist

    If Not Exist($DstDir)
      'MD ' $DstDir ?                                ; for Debugging
       MD $DstDir                                    ; creating the target dir
    EndIf

   SLEEP 1                                           ; slowing down for reading

    ; move file into the target dir::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    SLEEP 1                                          ; slowing down for reading
    Move $SPath + $File $DstDir                      ; enable executing

  EndIf

  $File = Dir()                                      ; getting next file

Loop

GOTO "Loop"





Buhli
(Fresh Scripter)
2015-03-06 10:29 AM
Re: need help form the experts again

Cheers Jochen!

I will try it in an hour.

About the GOTO... there are 8 different sortings in this file we use, i just copied one into the page.
It processes one by one, and at the end of all the sortings, it jumps back to the start-point.

I know, it could be faster and better, but my knowledge is very limited on this stuff and speed is not that important
for us, it should just work.
About the version of Kixtart, i have to confirm your guess ;\) - my boss... never touch a running system.

Thank you very much for now, i will report after testing.

Sorry about my English!

Best regards,
Buhli


Buhli
(Fresh Scripter)
2015-03-06 11:28 AM
Re: need help form the experts again

Hi Jochen,

it works just fine until there is no file in the dir for moving, except the ITN folder.

move C:\etic\Kopie\Test.txt
move C:\etic\Kopie\Testing.txt
move C:\etic\Kopie\ITN


Strange,

Buhli


LonkeroAdministrator
(KiX Master Guru)
2015-03-06 03:59 PM
Re: need help form the experts again

Sounds like a missing end if.

JochenAdministrator
(KiX Supporter)
2015-03-08 10:48 AM
Re: need help form the experts again

Yeah, missing qoutes or something .. we need to see the whole thing.

@Buhli: mind posting the complete code? If there is anything speaking against it, you may as well pm me with it.


NTDOCAdministrator
(KiX Master)
2015-03-09 07:24 PM
Re: need help form the experts again

Time to insert "Robocopy" idea here.. LOL

Robocopy can do some pretty amazing file copying routines for you. I would suggest at least looking into it to see if it might be a fit here. Aside from an easy one off file copies Robocopy is going to be better at the job and is built-in since Vista.


Buhli
(Fresh Scripter)
2015-03-10 02:38 PM
Re: need help form the experts again

Hi all, sorry for the late reply, but i had some issues with the forum, i can't enter the topic.
Works now.

@NTDOC, i know about robocopy, but our choice was Kixtart.

@Jochen, my boss don't let me do it, maybe a pm would be ok.
Maybe i said it wrong, it doesn't move the folder "ITN", it just gives out the message.

best regards,
Buhli


Glenn BarnasAdministrator
(KiX Supporter)
2015-03-10 02:47 PM
Re: need help form the experts again

Wait - are you saying now that you want to move the ITN folder and contents and not ignore the subfolders? If so, that is a different process.

The code change I originally provided changed the part that looked at the results from DIR and ignored the "." and "..". It should now ignore any filename returned from DIR() that has the Directory attribute set.

If you indeed want to copy the subfolder and files, the logic will be different.

Please clarify whether you want to IGNORE or COPY the subfolders and we'll put something together that will work.

Glenn


Buhli
(Fresh Scripter)
2015-03-10 03:49 PM
Re: need help form the experts again

Sorry if i did some errors in my expression.

It should move all files in the source-dir except the folder "TIN" into the target-dir. (it don't moves the folder, but the output says it does)
We need the folder "ITN" for a different sorting, if there is a file in ITN, move into bla-dir.

Hope my English is good enough gents and sorry for the trouble.
Buhli


JochenAdministrator
(KiX Supporter)
2015-03-10 04:50 PM
Re: need help form the experts again

you may send me the script (I'll delete all traces afterwards)
just click on my name,
<--- there, and choose "send PM" .. Code tags are working there as well as in posts ;\)


NTDOCAdministrator
(KiX Master)
2015-03-11 02:22 AM
Re: need help form the experts again

Well then you need to also verify that all files were moved after you make the move. Any type of network loss during the process can potentially delete files.

Buhli
(Fresh Scripter)
2015-03-11 10:59 AM
Re: need help form the experts again

Yep, true. Thats why i normal run the copy command as well, but so far no misses.

JochenAdministrator
(KiX Supporter)
2015-03-11 04:30 PM
Re: need help form the experts again

Ok, to complete the story for all for now ..

The simple solution was to change to:

 Code:
  if not ( getfileattr($SPath + $File) & 16 )        ; if file is not a dir.


A very D'oh moment for me as dir() of course returns only the name and not the path


Glenn BarnasAdministrator
(KiX Supporter)
2015-03-13 06:55 PM
Re: need help form the experts again

Crap! I didn't remember that either or my original suggestion would have worked. \:\(

NTDOCAdministrator
(KiX Master)
2015-03-13 11:15 PM
Re: need help form the experts again

Members of the Alzheimer's group eh! \:D

Buhli
(Fresh Scripter)
2015-03-16 11:50 AM
Re: need help form the experts again

Hi gents, thank you for all of your proposals.
Now it still gives back:
Move C:\etic\Kopie\.
Move C:\etic\Kopie\..


best regards,
Buhli


JochenAdministrator
(KiX Supporter)
2015-03-16 12:50 PM
Re: need help form the experts again

damn!

Buhli
(Fresh Scripter)
2015-03-16 02:36 PM
Re: need help form the experts again

Oh dear,

sorry Jochen, i'm an old man as well. ;\)
I miss typed one thing.

It runs perfectly now!!!

Thank you once more guys, for all the help an patience with me

All the best to you,
Buhli


Glenn BarnasAdministrator
(KiX Supporter)
2015-03-16 02:53 PM
Re: need help form the experts again

Jeez - this simple test of the logic works just fine:
 Code:
Break On

$Src = 'C:\Temp\'

$File = Dir($Src + '*.*')			; get all files AND folders that contain a dot from $Src folder

While Not @ERROR
  If Not (GetFileAttr($Src + $File) & 16)	; exclude files with attribute bit 5 (Val=16) set
    'File: ' $File ?				; display the file
  EndIf
  $File = Dir()					; get the next filename
Loop
I needed to create a folder with a dot in it to fully test the logic, otherwise other folders were always ignored.

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2015-03-16 02:55 PM
Re: need help form the experts again

Ah - I guess I shouldn't multitask while writing replies.. \:D

Buhli
(Fresh Scripter)
2015-03-16 03:00 PM
Re: need help form the experts again

No problem Glenn, i really appreciate all replies \:\)