CMD-tips and utils for files and folders

For updating folder dates, the utility "FolderTimeUpdate" can be used (developed by NirSoft).
 Search-words: bat cmd batch script
 

Comments

Permalink

Script below is a sample of calling another CMD-file and redirecting screen output (including errors) to a logfile with current time.

@echo off
echo *** Ready to run other cmd-file ?
pause
echo.
echo *** Started running.. check logfile for the progress..

REM *** Get current date and time in the desired format
REM *** Script assumes swedish date and time format. (YYYY-MM-DD and HH:mm:ss,xx)

for /f "tokens=1-3 delims=-" %%a in ('echo %date%') do (
    set "year=%%a"
    set "datestamp=!year:~-2!%%b%%c"
)

for /f "tokens=1-3 delims=:," %%a in ('echo %time%') do (
    set "hour=%%a"
    set "minute=%%b"
    set "seconds=%%c"
)
set "secdig=%seconds:~0,2%"

REM *** Add leading zero to hour if it is a single digit
if 1%hour% lss 110 set "hour=0%hour%"


call othercmdfile.cmd > "logfile-%datestamp%-%hour%%minute%%secdig%.txt" 2>&1
echo.
echo *** Completed! See status in the generated log-file.
pause

Permalink

The batch-script below can be used to rename files, it will ask for search and replace strings.

@echo off
setlocal enabledelayedexpansion

set /p "search=Enter the string to search for: "
set /p "replace=Enter the string to replace with: "

for %%F in (*%search%*.txt) do (
    set "filename=%%~nF"
    set "newname=!filename:%search%=%replace%!"
    ren "%%F" "!newname!%%~xF"
)

endlocal