Enhance the batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Enhance the batch file

#1 Post by foncesa » 11 Nov 2013 15:24

Hello,

I need to enhance the below scirpt which is creating the file, working perfectly according to my needs.
I want to create a new folder DATA-FILE and this file to be placed inside it, and copy this folder to USB pendrive.

Code: Select all

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"

set name=tmp.tmp
set "flag="
for %%a in (*.txt) do (
echo processing "%%a"
   if not defined flag (
     copy "%%a" "%name%" >nul
     set flag=1
    ) else (
     more +1 "%%a" >>"%name%"
   )
)
findstr /v "^Total" < "%name%" >"%dd%%mm%%yyyy:~2%Q.txt"
del "%name%"

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Enhance the batch file

#2 Post by Samir » 24 Nov 2013 22:09

This is simple enough. Just figure out the drive letter of your pen drive, create the directory and copy the file to it.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Enhance the batch file

#3 Post by trebor68 » 26 Nov 2013 10:09

Your code need to change the row to:

Code: Select all

...
findstr /v "^Total" < "%name%" >"X:\FOLDER\%dd%%mm%%yyyy:~2%Q.txt"
...

The letter X: is the USB drive (USB pen) and FOLDER is the path at this drive.

The letter of the USB drive is not anytime the same letter. Possible is this problem when you have more as one USB drive.
How can make a folder see MD /? or MKDIR /?.


And here a solution to find the USB drive.

FindUSB.bat

Code: Select all

@ECHO OFF
setlocal enableextensions
set "drlist="
for /f "tokens=*" %%A in ('fsutil fsinfo drives^|find /V ""') do (
    set "dr=%%A"
    call set "drlist=%%drlist%% %%dr:~-3%%"
)
set "USBdrive="
for %%A in (%drlist%) do for /f %%D in ('mountvol %%A /l') do (
  if "%%D" equ "\\?\Volume{332abe1e-c139-11dd-a897-000ae44fc4a7}\" set USBdrive=%%A
)
echo USB drive: %USBdrive%

You need to change the volume name to your USB drive (USB pen).

Please copy this following batch to the USB drive.
The same USB drive have not the same mount volume at different computers.

USB-Test.bat

Code: Select all

@echo off
set var=%~d0
for /f %%a in ('mountvol %var% /l') do set mvol=%%a
echo ComputerName: %computername%
echo LogonServer: %logonserver%
echo UserDomain: %userdomain%
echo current drive: %var%
echo MountVolumen: %mvol%
::
echo ComputerName: %computername%>>USB-Info.txt
echo LogonServer: %logonserver%>>USB-Info.txt
echo UserDomain: %userdomain%>>USB-Info.txt
echo current drive: %var%>>USB-Info.txt
echo MountVolumen: %mvol%>>USB-Info.txt
echo.>>USB-Info.txt
echo.
pause

Post Reply