Page 1 of 1

copy folder

PostPosted: Tue Mar 19, 2013 12:52 am
by xide
I am having a hard time trying to copy a folder from my flash drive to client desktop.

Full details:
I have a folder on my flash drive that contains some useful items for my client to use, I would like to copy this folder to the client desktop. I would also like to change this icon of the folder (i should be able to set that when i create the folder on my flash drive as long as i use a windows icon). I would like to be able to run as a script so I can use it with D7 to run automatic. Of course this will be used on XP,Vista,7,8 and the username will be different so it would have to be universal, I know that should be a given but I just wanted to point that just in case. No need for below XP. I don't know if it matters but running as admin won't be an issue either.

Thank you for your help.....I have been trying for days now with no luck, so I really appreciate anything you can give me no matter how sloppy it may be just as long as it does the job.

Re: copy folder

PostPosted: Tue Mar 19, 2013 7:07 am
by Nick
Where is the folder located on your flash drive? Root?

Re: copy folder

PostPosted: Tue Mar 19, 2013 7:31 am
by Nick
I'm going to assume the folder is in the root directory of your flash drive. If so this will work great. The ONLY thing you need to change in this batch is the set sourcedir= line to read the name of your directory instead of My Directory and this should work out. Of course you'll need admin privileges on Vista+ but if you're running this from D7 it won't matter.

Code: Select all
:: set echo off and change to the root directory.
@echo off&pushd "%~dp0"&cd\

:: CHANGE ME
set sourcedir=My Directory

:: Check Windows Version
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto XP

:: Vista and above goes here
set destdir=%public%\Desktop\%sourcedir%
goto :end

:: Windows XP Code goes here
:XP
set destdir=%allusersprofile%\Desktop\%sourcedir%
goto :end

:: Do the copy
:end
if exist %sourcedir% (xcopy "%sourcedir%" "%destdir%" /y /s /c /i /h /r)

Re: copy folder

PostPosted: Tue Mar 19, 2013 11:18 pm
by xide
I only have access to a windows 7 and 8 machine here at home. I tried on both and couldn't get it to work, I even renamed the directory to "folder" in case it had an issue with spaces. Yes my directory named "folder" is in the root of the flash drive. Also I did run as admin, and I do plan to put this in D7 once I get it working.

I have also tried playing around with the path name as well such as capitalization, putting the full path and still nothing Here is what I have now....

:: set echo off and change to the root directory.
@echo off&pushd "%~dp0"&cd\

:: CHANGE ME
set sourcedir=folder

:: Check Windows Version
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto XP

:: Vista and above goes here
set destdir=%public%\Desktop\%sourcedir%
goto :end

:: Windows XP Code goes here
:XP
set destdir=%allusersprofile%\Desktop\%sourcedir%
goto :end

:: Do the copy
:end
if exist %sourcedir% (xcopy "%sourcedir%" "%destdir%" /y /s /c /i /h /r)

Re: copy folder

PostPosted: Wed Mar 20, 2013 10:16 am
by Nick
What do you mean it doesn't work? What happens if you put a "pause" (no quotes) at the end of the batch - what is displayed in the console window?

The batch I posted works, I did test on WinXP and on 8 just now to confirm. If you are testing outside of D7 be sure to run as administrator on Vista+!!

Re: copy folder

PostPosted: Wed Mar 20, 2013 1:38 pm
by xide
when I place a pause in it it comes back with "0 files copied" I must have done something wrong if it's working fine for you....this is a .bat right? And yes I have been running it as admin

Re: copy folder

PostPosted: Wed Mar 20, 2013 1:40 pm
by xide
lmao....nevermind that last post, I really feel dumb now. I had to put something in the folder lol. I apologize, thanks for your help and your patience. I really appreciate it. Sorry again for my mistake.

Re: copy folder

PostPosted: Wed Mar 20, 2013 2:10 pm
by xide
One more question...I changed the folder icon to one that is used in xp,vista,7,8 which is the red power button. However when the folder is copied the icon doesn't stay. Any ideas of what I can try? thanks again

Re: copy folder

PostPosted: Wed Mar 20, 2013 2:23 pm
by Nick
Yeah, I don't think there is a way to copy that attribute on the directory actually. I'll see if I can figure something out

Re: copy folder

PostPosted: Fri Mar 29, 2013 11:43 am
by darkman738
xide wrote:One more question...I changed the folder icon to one that is used in xp,vista,7,8 which is the red power button. However when the folder is copied the icon doesn't stay. Any ideas of what I can try? thanks again


This: http://msdn.microsoft.com/en-us/library/cc144102(v=vs.85).aspx may help. You need to set the icon in a desktop.ini file inside the folder, you may also need to put the .ico file inside the folder as well.