batch-file

How to replace a string with a substring when there are parentheses in the string

牧云@^-^@ 提交于 2021-02-08 05:06:07
问题 I have been scratching my head for the last two days trying to put together a code that reads a folder structure and the strips off the base path of the listing. What I have so far is this: @ECHO OFF CLS SETLOCAL EnableExtensions EnableDelayedExpansion SET "StartTime=%TIME: =0%" SET "Folder=%~1" IF "%Folder:~-1%"=="\" SET "Folder=%Folder:~0,-1%" FOR %%G IN ("%Folder%") DO SET "Archive=%%~nxG" ECHO Processing %Folder%... ECHO. PUSHD "%Folder%" FOR /F "DELIMS=" %%G IN ('DIR /A:-D /B /O:N /S')

How to replace a string with a substring when there are parentheses in the string

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 05:05:32
问题 I have been scratching my head for the last two days trying to put together a code that reads a folder structure and the strips off the base path of the listing. What I have so far is this: @ECHO OFF CLS SETLOCAL EnableExtensions EnableDelayedExpansion SET "StartTime=%TIME: =0%" SET "Folder=%~1" IF "%Folder:~-1%"=="\" SET "Folder=%Folder:~0,-1%" FOR %%G IN ("%Folder%") DO SET "Archive=%%~nxG" ECHO Processing %Folder%... ECHO. PUSHD "%Folder%" FOR /F "DELIMS=" %%G IN ('DIR /A:-D /B /O:N /S')

Is it possible to return error code to VBA from batch file?

一笑奈何 提交于 2021-02-08 04:58:47
问题 My batch file: SET username=%1 SET password=%2 net use "\\gessel\toys\name" %password% /user:shops\%username% ECHO.%ERRORLEVEL% :copy Xcopy "\\gessel\toys\name\babytoys" "%appdata%\shops" /S /E ECHO.%ERRORLEVEL% IF ERRORLEVEL 0 goto disconnect goto end :disconnect net use "\\gessel\toys\name\babytoys" /delete goto end :end EXIT /B %ERRORLEVEL% I have called above batch file from VBA and the code as follows: call Shell(Environ$("COMSPEC") & " /c " & path & username & password, vbHide) The

List directory stack in windows

旧时模样 提交于 2021-02-08 04:39:42
问题 I am trying to list the directories that have been added to the directory stack using the command: pushd I cannot find any references or command on how to print the directory stack contents. Any help is appreciated 回答1: A pushd without parameters outputs the list of the stacked directories. pushd c:\ pushd windows pushd help pushd windows pushd en-us pushd Will output c:\Windows\Help\Windows c:\Windows\Help c:\Windows c:\ c:\Temp The latest pushed directory is missing here, but can simply

test batch statements directly in powershell without wrapping the call in a batch file

谁都会走 提交于 2021-02-08 03:59:54
问题 I am writing a batch file to automate a task using vscode where I get a powershell as my default shell. The line if not exist build (md build) produces errors in powershell. When I pack the same line into a batch file called test.bat I can call ./test.bat and get the expected behaviour. Is there a way to test my batch statements directly in the powershell? 回答1: In powershell use Test-Path : If(!(Test-Path ".\build")){md ".\build"} Or another way.. Cmd /c "your statement" Get error code in

List of files between two timestamps

我们两清 提交于 2021-02-08 03:58:35
问题 using the below code we are able to list the files between two dates. But we need to check the timestamp also. i.e. List all the files between date & time. wmic datafile where "drive='%drive%' and path='%folder:\=\\%' and creationdate>'%start%' and creationdate<'%end%'" get creationdate, name, size 回答1: Check FileTimeFilterJS.bat To print files between two dates in the current directory try with in : call FileTimeFilterJS "." -beginDate "September 1, 2014 10:15 AM" -endDate "November 1, 2014

How to close Command Prompt window after Batch file execution in python?

Deadly 提交于 2021-02-08 03:34:06
问题 I have a batch file which run a python based application which reads a messages continuously. I have python script which closes the application after a timeout period and Execute the Remaining code. I am using Subprocess.Popen for Batch file run and terminate() call to terminate but the Cmd Window is still in OPen. It is not closing? And the code is not executing untill the Window Closes. How can i forcly close the cmd? 回答1: You can use psutil And specifically the Process.terminate() function

How to close Command Prompt window after Batch file execution in python?

戏子无情 提交于 2021-02-08 03:33:07
问题 I have a batch file which run a python based application which reads a messages continuously. I have python script which closes the application after a timeout period and Execute the Remaining code. I am using Subprocess.Popen for Batch file run and terminate() call to terminate but the Cmd Window is still in OPen. It is not closing? And the code is not executing untill the Window Closes. How can i forcly close the cmd? 回答1: You can use psutil And specifically the Process.terminate() function

Handling ; (semi-colon) in filenames with this drag and drop routine

北城余情 提交于 2021-02-07 19:40:19
问题 Consider these filenames. ; f - Copy.txt ;f.txt f - Copy ;- Copy.txt f - Copy.txt I've got this code which resolves the & symbol in any files with this answer: Drag and drop batch file for multiple files? @echo off title %~nx0 setlocal enabledelayedexpansion rem Take the cmd-line, remove all until the first parameter set "params=!cmdcmdline:~0,-1!" set "params=!params:*" =!" set count=0 rem Split the parameters on spaces but respect the quotes for %%G IN (!params!) do ( set /a count+=1 set

Setting environment variables in Jenkins with a bat file?

浪子不回头ぞ 提交于 2021-02-07 14:20:55
问题 Currently I have a batch file that sets all the environment variables needed before starting the build process. It's a must to use the same bat for setting the env variables. I tried to use EnvInject Plugin, didn't have any success. Also tried "Execute Windows batch command" before running msbuild. e.g. start mybat.bat - this didn't seem to work either How can I integrate the same bat file to set the variables? 回答1: Each Jenkins "build step" has it's own environment, I explained this in