# Tag Info

## New answers tagged batch-file

1

I'm attempting to rename all files in a folder via a batch script but I'm getting an incorrect syntax error that I can't seem to identify: for %%f in (%Source%\*DebugLog.Config) do %%f ren %%f "%Source%\%ProjectName%.*DebugLog.Config" A simple way to do this just like your above example excluding your scripting errors such as (1.)the FOR variable ...

0

This is going wrong in more than one place. Assuming %Source% ends in a backslash (edit: it seems it doesn't, so adding the backslash:) for %%f in (%Source%\*DebugLog.Config) do ren "%%f" "%ProjectName%.%%~nxf" The ren target mustn't contain a path, so %%~nxf extracts Name and Extention of %%f.

2

I'm getting an incorrect syntax error that I can't seem to identify for %%f in (%Source%\*DebugLog.Config) do %%f ren %%f "%Source%\%ProjectName%.*DebugLog.Config". There are several mistakes in your batch file (2 of which I made myself). As pointed out to me in comments elsewhere by dbenham: The REN target cannot include drive or path. It must be ...

1

ADD SOMETHING TO THE END OF MULTIPLE FILES WITH A FILE RENAME Figured I'll add an answer per Remove a part of a list of names and your comments to me there. Explicitly defined scripts and very easy and clear where to set those variables to accommodate for your usage as-needed as "text" now but "anything else" later. This doesn't require ...

0

Does it have to be done in a batch file? AdvancedRenamer is a free and very versatile program for renaming files or folders in batch. Easily solves your problem.

2

You can add text to the end of any file name (prior to the first dot, which is usually the beginning of the extension) by using a series of ? that is at least as long as the original name. ren "C:\Users\user123\Desktop\mp3\*.mp3" ??????????????????????text.* The ? greedily matches and preserves any character except ., and is free to match nothing if it ...

1

How do I add "text" to the end of multiple filenames. Before: 1.mp3 2.mp3 After: 1text.mp3 2text.mp3 There are multiple errors in your batch file, for example: *.mp2 should be *.mp3 goto E - the label :E is missing. you dont need to call anything. Simple working batch file rem @echo off setlocal setlocal enabledelayedexpansion for %%a in ...

0

start "" "C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe" --startvm Slack131 The start command will run VirtualBox asynchronously, then the batch file will continue its own execution and close right away (assuming there are no further commands after start). The first pair of quotes "" is required by the start syntax (which takes the first quoted ...

1

This may work based on your comment of wanting to start a batch file when Chrome is found to be running on your PC. ECHO OFF TASKLIST | FIND /I "Chrome.exe" IF NOT %ERRORLEVEL%==0 EXIT CALL "C:\Batch\Batchfile.bat" EXIT The part that I'm not sure about here is once the batch starts, how you tell the tasklist process to not run any longer to keep launching ...

3

Try something like this which is pure batch script creating an HTA file that has a timer set to auto close which is set as a variable within the logic up top. This script basically builds an HTA file for the pop up window and then builds the VBS file and then calls it just as you were doing from the %tmp% location. I wasn't able to figure out another way ...

1

FreeDOS has source code available.

0

@echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto ...

0

It is an example to run the bat as administrator. It works for me. It goes like this: if "%~s0"=="%~s1" ( cd %~sp1 & shift ) else ( echo CreateObject^("Shell.Application"^).ShellExecute "%~s0","%~0 %*","","runas",1 >"%tmp%%~n0.vbs" & "%tmp%%~n0.vbs" & del /q "%tmp%%~n0.vbs" & goto :eof ) :eof start Cmd /k "netsh wlan show profile" ...

2

Just for the record, here's another batch solution, it exploits delayed expansion of the %ERRORLEVEL% system variable: @echo off setlocal EnableDelayedExpansion for /f "delims=" %%L in ('ipconfig') do ( echo %%L | findstr /r "^[A-Z]" 1>NUL if !errorlevel! == 0 set "_int=%%L" echo %%L | findstr /c:%1 1>NUL if !errorlevel! == 0 ( ...

0

We have faced similar issue. We end up renaming the xlsm file. THere was an issue with encoding in the file name.

1

Thanks for the effort everyone. It seems there are several hurdles: the number of IP addresses assigned to an adapter the language of the OS All the -Bx and Regex stuff seems to break easily, so I googled for something I could implement myself and came up with the following C# program, which takes the IP address as parameter (IP2Adapter <IP>): ...

3

You could use this PS one liner: $addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains $addr} |select Description |% {$_.Description} To use it directly from command line: powershell "$addr='192.168.2.4'; get-wmiobject Win32_NetworkAdapterConfiguration |? {$_.ipaddress -contains \$addr} |select Description |% ...

3

How do I display the name of a network adapter for a given IP address? This solution does not require any external commands (pcre2grep, sed, etc). Use the following batch file (getname.cmd): @echo off setlocal setlocal enabledelayedexpansion set "_adapter=" set "_ip=" for /f "tokens=1* delims=:" %%g in ('ipconfig /all') do ( set "_tmp=%%~g" if ...

5

I'm looking for a reverse command that displays the name of the network adapter for a given IP address. Based on everything I tried, this should work seems you say you need to get this information ONLY from the IP address which you already specify in your example. ALL ONE-LINERS INTERACTIVE PROMPT FOR IP ADDRESS TO GET NETWORK CONNECTION NAME (Use ...

3

To be more accurate, following OP's example, I'd use sed, which can be found under the \usr\local\wbin folder of this zipped file (UnxUtils project). ipconfig | sed -rn "/^[A-Z]/h;/192.168.2.4/{g;s/.* adapter (.*):/\1/p;}" -n suppresses non matching lines; first pattern finds any line starting with capital letter, then h puts it away on hold space; second ...

2

Okay, here's a batch script that will find the Java folder with the highest version build number and then copy all files from your stage folder to the correct folder (with the highest version number only) as you need for the Java installed on your machine. I also put some IF logic in there so if the \jre\lib\security directory does not exist, it creates it ...

0

Suppose "A" is in "myoutbox" folder, let's call it A.doc. A copy is made in "mmyinbox" and checked by robocopy for changes (/IT). Here's a batch file to be scheduled every N minutes: @echo off setlocal rem File names variables set "fn=A.doc" set "test=test.doc" for %%f in ("c:\mmyinbox\%fn%") do if exist %%~sf set ok=1 for %%f in ("c:\myoutbox\%test%") do ...

1

The above script works for me, assuming I run the Command Prompt as an Admin. Do you have write access to your D:\? What about the file named D:\File_location?

0

You could run this batch file in the same folder as the files. Each file will be moved into a folder of the same name. for /f "delims=" %%a in ('dir /b') do ( if not "%%~fa"=="%~f0" ( md "%%~na" 2>nul if exist "%%a" move "%%~na.*" "%%~na" ) ) I use it with a warning below to avoid accidental use. @echo off echo. set sure= set /p sure=you want to put ...

1

You probably don't need to be using the START command. The reason I typically find the START command may be quite useful is for running a program in the background, which may not be the desired action if you're trying to see results. Just make a new text file that says: @Echo Off C:\Users\delta\dc2.exe -configure="C:\Users\delta\Switch.xml" pause Make ...

0

Any ideas on where I am going wrong? START cmd.exe /k "C:\Users\delta\dc2.exe -configure="C:\Users\delta\Switch.xml"" Your start command is wrong. The first argument should be the title of the command (it is not optional). Try: START "my command title" "C:\Users\delta\dc2.exe" -configure=C:\Users\delta\Switch.xml or START "" "C:\Users\delta\dc2.exe" ...

-1

IF program closes on crash you can detect if its running or not. (You can check if its running and run it if need be - you can loop the check at interval) http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script IF the program doesn't close on crash: Short of coding a custom program to do it you can use a Macro ...

1

You might find that if you create numbered folders named like this, they won't display in the proper (expected) sort order: C:\Dropbox\Development> dir /b Lec-10 Lec-100 Lec-101 Lec-102 Lec-103 Lec-104 Lec-105 Lec-106 Lec-107 Lec-108 Lec-109 Lec-11 Lec-110 Lec-111 Lec-112 Lec-113 Lec-114 Lec-115 Lec-116 Lec-117 Lec-118 Lec-119 Lec-12 Lec-120 Lec-13 ...

21

There is another easy way, for limited number of folders. May be Useful here Or for someone else. In Windows we can make numbered folder names by creating a folder "lec(1)" and copy pasting it how many time we want, if we paste 10 time there will be 11 folders with names "lect(1)" to "lec(10) - Copy" Only trick here is that the first folder must include ...

2

This won't be better than a script for your particular scenario, but it's kind of nice to know this when your folder names are unrelated: you can make multiple directories from the command line by separating them by a space: C:\temp\animals>dir Volume in drive C is Windows Volume Serial Number is 82CB-BB0F Directory of C:\temp\animals 11/16/2015 ...

27

How can I can create all these sub-folders at once, using my naming scheme? If I were to create the sub-folders in a specific directory, such as C:\Dropbox\Development, would I need to cd to that directory first? Assuming I'm using the cmd shell? To create the sub-folders (sub-directories) in a specific directory (that is not the current directory), ...

1

AUTO-OPEN MP3 FILES WITH WINDOWS MEDIA PLAYER TO PLAY How to open multiple MP3 files with batch or vbs, just like Ctrl+A Enter (There are two scripted solutions below (batch and VB script) to open all MP3 files in a single folder with Windows Media Player which will play one song after the other without you needing to do manually from WMP after each ...

0

for /f "delims=" %%f in ('dir /ad /b c:\share\') do rd /s /q c:\share\%%f This does not work if the subdirectories contain other directories that contain spaces. In order to make this work, I needed to quote the final string, like this for /f "delims=" %%f in ('dir /ad /b c:\share\') do rd /s /q "c:\share\%%f" Apparently, this causes the command to work ...

0

Mark's answer works fine as long as you have fairly short scheduled task names, but the default output of schtasks /query (table format) truncates the task names to 32 characters, which causes errors when trying to delete them. If you need to deal with tasks that have longer names, I would recommend using list output format instead, which does not ...

0

Perhaps you expected copy con c:\55.HTML to read the next line(s) as if it were a shell here-document. Since the result is empty, more likely it did not do that, but copied nothing (in a quick check, the script hangs on the copy command, and killing that moves on to an unrecognized command "my"). You can always do this however: echo my HTML page %n% ...

0

You can use a command line utility elevate. (download link - https://drive.google.com/open?id=0Bz7qe_olclTwVGZLUklFMHNxQ00 ) Usage: Elevate [-?|-wait|-k] prog [args] -? - Shows this help -wait - Waits until prog terminates -k - Starts the the %COMSPEC% environment variable value and executes prog in it (CMD.EXE, 4NT.EXE, etc.) prog - ...

1

Remove all but one language from your keyboard entry options. Go to your Control Panel, go to the Languages option (I'm on mobile, can't remember the exact name right now). Remove all the keyboard layouts except the one you want to keep. When you hit OK, the Language bar disappears!

0

Since you are asking about a batch file, I'll assume this is on Windows xcopy /E /T /D:m-d-y <top level source dir> <destination> /D:m-d-y will copy only files changed on or after the specified date.

0

After looking at the website for a while, i figured it out. this is what i got: :Q3 echo ==================================== echo Do you want to be skilled in: echo. echo Speed (1) echo Enchanting (2) echo Attack (3) echo Magic (4) echo. echo Say the Number it's labeled as. (1-5) echo. echo ===================================== set SPEE=0 set ENCH=0 ...

0

I'm not sure what you are trying to do, but try this: @echo off :Q3 echo ==================================== echo Do you want to be skilled in: echo. echo Speed (1) echo Enchanting (2) echo Pickpocket (3) echo Attack (4) echo Magic (5) echo. echo Say the Number it's labeled as. (1-5) echo. echo ===================================== SET /P QU3="INPUT:" ...

0

You should put the same command in a batch file, and it should work correctly (Not tried it myself, and it added the registry key.) You just have to make sure to execute the batch file as administrator (Right click>Run As Administrator), since you need admin rights to add a registry key.

0

I found a VBS script that prints all documents in the folder it's executed in: set shApp = CreateObject("shell.application") currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") set shFolder = shApp.NameSpace( currentPath ) set files = shFolder.Items() for each files in files if files.name <> "Imprimir.Expediente" ...

0

@echo off setlocal set "winword=C:\Program Files\Microsoft Office\Office14\winword.exe" for /f "delims=" %%a in (' dir /b /s "c:\path\docs\*.docx" ') do ( "%winword%" "%%~a" /mFilePrintDefault /mfileexit ) Used SET VARIABLE, wildcards inside DIR inside FOR.

1

Try this: forfiles /s /C "cmd /c echo @file, @fdate, @ftime, @isdir" > MyTextOutput.csv You are telling the OS what to output, just tell it to output commas too.

1

Here's another approach: @ECHO OFF SETLOCAL EnableExtensions EnableDelayedExpansion rem get list of disk letters in use set "_inUseDisks=" for /f "tokens=2 delims==" %%D in (' wmic logicaldisk get caption /value ') do ( for /F "delims=:" %%d in ("%%D") do ( set "_inUseDisks=!_inUseDisks! %%d" ) ) echo Disk letters in use %_inUseDisks% rem ...

0

@echo off setlocal EnableDelayedExpansion pushd \\computername\sharename for /f "delims=" %%u in ('cd') do set av_unit=%%u && echo !av_unit:\ =! popd EnableDelayedExpansion allows variable manipulation inside for statement, which only removes backslash and space from drive root dir.

Top 50 recent answers are included