How to verify if a file exists in a batch file?

I have to create a .BAT file that does this: If C:\myprogram\sync\data.handler exists, exit; If C:\myprogram\html\data.sql does not exist, exit; In C:\myprogram\sync\ delete all files and folders except (test, test3 and test2) Copy C:\myprogram\html\data.sql to C:\myprogram\sync\ Call other batch file with option sync.bat myprogram.ini. If it was in the Bash environment it was easy for … Read more

Setting a system environment variable from a Windows batch file?

Is it possible to set a environment variable at the system level from a command prompt in Windows 7 (or even XP for that matter). I am running from an elevated command prompt. When I use the set command (set name=value), the environment variable seems to be only valid for the session of the command … Read more

How to loop through files matching wildcard in batch file

I have a set of base filenames, for each name ‘f’ there are exactly two files, ‘f.in’ and ‘f.out’. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should: Display the base name ‘f’ Perform an action on ‘f.in’ Perform another action on ‘f.out’ … Read more

Format date and time in a Windows batch script

In a Windows (Windows XP) batch script I need to format the current date and time for later use in files names, etc. It is similar to Stack Overflow question How to append a date in batch files, but with time in as well. I have this so far: echo %DATE% echo %TIME% set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2% echo … Read more

Hidden features of Windows batch files

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. What are some of the lesser know, but important and useful features of Windows batch files? Guidelines: One feature per answer Give both a short description of the feature … Read more