Batch programozás - Szoftverfejlesztés fórum

üzenetek

hozzászólások


sonar
(addikt)
Blog

Szerintem nem 7z függő, hanem bármi ami a Program Files (x86) -ban van az problémás.
Mondjuk nekem még a Notepad++ van ott (érthetetlen okból)
Gyors próba alapján azt sem képes elindítani.


mepet
(addikt)

Anno kuzdottem hasonloval, a vegen a megoldas az lett, hogy az exe fajlt atmasoltam a munkakonyvtarba, futtattam ott, majd toroltem. Persze ehhez standalone exe kell.


sonar
(addikt)
Blog

Ugye tudod, hogy a cmd /c hívásnál a munkakönyvtár mi? :N Oda nem másolunk.


csadi0011
(őstag)

Nem értettem, hogy nekem miért volt jó. Én kicsit tisztítottam a programodon, hogy könnyebben átlássam.
Most kipróbáltam az egészet és nekem is ezt az unexpected hibát írja.
Az if @fsize nem jó. Ha átírtam pl. így: if @fsize GTR 0 vagy kitöröltem, akkor jó volt.
Próbálgattam az if-et, de szám bemenettel vagy logikai vizsgálat nélkül parancssorból és scriptből sem működött. Viszont akkor hogyan futott le neked eddig másik mappából?

[ Szerkesztve ]


sztanozs
(veterán)
Blog

Ez nekem mukodik x86-bol:
@echo off
set "A510=c:\temp\py"
set "fullstamp=2023-02-28"
set "b_backup=\\server\backup"
IF EXIST "%A510%" (
FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C if @isdir==FALSE if @fsize GTR 0 0x22c:\Program Files 0x28x860x29\Microsoft Visual Studio\Shared\Python39_64\python.exe0x22 -c 0x22print(r'%b_backup%\%fullstamp%.zip @file')0x22"
)

Kimenet:
\\server\backup\2023-02-28.zip certificates.py
\\server\backup\2023-02-28.zip search_dump.py
^CTerminate batch job (Y/N)?

[ Szerkesztve ]


csadi0011
(őstag)

Neked ez hogy működik ^ nélkül? Ha 0x22-t írok ^0x22 helyett, akkor nekem már nem jó.
Amúgy sem értem, hogy miért értelmezné a szoftver a 0x22-t másnak, mint ami. Mi van ha a mappanévben vagy fájlnévben van 0x22? Nem tiltott és nem speciális.


sztanozs
(veterán)
Blog

ez a forfiles sajatja, nem a cmd/c ertelmezi, forfile commandban nem kell escape-elni

[ Szerkesztve ]


csadi0011
(őstag)

Azt értem, hogy a forfiles /c " után érvényes, de miért működik escape nélkül?
Én neveztem már el mappát win10x64-nek.

Veszélyes...

[ Szerkesztve ]


sonar
(addikt)
Blog

Win11-en itthon:
Ez működik:
FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C ^0x22c:\Program^ Files^ ^(x86)\ImgBurn\ImgBurn.exe^0x22"

Ezek nem
FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C ^0x22c:\Program Files 0x28x860x29\ImgBurn\ImgBurn.exe^0x22"
'"c:\Program' is not recognized as an internal or external command,
operable program or batch file.

sztanozs - elvileg ez a te mintád ami szintén nem megy a win11-en.
FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C 0x22c:\Program Files 0x28x860x29\ImgBurn\ImgBurn.exe0x22"
'c:\Program' is not recognized as an internal or external command,
operable program or batch file.

FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C "c:\Program Files 0x28x860x29\ImgBurn\ImgBurn.exe""
FORFILES /P "c:\oem\CareCenter\DebugLog" /S /M *.* /C "cmd /S /C "c:\Program Files 0x28x860x29\ImgBurn\ImgBurn.exe""
ERROR: Invalid argument/option - 'Files'.

FORFILES /P "%A510%" /S /M *.* /C "cmd /S /C "c:\Program Files (x86)\ImgBurn\ImgBurn.exe""
FORFILES /P "c:\oem\CareCenter\DebugLog" /S /M *.* /C "cmd /S /C "c:\Program Files (x86)\ImgBurn\ImgBurn.exe""
ERROR: Invalid argument/option - 'Files'.


sztanozs
(veterán)
Blog

Nekem Win10 van, lehet, hogy ez a kulonbseg...


