windows - RoboCopy giving error in universal file path -


i conducting arduino hid research. trying set leo open powershell , make of .pdfs in documents folders flash drive volume name.

i want portable different machines. specified file path includes username can not used.

the original script found one.

    param([parameter(mandatory=$true)]$volumename,       [parameter(mandatory=$true)]$srcdir)  # find connected backup drive: $backupdrive = $null get-wmiobject win32_logicaldisk | % {     if ($_.volumename -eq $volumename) {         $backupdrive = $_.deviceid     } } if ($backupdrive -eq $null) {     throw "$volumename drive not found!" }  # mirror  $backuppath = $backupdrive + "\" & robocopy.exe $srcdir $backuppath /mir /z 

the problem having when pass path of c:\users\$env:username\documents\ powershell throws error stating.

"error 123 (0x0000007b) accessing source directory c:\users\$env:username\documents\ filename, directory name, or volume label syntax incorrect." 

next tried removing $srcdir parameter , specifying path in variable new script looking this:

param([parameter(mandatory=$true)]$volumename)  $backupdrive = $null  get-wmiobject win32_logicaldisk | % {    if ($_.volumename -eq $volumename) {        $backupdrive = $_.deviceid     }  }   $backuppath = $backupdrive + "\"  $source=@($env:username + "\documents\") $destination=@($backuppath)  robocopy $source  $destination *.pdf /mir /z 

that failed giving me path error apparently robocopy imputing username twice seen here:

    -------------------------------------------------------------------------------    robocopy     ::     robust file copy windows -------------------------------------------------------------------------------    started : tuesday, august 15, 2017 3:49:04    source : c:\users\me\me\documents\      dest = f:\      files : *.pdf    options : /s /e /dcopy:da /copy:dat /purge /mir /z /r:1000000 /w:30  ------------------------------------------------------------------------------  2017/08/15 03:49:04 error 3 (0x00000003) accessing source directory c:\users\damav\damav\documents\ system cannot find path specified. 

so edited last line include direct path , no varible.

robocopy c:\users\$env:username\documents\  $backupdrive *.pdf /mir /z  

the output gave different results confuses me more rest of issues. have look:

-------------------------------------------------------------------------------    robocopy     ::     robust file copy windows -------------------------------------------------------------------------------    started : tuesday, august 15, 2017 3:55:36    source : c:\users\me\documents\      dest = f:\      files : *.pdf    options : /s /e /dcopy:da /copy:dat /purge /mir /z /r:1000000 /w:30  ------------------------------------------------------------------------------                             0    c:\users\me\documents\                            0    c:\users\me\documents\my music\           new dir          0    c:\users\me\documents\my pictures\ 2017/08/15 03:55:36 error 5 (0x00000005) time-stamping destination directory f:\my pictures\ access denied. waiting 30 seconds... retrying... 2017/08/15 03:56:07 error 5 (0x00000005) time-stamping destination directory f:\my pictures\ access denied. waiting 30 seconds... 

the reason why confusing because these directories robocopy tried copy not exist within documents folder nor flash drive. c:\users\me\documents\

c:\users\me\documents\my music\ c:\users\me\documents\my pictures\ f:\my pictures\

so stumped , came here ask pros assistance. have tried %username% , %userprofile% in file path using same script variations stated above didn't work either due robocopy assuming part of actual path name. i.e. c:users\%userprofile%\documents

so conclude need able plug named volume flash drive pc. insert arduino have type out command in cmd, powershell, or create .ps1 in notepad issue having source directory path not being recognized when not using specific user name in path not possible due need have portable across machines , users.

issue 1:
problem having when pass path of c:\users\$env:username\documents\ powershell throws error stating.

just assuming, sounds issue on how transmit path. take @ following code:

'c:\users\$env:username\documents\' "c:\users\$env:username\documents\" 

both lines generating string, second 1 "translates" correct path. powershell differentiates between normal quotes (") , single quotes ('). see about quoting rules more information.

the script works fine on test using normal quotes source directory.

issue 2:
next tried removing $srcdir parameter , specifying path in variable new script looking this: failed giving me path error apparently robocopy imputing username twice seen here:

your issue here $env:username contains username, depending on start script code behave differently. starting c:\users\me translates c:\users\me\me\documents, in c:\users have translated c:\uses\me\documents , have worked. instead of hard coded path $env:username use:

"$env:userprofile\documents" 

issue 3: reason why confusing because these directories robocopy tried copy not exist within documents folder nor flash drive. c:\users\me\documents\

the robocopy error tells can't write on target, permission/file system (ntfs fat32?) issue. make sure can write on flash drive. e.g. try first write without powershell script use robocopy directly

robocopy c:\users\me\documents\ f:\ *.pdf /mir /z 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -