Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

script that will copy and past files


  • Please log in to reply
14 replies to this topic

#1 program builder

program builder

    Prodigy

  • Banned (NOT IN USE)
  • 159 posts

Posted 13 March 2010 - 09:58 PM

I am looking for autoit script, that will copy and paste files from a folder
into another folder. Does anyone have a script for this?







#2 99ojo

99ojo

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 872 posts

Posted 13 March 2010 - 10:02 PM

Hi,

have look at helpfile or have a search over forum:
FileCopy ()
DirCopy ()
_FileListToArray ()

Try start coding. If you still have problems, come back with some code snippet.

;-))
Stefan

#3 program builder

program builder

    Prodigy

  • Banned (NOT IN USE)
  • 159 posts

Posted 13 March 2010 - 11:01 PM

I am trying to take all of the mp3 files from one folder, and put them in another

would this work.

$programfiles = ("c:/program files/ copyall ".mp3")

$programfilesmusic = ("c:/program files/music/ pastall ".mp3")

$copy = $programfiles

$past = $programfilesmusic

copyfile(($copy))
pastfile(($past))

I know this isn't the right code. But does anybody see what I am wanting to do?

Edited by program builder, 13 March 2010 - 11:04 PM.


#4 Yoriz

Yoriz

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 356 posts

Posted 13 March 2010 - 11:25 PM

You want to be looking at something more like

$programfiles = "c:/program files/"
$programfilesmusic = "c:/program files/music/"

create a list of files of type ".mp3" inside $programfiles

loop through each of the files in the list of files found while copying them from $programfiles each filename into $programfilesmusic each filename

Edited by Yoriz, 13 March 2010 - 11:26 PM.

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

#5 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 13 March 2010 - 11:32 PM

This is just intended to get you started down the right path.
First of all it's backslash "\" in a folder path, not forward slash "/". It also helps to look up the functions in the help file to see what is actually happening.

$sCopyFrom = "C:\Some\Folder\" $sCopyTo = "C:\Some\Other\Folder\" $hSearch = FileFindFirstFile($sCopyFrom & "*.mp3") If $hSearch <> -1 Then     While 1         $sFile = FileFindNextFile($hSearch)         If @Error Then ExitLoop         If StringInStr(FileGetAttrib($sCopyFrom & $sFile), "D") Then             DirCopy($sCopyFrom & $sFile, $sCopyTo & $sFile)         Else             FileCopy($sCopyFrom & $sFile, $sCopyTo & $sFile)         EndIf     WEnd EndIf

Edited by GEOSoft, 13 March 2010 - 11:32 PM.

GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#6 program builder

program builder

    Prodigy

  • Banned (NOT IN USE)
  • 159 posts

Posted 14 March 2010 - 01:00 AM

;I tryed this, but it didn't work. I tryed it with txt

;I put 2 text files into the text 1 and tryed to copy and

;past them into the text 2 folder

;here is the code I used

$sCopyFrom = "C:\program files\text 1\"
$sCopyTo = "C:\program files\text 2\"

$hSearch = FileFindFirstFile($sCopyFrom & "*.txt")
If $hSearch <> -1 Then
While 1
$sFile = FileFindNextFile($hSearch)
If @Error Then ExitLoop
If StringInStr(FileGetAttrib($sCopyFrom & $sFile), "D") Then
DirCopy($sCopyFrom & $sFile, $sCopyTo & $sFile)
Else
FileCopy($sCopyFrom & $sFile, $sCopyTo & $sFile)
EndIf
WEnd
EndIf

;could someone tell me why it isn't working, when I run it?

#7 dani

dani

    Polymath

  • Active Members
  • PipPipPipPip
  • 215 posts

Posted 14 March 2010 - 01:17 AM

You could also use this one:
AutoIt         
$sTarget = @ScriptDir & "\" & "temp" $sSource = @ScriptDir $sExt    = "txt" MoveFiles($sSource, $sTarget, $sExt) Func MoveFiles($sSource, $sTarget, $sExt = ".*")   If Not StringRegExp($sSource, "\\\z") Then $sSource &= "\" ; Append missing '\' to $sSource if needed   If Not StringRegExp($sTarget, "\\\z") Then $sTarget &= "\" ; Append missing '\' to $sTarget if needed   FileChangeDir($sSource)   $hSearch = FileFindFirstFile("*.*")   $hFile = FileFindNextFile($hSearch)   While Not @error     If @extended Then ; $hFile is a directory       MoveFiles($sSource & $hFile, $sTarget, $sExt) ; Scan the subdirectory     Else              ; $hFile is a file       FileChangeDir($sSource)       If StringRegExp($hFile, "(?i)\." & $sExt & "\z") Then FileCopy($hFile, $sTarget, 8+1) ; Copy $hFile to $sTarget (create directory if needed and overwrite existing files -- flag 8+1)     EndIf     $hFile = FileFindNextFile($hSearch)   WEnd   FileClose($hSearch) EndFunc

It is recursive -- it also moves files from subdirectories. If you don't want this, simply comment this line:
MoveFiles($sSource & $hFile, $sTarget, $sExt) ; Scan the subdirectory

Edited by dani, 14 March 2010 - 11:31 AM.


#8 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 14 March 2010 - 01:41 AM

Another way.

AutoIt         
#Include <File.au3> _FileCopyEx('C:\Program Files\text 1', 'C:\Program Files\text 2', '*.txt') Func _FileCopyEx($sSrc, $sDest, $sMask = '*', $fReplace = 0)     Local $FileList     $FileList = _FileListToArray($sSrc, $sMask, 1)     If Not @error Then         For $i = 1 To $FileList[0]             If (Not $fReplace) And (FileExists($sDest & '\' & $FileList[$i])) Then                 ContinueLoop             EndIf             If Not FileCopy($sSrc & '\' & $FileList[$i], $sDest & '\' & $FileList[$i], 9) Then                 Return 0             EndIf         Next     EndIf     $FileList = _FileListToArray($sSrc, '*', 2)     If Not @error Then         For $i = 1 To $FileList[0]             If Not _FileCopyEx($sSrc & '\' & $FileList[$i], $sDest & '\' & $FileList[$i], $sMask, $fReplace) Then                 Return 0             EndIf         Next     EndIf     Return 1 EndFunc   ;==>_FileCopyEx

Edited by Yashied, 14 March 2010 - 01:48 AM.


#9 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 14 March 2010 - 01:58 AM

@dani
Using StringRegExp() the way you did to check for trailing backspaces seems like overkill ans abuse of StringRegExp(). A better method would be.
Func MoveFiles($sSource, $sTarget, $sExt = ".*")   $sSource = StringRegExpReplace($sSource, "(.+)\\?$", "$1\\")   $sTarget = StringRegExpReplace($sTarget, "(.+)\\?$", "$1\\")

Also did you test that code? I didn't but it looks all wrong, at least at a glance.

@program builder
Did you test to make sure the folders actually exist and that the script "sees" files in the source folder?
Hint: MsgBox(0, "Result", $sFile)
Spoiler

Did you check the help file for the functions I used to see what flags can be used with those functions?
Did you bother to look for Dir*() functions in the help file?
Did you look at the example code for the functions in the help file?
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#10 dani

dani

    Polymath

  • Active Members
  • PipPipPipPip
  • 215 posts

Posted 14 March 2010 - 11:27 AM

@dani
Using StringRegExp() the way you did to check for trailing backspaces seems like overkill ans abuse of StringRegExp(). A better method would be.

Func MoveFiles($sSource, $sTarget, $sExt = ".*")   $sSource = StringRegExpReplace($sSource, "(.+)\\?$", "$1\\")   $sTarget = StringRegExpReplace($sTarget, "(.+)\\?$", "$1\\")

Also did you test that code? I didn't but it looks all wrong, at least at a glance.

Hi Geo. Why is it abuse of StringRegExp? I don't really follow, as your StringRegExpReplace essentially does the same, but replaces it at the same time. It might be nicer as it's one command, but I am really not sure if it is more efficient seeing how your code always does a string replacement, while mine only does that if needed. My regular expression is easier, thus faster I think? Not sure how it's an overkill :mellow:

Anyway, of course I tested it, works perfectly. It's a bit different from the examples in the Help File, I tend to use this While Not @error instead of If @error Then ExitLoop etc. Also, @extended is a bit shorter than your StringInStr combined with FileGetAttrib to test whether the file is a directory.

Edited by dani, 14 March 2010 - 11:28 AM.


#11 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 14 March 2010 - 04:06 PM

What I meant by overkill was that If StringRight($s_Source, 1) <> "\" Then $s_Source &= "\" does the same as you did with the SRE (and probably faster). The other was just an example. Of course in this case we are talking milli-micro-seconds difference which is virtually no difference at all, I never worry about time differences that are shorter than the blink of an eye unless they are being called in a loop.

What didn't look right had nothing to do with @Extended, it had to do with the positioning of the FileFindNextFile() line which is generally inside the loop.

EDIT: of course mine wasn't right either because I forgot to close the search handle and yours was correct. I was just brain dead.

Edited by GEOSoft, 14 March 2010 - 05:25 PM.

GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#12 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,119 posts

Posted 14 March 2010 - 05:01 PM

I don't get this. The guy is asking for code to copy mp3 files fom one location to some other (nothing more) and you are posting some uber-almost-cooking-coffee-recursive-300-level-fancy scripts.
My advice to program builder is to read FileCopy related page in the help file, check for his permisions in the destination folder and change the nick name.

Edited by trancexx, 14 March 2010 - 05:03 PM.

Yeah baby!

.
eMyvnE


#13 Jos

Jos

    ...

  • Developers
  • 22,953 posts

Posted 14 March 2010 - 05:11 PM

I would even go one steps further as far as an simple advice:
Just open the helpfile for a change.

For somebody that has shown much attitude it the past we can expect better than this .... right?

Edited by Jos, 14 March 2010 - 05:19 PM.

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#14 GEOSoft

GEOSoft

    Sure I'm senile. What's your excuse?

  • MVPs
  • 10,573 posts

Posted 14 March 2010 - 05:29 PM

I would even go one steps further as far as an simple advice:
Just open the helpfile for a change.


Hmmmm, where have I read that before?

Did you check the help file for the functions I used to see what flags can be used with those functions?
Did you bother to look for Dir*() functions in the help file?
Did you look at the example code for the functions in the help file?


As we know, that's where most of the answers are if people would take the time to look.
GeorgeQuestion about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else."Old age and treachery will always overcome youth and skill!"

#15 dani

dani

    Polymath

  • Active Members
  • PipPipPipPip
  • 215 posts

Posted 14 March 2010 - 07:29 PM

True. I have once said most of the topics in General Help and Support would be obsolete if people would actually read the Help file. And I'm not talking about reading through it in 2 minutes but actually take the time, read some tutorials and practice some.

Nevertheless; @program builder: you have enough input now so I'd recommend to either

a | take one of the scripts provided and make sure to fully understand what they do and learn from them
or
b | take trancexx' suggestion and code something yourself.

Btw I wouldn't call the scripts posted an overkill as trancexx does, they do only copy files from one directory to another so .. :mellow: would be nice if they would make my cofee!

Edited by dani, 14 March 2010 - 07:32 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users