sztanozs
(veterán)
Blog

Ezert is irja a help, hogy celszeru a FORFILES helyett sima FOR+parameter extension-t hasznalni... Egy bughalmaz az egesz.
Vagy meginkabb powershell, azt sokkal nehezebb elb*bni.

[ Szerkesztve ]


sztanozs
(veterán)
Blog

Powershell:
$A510="c:\temp\A510\"
$fullstamp="2023-02-28"
$b_backup="\\server\backup"
Get-ChildItem $A510 -recurse -Filter *.* | ForEach-Object {
if ($_.Attributes -ne "Directory") {
if ($_.Length -gt 0) {
Start-Process -WorkingDirectory $A510 -FilePath "c:\Program Files (x86)\7-Zip\7z.exe" -ArgumentList "a `"$($b_backup)$($fullstamp).zip`" `"$($_.Directory)\$($_.Name)`"" -Wait
}
}
}

[ Szerkesztve ]


sonar
(addikt)
Blog

Nem powershell-ezek, és a forfiles probléma csak egy része volt a batch file-nak.
Arról nem beszélve, hogy PS1 futtatáshoz módosítani kell a policy-t vagy batchből hivni -e bypass paraméterrel.

Nem érzem az ambiciót, hogy mindent a nyakamba vegyek.


sztanozs
(veterán)
Blog

Akkor ennek mennie kell:
@echo off
SET "A510=c:\temp\A510"
SET "fullstamp=2023-02-28"
SET "b_backup=\\server\backup"
IF EXIST "%A510%" (
FOR /R "%A510%" %%G IN (*) DO (
IF %%~zG GTR 0 "c:\Program Files (x86)\7-Zip\7z.exe" a "%b_backup%\%fullstamp%.zip" "%%G"
)
)

[ Szerkesztve ]


sonar
(addikt)
Blog

Le is fut rendesen.


include777
(aktív tag)

Szia!

Powershellel:
$sourcePath = "C:\originalfiles\"
$destinationPath = "C:\convertfiles\"
if (!(Test-Path $destinationPath))
{
    New-Item -ItemType Directory -Path $destinationPath
}
Get-ChildItem -Path $sourcePath -File | ForEach-Object {
 Write-Host "Converting $_" 
 $content = Get-Content $_.FullName
 Set-content (Join-Path -Path $destinationPath -ChildPath $_) -Encoding Ascii -Value $content
}


sonar
(addikt)
Blog

Most néztem meg jobban a kódot és értelmezni próbáltam, ezt %%~zG el tudod magyarázni?


sztanozs
(veterán)
Blog

Ha nem baj, nem forditom le magyarra (megfelelo sort kiemeltem):

Parameter Extensions
When an argument is used to supply a filename then the following extended syntax can be applied:
We are using the variable %1 (but this works for any argument, including FOR parameters).
%~f1 Expand %1 to a Fully qualified path name - C:\utils\MyFile.txt
%~d1 Expand %1 to a Drive letter only - C:
%~p1 Expand %1 to a Path only e.g. \utils\ this includes a trailing \ which will be interpreted as an escape character by some commands.
%~n1 Expand %1 to a file Name without file extension or path - MyFile
or if only a path is present, with no trailing backslash, the last folder in that path.
%~x1 Expand %1 to a file eXtension only - .txt
%~s1 Change the meaning of f, n, s and x to reference the Short 8.3 name (if it exists.)
%~1 Expand %1 removing any surrounding quotes (")
%~a1 Display the file attributes of %1
%~t1 Display the date/time of %1
%~z1 Display the file size of %1
%~$PATH:1 Search the PATH environment variable and expand %1 to the fully qualified name of the first match found.

The modifiers above can be combined:
%~dp1 Expand %1 to a drive letter and path only.
%~sp1 Expand %1 to a path shortened to 8.3 characters.
%~nx2 Expand %2 to a file name and extension only.

[ Szerkesztve ]


sonar
(addikt)
Blog

Köszönöm, így tökéletes. Ma is tanultam valami újat.

[ Szerkesztve ]


sztanozs
(veterán)
Blog

Akkor bedobok meg egy trukkot. Ha jo a local beallitas, akkor a datum is kisakkozhato, nem kell kezzel megadni:
SET fullstamp=%DATE:~6,4%-%DATE:~0,2%-%DATE:~3,2%

Reszletek: [link]

üzenetek