#183082 - 2007-11-30 03:02 PM
Copy/Moving files with folder creating
|
Zirian
Fresh Scripter
Registered: 2007-11-30
Posts: 5
|
Hi,
I should paste here an example of script, however I am almost new to it, so that's why I ask you for help. Is somehow possible, using KiXtart to copy/move wav files from one location, let say C:\Program Files\VRL\Dep1, to another one (on the same machine), where script will create a new folder (if no exist), where folder name will be a date, when these wav files were created for example C:\wav\20071131 etc?
Thank you for any idea.
|
|
Top
|
|
|
|
#183090 - 2007-11-30 03:39 PM
Re: Copy/Moving files with folder creating
[Re: Jochen]
|
Zirian
Fresh Scripter
Registered: 2007-11-30
Posts: 5
|
It's working! You are genius! Thank you very much for your time and help!
Is possible in this situation to use command MOVE, to move files across, or after successful finish above script, use command to delete files from source folder, as I would like to make a space on that disk?
Thank you once again!
|
|
Top
|
|
|
|
#183092 - 2007-11-30 03:48 PM
Re: Copy/Moving files with folder creating
[Re: Zirian]
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Either one is possible ... but with MOVE you will need to MD the target directory :
Move
Action: Moves files and renames files and directories. Syntax: Move "source" "target" [/c] [/h] [/r] [/s] /c Continue moving files, even if error(s) occur. /h Moves/renames hidden and system files also. /r Overwrite read-only files in target. /s Renames specified files in all subdirectories. Remarks: If the source or target specifies a directory, please make sure to add a trailing backslash. If the target exists, the source will be moved below the target. If the target does not exist, the source will be renamed.
Wildcards are supported.
MOVE overwrites existing files without warning. See Also: CD, Copy, Del, Go, MD, RD Examples: ; If NewDir does not exist, this command will RENAME ; MyDir to NewDir: MOVE "S:\MyDir\" "S:\NewDir\"
; If NewDir does exist, this command will MOVE MyDir ; below NewDir: MOVE "S:\MyDir\" "S:\NewDir\"
; This command will change the extension of all files ; matching the wildcard specification to '.bak' MOVE "MyDir\file*.txt" "MyDir\file*.bak"
simpler way is to DEL after copy
Del
Action: Deletes one or more files. Syntax: DEL "file name" [/c] [/f] [/h] [/s] /c Continue deleting files, even if error(s) occur. /f Delete read-only files. /h Deletes hidden and system files also. /s Delete specified files from all subdirectories. Remarks: DEL does not prompt the user to confirm the deletion. Wildcards are supported.
or if the directory structure needs to be removed you can use RD (in the mean time I think the directory structure doesn't need to be empty anymore)
_________________________
|
|
Top
|
|
|
|
#183093 - 2007-11-30 04:12 PM
Re: Copy/Moving files with folder creating
[Re: Jochen]
|
Zirian
Fresh Scripter
Registered: 2007-11-30
Posts: 5
|
Hmm...The only thing in this script is that files are copying and saving into the folder with the current date. Let's say we have 2 files created on 29.11.2007 and 30.11.2007. Both of them should be copied/moved and saved into proper folders like 20071129 and 20071130. When I cut/paste files to save "created" date and then run the script, it makes save it in the folder with today’s date... It’s possible to do it like I have explained on the beginning?
|
|
Top
|
|
|
|
#183098 - 2007-11-30 05:26 PM
Re: Copy/Moving files with folder creating
[Re: Les]
|
Zirian
Fresh Scripter
Registered: 2007-11-30
Posts: 5
|
Well I not good with COM unfortunately. So far, with my friend, we have created somthing like this:
Function Replace($String,$SS,$RS)
$Replace=Join(Split($String,$SS),$RS)
EndFunction
function GetExtFileProperties($FQFN, $attribute)
dim $objShell, $objFolder,$i,$found
if exist($FQFN)
$objShell=CreateObject("Shell.Application")
$objFolder=$objShell.Namespace(left($FQFN,instrrev($FQFN,"\")))
if $objFolder
if vartypename($attribute)="string"
While $i<267 and $found=0
if $attribute=$objFolder.GetDetailsOf($objFolder.Items, $i)
$attribute=$i
$found=1
endif
$i=$i+1
loop
endif
if vartypename($attribute)="long" ; Number
$GetExtFileProperties=$objFolder.GetDetailsOf($objFolder.ParseName(right($FQFN,len($FQFN)-instrrev($FQFN,"\"))),$att
ribute)
else
exit -1
endif
else
exit @error
endif
else
exit 2
endif
endfunction
$ShortPath = "D:\Music\"
$Path = "D:\Music\*.mp3"
$outputpath = "C:\OUtput\"
$FileName = Dir($path)
While $FileName <> "" and @ERROR = 0
$DateCreated = GetExtFileProperties($ShortPath + $FileName, "Date Created")
$TrimmedDate = LEFT($DateCreated, 10)
$TrimmedDateWithoutSlashes = Replace($TrimmedDate ,"/", "")
;Next Step... Create Folder
If NOT Exist ($ShortPath + $TrimmedDateWithoutSlashes)
MD "$$outputpath" + "$TrimmedDateWithoutSlashes"
Else
Copy "$Path\$FileName" "$outputpath\$TrimmedDateWithoutSlashes"
$FileName = Dir() ; retrieve next file
Loop
For testing purposes we change it for music folder and mp3 files...
|
|
Top
|
|
|
|
#183099 - 2007-11-30 06:37 PM
Re: Copy/Moving files with folder creating
[Re: Zirian]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Maybe this can help you getting started using the DIRPlus() Function
;Script Options
Break On
Dim $RC
$RC = SetOption('Explicit','On')
$RC = SetOption('NoVarsInStrings','On')
$RC = SetOption('NoMacrosInStrings','On')
;Declare Variables
Dim $Directory, $DirInfo, $DirItem
;Initialize Variables
$Directory = 'C:\Script'
;Code
;'/A-D' only searches for files
$DirInfo = DirPlus($Directory,'/A-D')
For Each $DirItem in $DirInfo
'1. ' $DirItem.Path ?
'2. ' $DirItem.Name ?
'3. ' $DirItem.Drive ?
'4. ' $DirItem.Type ?
'5. ' $DirItem.DateCreated ?
'6. ' $DirItem.DateLastAccessed ?
'7. ' $DirItem.DateLastModified ?
'8. ' $DirItem.Size ?
?
Next
;If needed, Get $RC fakes a kind of pause
;so you get time to read the result window
Get $RC
$DirItem = ''
$DirInfo = ''
;UDF
;Paste here the DIRPlus UDF
;http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82153
|
|
Top
|
|
|
|
#183137 - 2007-12-02 09:27 AM
Re: Copy/Moving files with folder creating
[Re: Witto]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I did not test this!!! I think you want something like this
;************************************************************************* ; Script Name: MoveWavFiles ; Author: Wim Rotty ; Date: 1/12/2007 ; Description: Moves Wav files to directory with as name ; the creation date ;************************************************************************* ;Script Options If Not @LOGONMODE Break On Else Break Off EndIf Dim $RC $RC = SetOption("Explicit", "On") $RC = SetOption("NoMacrosInStrings", "On") $RC = SetOption("NoVarsInStrings", "On") If @SCRIPTEXE = "KIX32.EXE" $RC = SetOption("WrapAtEOL", "On") EndIf
;Declare Variables Dim $Directory, $DirInfo, $DirItem, $Destination Dim $Day, $Month, $Year
;Initialize Variables $Directory = 'C:\Program Files\VRL\Dep1\' $Destination = 'C:\Wav\'
;Code ;Check if target path exists If Not Exist($Destination) ;If not exists, create it MD $Destination ;If creation fails, just stop the script If @ERROR Exit @ERROR EndIf EndIf ;'/A-D' only searches for files ;'/F wav' searches for files with WAV extension $DirInfo = DirPlus($Directory,'/A-D /F wav') For Each $DirItem In $DirInfo ; '1. ' $DirItem.Path ? ; '2. ' $DirItem.Name ? ; '3. ' $DirItem.Drive ? ; '4. ' $DirItem.Type ? ; '5. ' $DirItem.DateCreated ? ; '6. ' $DirItem.DateLastAccessed ? ; '7. ' $DirItem.DateLastModified ? ; '8. ' $DirItem.Size ? ; "Date Created: " Split($DirItem.DateCreated," ")[0] ? $Day = Split(Split($DirItem.DateCreated," ")[0],"/")[0] If Len($Day) = 1 $Day = '0' + $Day EndIf ; "Day: " $Day ? $Month = Split(Split($DirItem.DateCreated," ")[0],"/")[1] If Len($Month) = 1 $Month = '0' + $Month EndIf ; "Month: " $Month ? $Year = Split(Split($DirItem.DateCreated," ")[0],"/")[2] ; "Year: " $Year ? ? ;Check if target folder with date exists If Not Exist($Destination+$Year+$Month+$Day+'\') ;If not exists, create it MD $Destination+$Year+$Month+$Day+'\' EndIf ;Move the file $DirItem.Move($Destination+$Year+$Month+$Day) Next
;If needed, Get $RC fakes a kind of pause ;so you get time to read the result window ;Get $RC
$DirItem = '' $DirInfo = ''
;Personal UDF Section
;UDF ;Paste here the DIRPlus UDF ;http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82153 |
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1045 anonymous users online.
|
|
|