1.

Solve : Copy %CD% to server %username%?

Answer»

So were doing a server move and staff rename and didn't want to COPY all our staffs old files over to the new one. We wanted them to do it so were not storing old stuff they never use anymore.

I would like to be able to copy the current location the .bat file will be in (on the old server \\server\staff_folders\userfolder) to \\server\staffhome\%USERNAME\


So figured something like below but just can't get it to work. I am prolly missing something simple..

Copy current directory to their new staff folder.

netuse x: \%cd%
copy x: \\file1\staffhome\%USERNAME%\

I'm not going to be using this for every staff member but it would help me speed up the process as I know a bunch of them that constantly use their space properly.

Any help would be greatly appreciated!!! In a batch, the directory where that batch file is located (physically stored) is %~p0, (that's a zero) so you could try using that instead of %cd% which is the current directory, which is not necessarily the same.

Full path and name would be %~dp0


Thanks I tried switching that out and it still doesn't work :/

That's good to know for FUTURE reference!! You will not get the server and share name from %cd% or %~dp0

net use x: \\server\staff_folders\userfolder

or

pushd "\\server\staff_folders\userfolder"
:: commands here
popd
OK after searching and searching here is what I've come up with that works..

Now the only problem I'm having is I'm trying to run this on XP and Win7. Since they changed Documents and Settings to Documents I need to figure out a way to have it check somehow. If anyone knows a way that would be great, I'm still searching and learning.


@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /h /i /r /k /y /EXCLUDE:excludebackupcopy.txt

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up your Desktop...
%backup% "%USERPROFILE%\Desktop" "\\file1\staffhome\%USERNAME%\Desktop\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\Documents" "\\file1\staffhome\%USERNAME%\My Documents\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseYou could parse the output of the VER command and do different THINGS according to the major version number (5 for Windows 2000 & XP, 6 for Vista, W7 & W8)

e.g. (just a pointer):


for /f "tokens=1-6 delims=. " %%A in ('ver') do (
if "%D"=="6" (
set pname=Documents
) else (
set pname=My Documents
)
)


2000
Microsoft Windows 2000 [Version 5.00.2195]

xp
Microsoft Windows XP [Version 5.1.2600]

windows Vista
Microsoft Windows [Version 6.0.6001]

Windows 7
Microsoft Windows [Version 6.1.7600]


Awesome sounds PERFECT!!!

I've tried it a few different ways but still can't figure out how to implement it into this. Here is where is makes logical sense to me lol Still kinda learning this stuff..


Code: [Select]@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /i /r /k /y /EXCLUDE:excludebackupcopy.txt

for /f "tokens=1-6 delims=. " %%A in ('ver') do (
if "%D"=="6" (
set pname=Documents
) else (
set pname=My Documents
)
)

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\My Documents" "\\file1\staffhome\%USERNAME%\My Documents\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseTry this:

Code: [Select]@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /i /r /k /y /EXCLUDE:excludebackupcopy.txt

ver |find " 6.">nul && (set pname=Documents) || (set pname=My Documents)

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\%pname%" "\\file1\staffhome\%USERNAME%\%pname%\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseThanks but now I get errors. Invalid drive specification..


Code: [Select]This PC is running Windows 7 Enterprise
### Backing up current folder...
Invalid drive specification
0 File(s) copied
### Backing up My Documents...
Invalid drive specification
0 File(s) copied
### Backing up Favorites...
Invalid drive specification
0 File(s) copied
Backup Complete!
Press any key to continue . . .
You are also getting errors in lines that I did not alter.


The \\file1 server is not online probably.
Well this is odd. My old script that was working yesterday isn't working either...

Servers are up and running. I can browse to each location, create, view, and edit files.. Try this:

Code: [Select]@echo off
dir "\\file1\staffhome"
pause
Well your version worked!!! Thanks!

My boss changed a ton of permissions yesterday. So I setup a share on a local machine and it worked perfectly! Now to figure out what he changed.......

Thanks for your help!!!!



Discussion

No Comment Found