Best4FREE Posted April 23, 2008 Share Posted April 23, 2008 Hi can someone give me a code that Copy a file and save it in a other folder under random name ? Link to comment Share on other sites More sharing options...
spudw2k Posted April 23, 2008 Share Posted April 23, 2008 Like This? $srcfile = FileOpenDialog("Copy File",@WorkingDir,"(*.*)") If Not FileExists($srcfile) Then Exit $destfolder = FileSelectFolder("Save to","") If Not FileExists($destfolder) Then Exit $rnd = Random(1,100,1) Do If StringLen($rnd) < 3 Then $rnd = "0" & $rnd Until StringLen($rnd) = 3 $extension = "." & StringRight($srcfile,StringLen($srcfile)-StringInstr($srcfile,".")) $filename = "screenshot" $file = $destfolder & "\" & $filename & $rnd & $extension FileCopy($srcfile,$file) If FileExists($file) Then Msgbox(0,"Done.","Filed Copied Successfully." & @CRLF & $srcfile & @CRLF & $file) Else Msgbox(16,"Failed.","Failed to Copy File." & @CRLF & $srcfile & @CRLF & $file) EndIf Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
martin Posted April 23, 2008 Share Posted April 23, 2008 Like This? $srcfile = FileOpenDialog("Copy File",@WorkingDir,"(*.*)") If Not FileExists($srcfile) Then Exit $destfolder = FileSelectFolder("Save to","") If Not FileExists($destfolder) Then Exit $rnd = Random(1,100,1) Do If StringLen($rnd) < 3 Then $rnd = "0" & $rnd Until StringLen($rnd) = 3 $extension = "." & StringRight($srcfile,StringLen($srcfile)-StringInstr($srcfile,".")) $filename = "screenshot" $file = $destfolder & "\" & $filename & $rnd & $extension FileCopy($srcfile,$file) If FileExists($file) Then Msgbox(0,"Done.","Filed Copied Successfully." & @CRLF & $srcfile & @CRLF & $file) Else Msgbox(16,"Failed.","Failed to Copy File." & @CRLF & $srcfile & @CRLF & $file) EndIf Ummm. If you want a random number with 3 digits then you might as well use Random(100,999,1). Using 1 to 100 only allows for 100 different files which might not be enough. I don't know if 900 is enough either. However, you need to ensure that the "random" number isn't repeated or a file will get overwritten. The easiest way (I think) to generate a unique number, if that is what is needed rather than a random number, is to use the date and time which is never repeated. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
spudw2k Posted April 23, 2008 Share Posted April 23, 2008 (edited) That was just an example. I'd say you could even do Random(1,999,1). The only reason I put zeros in front (if length isn't full) is so files are sorted properly. Also, yes the file will overwrite with this code, but it's not hard to add a check for that. Edited April 23, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
martin Posted April 23, 2008 Share Posted April 23, 2008 That was just an example. I'd say you could even do Random(1,999,1). The only reason I put zeros in front (if length isn't full) is so files are sorted properly.OK. Also, yes the file will overwrite with this code, but it's not hard to add a check for that. Agreed do $randomNum = Random(100,999,1) until not FileExists($path & "\" & $randomNum & ".xyz") Which is ok until you have 900 files and then it will get stuck. With the date way there is no problem with duplicates and displaying by name will also give them in date order. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
spudw2k Posted April 23, 2008 Share Posted April 23, 2008 Which is ok until you have 900 files and then it will get stuck. With the date way there is no problem with duplicates and displaying by name will also give them in date order.Fair 'nough. Didn't think about that. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now