Robocopy "invalid parameter" for file names beginning with "-" (minus sign) - robocopy

I use robocopy to backup folders and individual files via a batch file. This works fine for all folders and nearly all files, but not for files where the name starts with a "-" (minus sign).
My OS: German Windows 7, 64 Bit. (I don't know if that matters.)
My test batch file does this:
SET fileName=-Test.rar
robocopy "folder 1" "folder 2" "%fileName%"
ECHO Errorlevel: %Errorlevel%
Where %fileName% is quoted because the file name may contain spaces as well.
The result is an ERROR : Invalid Parameter.
-------------------------------------------------------------------------------
ROBOCOPY :: Robustes Dateikopieren für Windows
-------------------------------------------------------------------------------
Gestartet: Wed Nov 21 15:42:47 2018
Quelle - E:\BackupThisFile\folder 1\
Ziel - E:\BackupThisFile\folder 2\
Dateien :
Optionen: /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
FEHLER: Ungültiger Parameter #3 : "-Test.rar"
[...]
Errorlevel: 16
Tested versions of "robocopy.exe":
XP010 (Windows XP?)
XP026 (Windows 2000?)
XP027 Win7 32 Bit
XP027 Win7 64 Bit
It always resulted in the same error message or only the equivalent error code 16.
Tested variation of the command:
Then i have tried different variations of the command. Only 1 change (additional quotes) looked remotely promising:
robocopy "folder 1" "folder 2" \""%fileName%""
But it didn't work either:
-------------------------------------------------------------------------------
ROBOCOPY :: Robustes Dateikopieren für Windows
-------------------------------------------------------------------------------
Gestartet: Wed Nov 21 15:43:00 2018
Quelle : E:\BackupThisFile\folder 1\
Ziel : E:\BackupThisFile\folder 2\
Dateien : "-Test.rar"
Optionen: /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
0 E:\BackupThisFile\folder 1\
------------------------------------------------------------------------------
Insgesamt KopiertÜbersprungenKeine Übereinstimmung FEHLER Extras
Verzeich.: 1 0 1 0 0 0
Dateien: 0 0 0 0 0 0
Bytes: 0 0 0 0 0 0
Zeiten: 0:00:00 0:00:00 0:00:00 0:00:00
Nothing was copied even though the file name parameter was kind of recognized.
I guess that the quotes in the value of the parameter are wrong as well.
Does anyone have an idea?

Related

Robocopy behaves differently when running directly or from powershell script

I have a script that copies a file from a network location to a local folder using robocopy.
When I run following powershell 7 script from Visual Code, or execute the command directly in PS, only 1 file is copied as intended. If a run the script in powershell 4 files are copied. How can I copy the single file running from the script.
$dbname = "domoticz.db"
$sourcedir="\\ix2\PiBackup\domoticz\"
$targetdir="C:\tmp\DomoticzScripts\"
$dbfile = $targetdir + $dbname
robocopy $sourcedir $targetdir $db -njh
Output running it directly or VS Code debugger
New Dir 1 \\ix2\PiBackup\domoticz\
100% New File 8.9 m domoticz.db
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 1 1 0 0 0 0
Bytes : 8.96 m 8.96 m 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 70709894 Bytes/sec.
Speed : 4046.052 MegaBytes/min.
Ended : zaterdag 30 mei 2020 11:45:40
Running it in a script
New Dir 4 \\ix2\PiBackup\domoticz\
100% New File 8.9 m domoticz.db
100% New File 32768 domoticz.db-shm
100% New File 0 domoticz.db-wal
100% New File 9.0 m domoticz_.db
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 4 4 0 0 0 0
Bytes : 18.05 m 18.05 m 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Speed : 75125841 Bytes/sec.
Speed : 4298.735 MegaBytes/min.
Ended : zaterdag 30 mei 2020 11:47:06

Parsing Text String

I have created a running windows process list to a text file using the command:
tasklist > c:\mytasklist.txt. The result something like this:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 24 K
System 4 Services 0 12.408 K
smss.exe 320 Services 0 1.236 K
csrss.exe 424 Services 0 4.720 K
wininit.exe 516 Services 0 4.684 K
csrss.exe 524 Console 1 7.888 K
winlogon.exe 572 Console 1 7.764 K
services.exe 620 Services 0 9.532 K
and so on...
My question:
How I parsing the line on the text file, so I get output like the following format using Lua script:
PID - Process Name - Memory Usage
And the output automatic sorted by the biggest memory usage
local tasklist = io.popen"tasklist /fo csv /nh"
local list = {}
for line in tasklist:lines() do
local exe, pid, mem = line:match'^"(.-)","(%d+)",.-"([^"]+)"$'
table.insert(list, {pid = tonumber(pid), exe = exe, mem = tonumber((mem:gsub("%D", "")))})
end
tasklist:close()
table.sort(list, function(a, b) return a.mem > b.mem end)
for j = 1, math.min(10, #list) do
print(list[j].pid, list[j].mem, list[j].exe)
end
Output:
1036 549416 svchost.exe
4972 439524 firefox.exe
6540 214476 plugin-container.exe
7144 169268 OUTLOOK.EXE
532 75320 svchost.exe
1948 71644 avp.exe
3752 62704 svchost.exe
5268 61100 explorer.exe
596 56732 csrss.exe
5048 50248 CcmExec.exe

Robocopy Summary Times not correct

I've set up a robocopy script and it functions correctly.
However, within the summary in the log file, the Total Times does not make sense to me as the job runs for about 109 minutes, but total returns 3:39:06?
Can someone explain why this looks wrong.
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : 03 April 2019 20:30:04
Source : G:\Backup\
Dest : \\newserver\Backup\
Files : refresh*
Options : /V /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /Z /PF /MT:1 /R:5 /W:5
------------------------------------------------------------------------------
New File 21.0 g G:\Backup\refresh.bak
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 1 0 0 0 0
Files : 1 1 0 0 0 0
Bytes : 21.019 g 21.019 g 0 0 0 0
Times : 3:39:06 0:54:46 0:00:00 0:54:46
Ended : 03 April 2019 22:19:37

Perl touch -t file error for a future date

I am trying to touch a file(for referencing date) with a future date something like -
Current date - $date
Fri Jan 6 03:59:55 EST 2017
touch -t 201702032359.59 /var/tmp/ME_FILE_END
on checking the timestamp of the file as -
$ ls -lrt /var/tmp/ME_FILE_END
getting an output with only date and not the entire timestamp(hhmm.sec)
-rw-r--r-- 1 abcproc abc 0 Feb 3 2017 /var/tmp/ME_FILE_END
But for a date with is less than or equal to current it gives correct result -
touch -t 201612010000.00 /var/tmp/ME_FILE_START
ls -lrt /var/tmp/ME_FILE_START
-rw-r--r-- 1 abcproc abc 0 Dec 1 00:00 /var/tmp/ME_FILE_START
Can someone please suggest why this discrepancy ?
It's just the way ls displays the date. When far from now, the modification time is not displayed.
If you want details regarding the last access / modification / change time, you should be using stat.
stat /var/tmp/ME_FILE_END
You will see the expected output.
For example:
[10:29:41]dabi#gaia:~$ touch -t 201702032359.59 /var/tmp/ME_FILE_END
[10:29:43]dabi#gaia:~$ ls -ltr /var/tmp/ME_FILE_END
-rw-rw-r-- 1 dabi dabi 0 feb. 3 2017 /var/tmp/ME_FILE_END
[10:29:47]dabi#gaia:~$ stat /var/tmp/ME_FILE_END
File : '/var/tmp/ME_FILE_END'
Size : 0 Blocks : 0 I/O blocks : 4096 empty file
Device : 803h/2051d Inode : 5374373 Links : 1
Access : (0664/-rw-rw-r--) UID : ( 1000/ dabi) GID : ( 1000/ dabi)
Access : 2017-02-03 23:59:59.000000000 +0100
Change : 2017-02-03 23:59:59.000000000 +0100
Change : 2017-01-06 10:29:43.364630503 +0100
Birth : -

How can I add totals from a file in a dos batch

I want to add totals from lines in a text file.
My file.txt looks like this:
Totals: 7 passed, 0 failed, 0 skipped
Totals: 10 passed, 0 failed, 0 skipped
Totals: 6 passed, 0 failed, 0 skipped
Totals: 9 passed, 0 failed, 0 skipped
Totals: 4 passed, 0 failed, 1 skipped
Totals: 31 passed, 0 failed, 0 skipped
Totals: 10 passed, 0 failed, 0 skipped
Totals: 4 passed, 0 failed, 0 skipped
Totals: 8 passed, 0 failed, 0 skipped
So when I run sumtotals.bat file.txt then I want something like this:
Passed : XX
Failed : 0
Skipped: X
You can to this:
#echo off
set passed=0
set failed=0
set skipped=0
for /f "tokens=2,4,6 delims= " %%a in (%1) do call :add %%a %%b %%c
echo passed=%passed%
echo failed=%failed%
echo skipped=%skipped%
goto :eof
:add
REM echo %1 %2 %3
set /a passed=%passed%+%1
set /a failed=%failed%+%2
set /a skipped=%skipped%+%3
:eof
result:
C:\temp>sumtotals.bat file.txt
passed=89
failed=0
skipped=1