batch-file

Renaming files with spaces and dots in the filename

折月煮酒 提交于 2020-01-05 08:01:02
问题 I'm making a simple *bat file with drag/drop ability for replacing white spaces( ) and dots(.) for underscores(_). I think this should work, but it doesn't: @ECHO OFF setlocal enabledelayedexpansion FOR %%f IN (%*) DO ( set filename=%%~nj set filename=!filename:.=_! set filename=!filename: =_! if not "!filename!"=="%%~nf" RENAME "%%f" "!filename!%%~xf" ) Do you know what is going on? 回答1: try this: @ECHO OFF &setlocal FOR %%f IN (%*) DO ( set "oldname=%%~ff" set "oldfname=%%~nf" set

Renaming files with spaces and dots in the filename

拥有回忆 提交于 2020-01-05 07:59:08
问题 I'm making a simple *bat file with drag/drop ability for replacing white spaces( ) and dots(.) for underscores(_). I think this should work, but it doesn't: @ECHO OFF setlocal enabledelayedexpansion FOR %%f IN (%*) DO ( set filename=%%~nj set filename=!filename:.=_! set filename=!filename: =_! if not "!filename!"=="%%~nf" RENAME "%%f" "!filename!%%~xf" ) Do you know what is going on? 回答1: try this: @ECHO OFF &setlocal FOR %%f IN (%*) DO ( set "oldname=%%~ff" set "oldfname=%%~nf" set

Bat file to set append to PATH if PATH does not contain location [duplicate]

落花浮王杯 提交于 2020-01-05 07:59:05
问题 This question already has answers here : How to check if directory exists in %PATH%? (22 answers) Closed 4 years ago . I am writing a script for windows to install a selenium service that also sets the PATH for the chrome and ie drivers, but just setting them every time the script runs (if anything is updated) will eventually run into appending the same variables to the end over and over. I tried this: setx IEDRIVER "%~dp0..\ie" /m setx CHROMEDRIVER "%~dp0..\chrome" /m if not x%PATH:IEDRIVER=

Batch: How to prompt for input and continue if timed out?

北城以北 提交于 2020-01-05 07:35:06
问题 I know the timeout /t 60 way to get a delay with automatic continue and the set /p var="prompt" for getting user input but is there any change to do both; ask and have a timeout to continue if nothing is entered? I would use it for a sort of get set screen for my looping script to change script settings. 回答1: Take a look at choice /? to request a key and abort with a timeout. For example: CHOICE /T 10 /C YN /D Y will wait 10 seconds for Y (Yes) or N (No), otherwise the default (/D) will be

Batch: How to prompt for input and continue if timed out?

梦想与她 提交于 2020-01-05 07:35:06
问题 I know the timeout /t 60 way to get a delay with automatic continue and the set /p var="prompt" for getting user input but is there any change to do both; ask and have a timeout to continue if nothing is entered? I would use it for a sort of get set screen for my looping script to change script settings. 回答1: Take a look at choice /? to request a key and abort with a timeout. For example: CHOICE /T 10 /C YN /D Y will wait 10 seconds for Y (Yes) or N (No), otherwise the default (/D) will be

Script to rename files to parent folder, move renamed file and delete empty folder

↘锁芯ラ 提交于 2020-01-05 07:25:51
问题 Wondering if anyone here can help me out. I'm using Windows 7 and have a collection of movies and TV shows in individual folders which I'd like to be renamed to that of the folder name. For example: ../Media Files/Example Movie (2013)/EM2013.avi to: ../Media Files/Example Movie (2013)/Example Movie (2013).avi I'd then like the newly named file to be moved to the Media Files folder, and for the (then empty) folder to be deleted. So: ..Media Files/Example Movie (2013).avi I've searched for a

In vbscript, how do I run a batch file or command, with the environment of the current cmd prompt window?

天涯浪子 提交于 2020-01-05 07:11:48
问题 In vbscript, how do I run a batch file or command, in the current cmd prompt window, without starting a new process. For example. According to script56.chm (the vbscript help apparently) Windows Script Host Run Method (Windows Script Host) "Runs a program in a new process" So if I have code that uses that e.g. a VBS file, and a BAT file. An environment variable g has the value abc g=abc from that command window, The VBS file calls the BAT file with windows scripting host Run. The bat process

Setting an environment variable

社会主义新天地 提交于 2020-01-05 07:09:10
问题 I am using xp. I am facing problem in using Variables. I am using following code @echo off set var = "srting" When i check the value of var using % set %var% Environment variable %var% not defined Anyone help ... 回答1: If you want to execute different code path based on file content, this should work for you: @echo off set FILE_CONTENT=string for /f %%a in (file.txt) do set var=%%a if %var%==%FILE_CONTENT% ( goto MATCHED ) else ( goto NOT_MATCHED ) :MATCHED echo "matched" goto:EOF :NOT_MATCHED

How to run a batch file for every user returned in list by command net user?

我只是一个虾纸丫 提交于 2020-01-05 06:59:10
问题 My goal is to make a universal code which loops through all user account names in a computer and sends the output to a batch file. The "net user" command outputs a list of users but I want to assign each user name to an argument. So I should use the for /f command to do it. This may look easy, but remember user names may include spaces at any place: at the beginning, at the end or in the middle, Also, it's possible to find 2 consecutive spaces Hint 1: The maximum length of a user name is 20

Pass environment variables to subshell CMD

一个人想着一个人 提交于 2020-01-05 06:48:40
问题 I have a problem in my gitlab-ci.yml on Windows. I launch phpunit with environments variables. So, I have a variable like: PHPUNIT : %SOURCE_PATH%\cgi-bin\php.exe %PHPUNIT_PATH% And some variables are declared before: SOURCE_PATH: 'C:\Source' PHPUNIT_PATH: '"%SOURCE_PATH%\cgi-bin\tests\__init\tools\phpunit.phar"' But when I use the CALL command, Windows doesn't resolve the variable inside the other variable. So if I do: CALL Echo %PHPUNIT% I have: C:\Source\cgi-bin\php.exe "%SOURCE_PATH%\cgi