Jump to content
Sign in to follow this  
kris06

Dircopy copies only the contents. how to overcome?

Recommended Posts

kris06

Hi all,

Dircopy copies only the contents of a directory passed to it. It simply copies its contents to another location, but fails to copy

the folder itself. how to overcome this?

Rgds,

kris

Share this post


Link to post
Share on other sites
BigDod

Hi all,

Dircopy copies only the contents of a directory passed to it. It simply copies its contents to another location, but fails to copy

the folder itself. how to overcome this?

Rgds,

kris

Works ok for me, post what you tried please.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
kris06

Works ok for me, post what you tried please.

#RequireAdmin

$source = "c:\sip\"
$dest = "d:\hello\"

DirCopy($source,$dest,1)

Initially i thought it was copying the files inside the folder, but i just realised , that its not copying anythin.

Share this post


Link to post
Share on other sites
Valik

Read the documentation. It's very clear on what the problem is.

Share this post


Link to post
Share on other sites
kris06

Read the documentation. It's very clear on what the problem is.

well, it doesnt work eitherway, whether i have a trailing backslash or not.

#RequireAdmin

$source = "c:\sip"
$dest = "d:\sip\"

DirCopy($source,$dest)

Share this post


Link to post
Share on other sites
BigDod

well, it doesnt work eitherway, whether i have a trailing backslash or not.

#RequireAdmin

$source = "c:\sip"
$dest = "d:\sip[s]\[/s]"

DirCopy($source,$dest)
Does the source dir exist ?

Do you have a d drive ?

Does the dest dir exist ?, if so you need the overwrite flag

Edit - Just notice trailing backslash on $dest.

Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
kris06

Does the source dir exist ?

Do you have a d drive ?

Does the dest dir exist ?, if so you need the overwrite flag

Edit - Just notice trailing backslash on $dest.

I am trying to copy a folder from c: drive to d: drive.

The source dir exits? ---yes.

do i have a d drive? ----ofcourse!

does the dest dir exit? no!

heres wht i see,

#RequireAdmin

$source = "c:\sip"
$dest = "d:\sip

DirCopy($source,$dest)

the destination sip directory does not exist. but when i run the above script, it creates a folder sip and copies the contents to it,

but that doesnt help me yet. what i want is when i dont have a "sip" folder in my d: drive, it must be created prior to getting copied. just like a normal windows way of copying a folder to another location.

and wht flags are you talking about ? i only see two of them , 0 and 1. am i missing somethin here?

Share this post


Link to post
Share on other sites
BigDod

the destination sip directory does not exist. but when i run the above script, it creates a folder sip and copies the contents to it,

but that doesnt help me yet. what i want is when i dont have a "sip" folder in my d: drive, it must be created prior to getting copied. just like a normal windows way of copying a folder to another location.

and wht flags are you talking about ? i only see two of them , 0 and 1. am i missing somethin here?

Reread what you have just written. You have just said what happen and what you want to happen but the way you have written makes both statements the same.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
weaponx

Did you refresh the explorer window for drive D: after the copy finished? Also this works with and without trailing slash.

Share this post


Link to post
Share on other sites
kris06

Reread what you have just written. You have just said what happen and what you want to happen but the way you have written makes both statements the same.

BigDod,

apologies!! Heres my bit,

#RequireAdmin

$source = "c:\sip"
$dest = "d:\hello"

DirCopy($source,$dest)

Refer above code. note: destination folder "hello" does not exist.

what i am trying to acheive?: The "sip" folder must get copied as "d:\hello\sip" meaning, a folder called "sip" must be created

inside the "hello" folder and then the contents of the source "sip" folder must get copied to the destination "sip" folder.

Current behavior?: "hello" folder gets created. The contents of the sip folder gets copied to "hello".

what i actually want is "d:\hello\sip"... what i effectively get is "d:\hello"

hope am clear !

Share this post


Link to post
Share on other sites
weaponx

??????????

$source = "c:\sip"

$dest = "d:\hello\sip"

DirCopy($source,$dest)

Share this post


Link to post
Share on other sites
BigDod

You should have said that to start with

#RequireAdmin

$source = "c:\sip"
$dest = "d:\hello\sip"

DirCopy($source,$dest)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
kris06

??????????

$source = "c:\sip"

$dest = "d:\hello\sip"

DirCopy($source,$dest)

In that case, it works, but my purpose is lost then. what happens in a case, where i dont knw what the source folder is?

so having $dest="d:\hello\sip" doesnt help me!

Share this post


Link to post
Share on other sites
weaponx

In that case, it works, but my purpose is lost then. what happens in a case, where i dont knw what the source folder is?

so having $dest="d:\hello\sip" doesnt help me!

How can you copy that which you do not know?

Share this post


Link to post
Share on other sites
BigDod

How can you copy that which you do not know?

Magic :D


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
weaponx

Magic :D

Perhaps he is wearing the Helm of Ludacris Expectations

Share this post


Link to post
Share on other sites
kris06

How can you copy that which you do not know?

ok, this is getting a little confusing now. sorry. heres the story.

This piece of code is part of a slightly bigger code that lets me upload my new builds to my client server.

my script has a gui browse button for both source and destination. now, when i click on the browse, it brings up my root directory and lets me select a folder...lets assume i select "c:\sip\sipchannel" thats the folder for source.

now lets say i select "\\vector\new_release\4.5" as the destination. when i go ahead and upload it, it copies the contents of

"sipchannel" to "\\vector\new_release\4.5", instead of "\\vector\new_release\4.5\sipchannel" .........makes sense?

Share this post


Link to post
Share on other sites
weaponx

$source = @ScriptDir & "\New Folder"
$destination = @ScriptDir & "\New Folder2"

$sourceArray = StringSplit($source, "\")

DirCopy($source, $destination & "\" & $sourceArray[$sourceArray[0]], 1)

Share this post


Link to post
Share on other sites
Valik

The behavior is rather unintuitive. Assume the following source directory structure:

C:\Source\File.txt

What I expect to happen is this:

DirCopy("C:\Source", "C:\Dest")

Source is copied to Dest (current behavior) producing:

C:\Dest\File.txt

However, with:

DirCopy("C:\Source", "C:\Dest\")
I expect the following:

C:\Dest\Source\File.txt

The behavior, as the documentation says, is based off xcopy. I've always found xcopy a pain in the ass to use.

Share this post


Link to post
Share on other sites
kris06

$source = @ScriptDir & "\New Folder"
$destination = @ScriptDir & "\New Folder2"

$sourceArray = StringSplit($source, "\")

DirCopy($source, $destination & "\" & $sourceArray[$sourceArray[0]], 1)
two words!!

nicely done !! :D!!

thanks all you guys !!

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  

×