How do i make a folder shortcut wiht Batch Commando Prompt?
i have tried this:
copy "C:\Windows" "C:\Users\%username%\Desktop\Windows.ink"
mklink "C:\Windows" "C:\Users\%username%\Desktop"
#echo off
call :createDesktopShortcut "%~1" "%~2"
exit /b
:createDesktopShortcut targetOfShortcut nameOfShortcut
if not exist "%~f1" goto :eof
setlocal & set "tempFile=%temp%\%~nx0.vbs.tmp" & set "name=%~2" & if not defined name set "name=%~n1"
echo(Set S=WScript.CreateObject("Wscript.Shell"):With S.Createshortcut(S.SpecialFolders("Desktop")+"\%~2.lnk"):.TargetPath="%~f1":.Save:End With>"%tempFile%"
cscript //nologo //e:vbscript "%tempFile%">nul & del /f /q "%tempFile%" >nul 2>nul
endlocal & goto :eof
Save as createDesktopShortcut.cmd and call it as
createDesktopShortcut.cmd "%windir%" "Win directory"
Related
I want the batch file to move files %3 number of times, how can I accomplish this?
%1 is the source folder
%2 is the destination folder
%3 is the number of files
%4 is the filter.
This is the best I could come up with but it doesn't seem to work consistently.
#echo off
SETLOCAL EnableDelayedExpansion
set movedFiles=0
if [%4] EQU [] goto regular
:special
for /R "%1" %%G in (%4) do (
echo moving "%4"... "%%G"
move /Y "%%G" "%2"
set /a movedFiles+="1"
if !movedFiles! EQU %3 GOTO endOfCopy
)
GOTO endOfCopy
:regular
for /R "%1" %%G in (*) do (
echo moving... "%%G"
move /Y "%%G" "%2"
set /a movedFiles+="1"
if !movedFiles! EQU %3 GOTO endOfCopy
)
:endOfCopy
echo Done, %movedFiles% files Where copied successfully
ENDLOCAL
Perhaps you could change your code a little, (and in the meantime see if it fixes your issue):
#Echo Off & SetLocal EnableExtensions DisableDelayedExpansion
If "%~4"=="" (Call :StartMove %* "*") Else Call :StartMove %*
Pause & GoTo :EOF
:StartMove
Set "Moved=0" & For /R "%~1" %%A In ("%~4") Do (SetLocal EnableDelayedExpansion
If !Moved! Equ %3 (EndLocal & Set "Moved=%Moved%" & GoTo EndMessage)
Echo ...Moving "%%A" & Move /Y "%%A" "%~2" >Nul 2>&1 && Set /A Moved +=1)
:EndMessage
Echo Done, %Moved% files were copied successfully & EndLocal & Exit /B
Please note that this code, like yours, does not verify input parameters, (whether they exist, are of the correct type, in the correct order etc), I'd suggest you implement something to do so, moving forward. Even adding something as simple as the following would be a start:
If Not Exist "%~1\" Exit /B
If Not Exist "%~2\" Exit /B
If "%~3"=="" Exit /B
i tryied to delete registered files and folders from a gac.
with my script:
rem #echo off
setlocal ENABLEEXTENSIONS
set OutputFile=log.txt
set ListFile=list.txt
del %OutputFile%
del %ListFile% >> "%OutputFile%"
iisreset >> "%OutputFile%"
dir /d /s /b customdllfile* Logging | findstr /vi ".dll" | findstr /vi "Policy.custompolicy" >> "%ListFile%"
for /f %%a in (%ListFile%) do call :Sub %%a >> "%OutputFile%"
:Sub
del /f /s /q %1"\*" >> "%OutputFile%"
goto :eof
all good, but after delete from a gac the script also delete files from c folder.
what the problem with my script?
I want to copy from source to destination only the files with .txt extension. I want to give as parameters in commandline the path name - source and the path name - destination. Here is my batch file Script.bat:
#ECHO OFF
setlocal
set /p source =
set /p destination=
FOR %%f IN (*.txt) DO XCOPY "%source%"\"%%f" "%destination%" /m /y /d /s
I want to call this batch file in cmd so:
cmd> Script.bat "SourceFolder" "DestinationFolder"
But it doesn't work!
Thank you!
Give this a try. It may not be entirely correct, but it should help you get started.
#echo off
setlocal
set /p source =
set /p destination=
xcopy /m /y /d /s "%~source%\*.txt" "%~destination%\"
Supposing correctness of /m /y /d /s xcopy switches this script could work:
#echo off
setlocal
if "%~1"=="" goto :error empty 1
if "%~2"=="" goto :error empty 2
set "source=%~1"
if not exist "%source%\" goto :error not exist 1
set "destination=%~2"
if not exist "%destination%\" goto :error not exist 2
xcopy "%source%\*.txt" "%destination%\" /m /y /d /s
goto :eof
:error
echo wrong parameters %*
goto :eof
See also next resource: Command Line arguments (Parameters)
I have the following batch script to replace the supplied text with some other text.
#echo off
setlocal
call :FindReplace %1 %2 %3
exit /b
:FindReplace <findstr> <replstr> <file>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b
:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with
Now, I am trying to automate the build and set up of my application. I invoke the above script from following batch.
#echo off
set a=C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf
call Text_Replacer "branch-1" "branch-2" "%a%"
Due to the ')' in the path, I get the following in the console.
\Apache was unexpected at this time.
Please help me to escape the ')'.
This is one problem: change "%3" to "%~3"
It is why the characters in the path string are not protected, because %3 is already double quoted.
I used a tip on how to do what I want, but I have a difficulty, the folders that begin with "!" ex.: c:\!test and in the middle is "." ex.: c:\test.test are not erased. You can help me?
#Echo OFF
echo.
setlocal enabledelayedexpansion
echo Search...
FOR /R %root% %%A IN (.) DO (
if '%%A'=='' goto end
set dir="%%A"
set dir=!dir:.=!
set directory=%%A
set directory=!directory:.=!
set directory=!directory::=!
set directory=!directory:\=;!
for /f "tokens=* delims=;" %%P in ("!directory!") do call :loop %%P
)
:end
echo.
echo Finished.
echo Press any key to exit...
pause >nul
endlocal
exit
:loop
if '%1'=='' goto endloop
if '%1'=='history' (
rd /S /Q !dir!
echo !dir! was deleted.
)
SHIFT
goto :loop
:endloop
I think your code checks every folder and if it finds ones called history then they are all deleted.
If that is the task then this should do the same thing.
#echo off
FOR /D /R %root% %%A IN (*) DO if /i "%%~nxA"=="history" if exist "%%A\" rd /s /q "%%A" & echo "%%A" has been deleted