Jump to content
Sign in to follow this  
ESATU

File copy with create source folder name

Recommended Posts

ESATU

I always use my GUI with drop target to make an easier copy from file or folder with filecopy process...

but the problem is... how to create destination folder name, same as source folder name.. this my GUI...

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Local $Msg, $Box_1, $Box_2
Operation()
Func Operation()
GUICreate("Copy File & Folder", 500, 150, -1,-1, Default, $WS_EX_ACCEPTFILES)
GUICtrlCreateLabel("Copy Files and Folders...", 15, 15, 470, 40)
GUICtrlCreateLabel("From :", 20, 40, 53, 15)
$Box_1 = GUICtrlCreateInput("", 55, 35, 425, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("To :", 20, 65, 53, 15)
    $Box_2 = GUICtrlCreateInput("", 55, 60, 425, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$Bttn1 = GUICtrlCreateButton("Start", 315, 85, 80, 30)
$Bttn2 = GUICtrlCreateButton("Close", 400, 85, 80, 30)
GUISetState()
While 1
$Msg = GUIGetMsg()
Select
  Case $Msg = $GUI_EVENT_CLOSE
  ExitLoop
EndSelect
Select
Case $Msg = $Bttn1
   If File_Copy() Then
    MsgBox(0, "Success", "File was copied")
   Else
    MsgBox(0, "Error", "File was not copied")
   EndIf
Case $Msg = $Bttn2
  Exit
EndSelect
WEnd
EndFunc
Func File_Copy()
$From = GUICtrlRead($Box_1)
$Dest = GUICtrlRead($Box_2)
If Not FileExists($From) Then
        Return 0
    EndIf
    If Not FileExists($Dest) Then
  Return 0
    EndIf
If Not StringInStr(FileGetAttrib($Dest), "D", 1) Then
  Return 0
    EndIf
    If FileCopy($From, $Dest, 9) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

example... if I drop..

From = C:\Pictures\June22

Dest = D:\My File\All Pictures

I want it always to be like this D:\My File\All Pictures\June22, although it is not displayed in the drop input box.. want it to create destination folder name, same as source folder name...

Sorry, I am new in AutoIt and English is not my first language... thanks to all for helping... ;)

Share this post


Link to post
Share on other sites
PhoenixXL

Here We Go

First Input is 'From'

Second Input is 'TO'

Code:

#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $file, $btn, $msg,$sInput
Example()
Func Example()

    GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
    $file = GUICtrlCreateInput("", 10, 5, 300, 20)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $sInput=GUICtrlCreateInput("", 10, 35, 300, 20)  ; will not accept drag&drop files
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $btn = GUICtrlCreateButton("Ok", 40, 75, 60, 20)
    GUISetState()
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
   Case $msg = $btn
    If _FileCopy() Then Return MsgBox(64,"Information","SuccessFull :)")
    Return MsgBox(16,"Information","Failure.....  :(")
                ExitLoop
        EndSelect
    WEnd
EndFunc   ;==>Example
Func _FileCopy()
Local $sFile=GUICtrlRead($file)
Local $sTo=GUICtrlRead($sInput)
If Not StringInStr(FileGetAttrib($sTo),'D',2) Then
  Local $sSplit=StringSplit($sTo,'',1)
  $sTo= $sSplit[$sSplit[0]-1]
EndIf
If Not FileExists($sFile) Then Return 0
If StringRight($sFile,1)='' Then StringTrimRight($sFile,1)
Local $sDirectory=StringSplit($sFile,'',1)
If StringInStr(FileGetAttrib($sFile),'D',2) Then
  $sDirectory=$sDirectory[$sDirectory[0]]
Else
  $sDirectory=$sDirectory[$sDirectory[0]-1]
EndIf
DirCreate($sTo&''&$sDirectory)
GUIDelete()
Return FileCopy($sFile,$sTo&''&$sDirectory,1)
EndFunc

Thumbs Up If it Helped

Regards

Phoenix XL

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
ESATU

Here We Go

First Input is 'From'

Second Input is 'TO'

Wow..! it's great.... Yes..!!! this is what I want.....

Thanks..! Phoenix XL.... ;):) :)

Share this post


Link to post
Share on other sites
PhoenixXL

your welcome ;)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
Mechaflash

HI how do i copy from Appdata/local/Adobe

to Appdata/Roaming/Resources

Tried everything but it wont copy

it wont even make a copy in the same folder like Appdata/local/Adobe - Copy

Tried creating a directory like above and tried copying the contents to the new folder but nothing

Please help

Hijacking is illegal in most countries ;)

You should make your own thread on your problem.


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×