How to open the file that was searched in CMD - batch-file

I searched a file in command prompt using
dir /s *584.pdf
The file was found and the result is as follows
Volume in drive Z is New Volume
Volume Serial Number is E49F-4208
Directory of Z:\OHE_Design\DFCC\EMP-4 OHE\Submissions\References\Received\CTP-1 & 2\05-Bridge Mast files\CTP 1 & 2 DETAILS\OHE approval letters\L-NKC-SLT-PMC-1612-48
12/14/2016 05:11 PM 8,180,090 2-MB-13-011-OHE_Rev.0 584.pdf
1 File(s) 8,180,090 bytes
Total Files Listed:
1 File(s) 8,180,090 bytes
0 Dir(s) 47,574,523,904 bytes free
Now, i want to open the file that i searched for, is there any command to do that? How shall i proceed?

for /r "Z:\OHE_Design" %%a in ("*584.pdf") do (
start "" "%%~fa"
)
Try this.

I tried with some code and it seemed to work for me luckily.
#echo off
set /p search="Enter the file : "
cd "C:\users\suneel\desktop\Potato 23"
dir /s /b /a-d "*%search%*.pdf">"test.txt"
if '%ERRORLEVEL%'=='0' GOTO OPEN
if '%ERRORLEVEL%'=='1' echo Please search manually or Confirm with Authorities
:CONT
del "test.txt"
PAUSE
EXIT
:OPEN
set /p extract=<"test.txt"
start "" "%extract%"
echo FILE FOUND
echo Please wait while the file opens.
GOTO CONT

Related

MediaInfo Batch, get rid of the file path in the line "Complete name"

I currently have a batch file to create an nfo of all file inside a folder.
Now I'm looking to add a function for a "single file".
i have a part that works but the nfo file text includes the path of the file in the "Complete name" line.
I would like to know how to not display this path before the filename.
The nfo is currently saved at the location of the file, it should stay that way.
there is the batch file (without the "if single file") :
Tx to #Compo for this.
#Echo Off
SetLocal EnableExtensions
Set "MIExe=%UserProfile%\Standalone\MediaInfo\MediaInfo.exe"
Set "OutExt=nfo"
Set "HR=------------------------------------------------------------------"
For %%G In ("%~1") Do If "%%~aG" Lss "d" (If "%%~aG" GEq "-" (
Echo Error! File arg.
GoTo EndIt) Else (Echo Error! Invalid directory arg.
GoTo EndIt)) Else If "%%~dG" == "" (
Echo Error! Full directory path required.
GoTo EndIt)
If Not Exist "%MIExe%" (Echo Error! MediaInfo not found.
GoTo EndIt)
PushD "%~1"
Set "ExtLst="
For %%G In (aac ac3 aifc aiff ape asf au avi avr dat dts flac iff ifo irca m1v
m2v mac mat mka mks mkv mov mp2 mp3 mp4 mpeg mpg mpgv mpv ogg ogm paf pvf qt
ra rm rmvb sd2 sds vob w64 wav wma wmv xi) Do If Not Defined ExtLst (
Set "ExtLst=".":"*.%%G"") Else Call Set "ExtLst=%%ExtLst%% ".":"*.%%G""
Set "}=%PATHEXT%" && Set "PATHEXT="
%SystemRoot%\System32\where.exe /Q %ExtLst%
If ErrorLevel 1 (Echo Error! Directory has no supported files.
GoTo EndIt)
Set "i="
(For /F "Delims=" %%G In ('%SystemRoot%\System32\where.exe %ExtLst% 2^> NUL'
) Do (If Defined i Echo %HR%
"%MIExe%" "%%~nxG"
Set "i=T")) 1> "%~nx1.%OutExt%"
:EndIt
%SystemRoot%\System32\timeout.exe /T 3 /NoBreak 1> NUL
GoTo :EOF
i want to add this part with a if it's a file not folder :
:SingleFile
"%MIExe%" "%~1" > "%~1.%OutExt%"
This work but produce a full path with name at the "Complete name" line..
And i also like to know if the "is a file check" can be use with this part (at the start of the batch) :
...
If "%%~aG" GEq "-" (
Echo Single file.
GoTo SingleFile
...
Thanks in advance for your help !

RAR files with password and enryption using batch

I have four folders in drive d: and in each folder there is a file called file.txt. If I use the batch script below, all four txt files get compressed and they are compressed without the password and without hidding the file name inside. I only want to compress the file in Folder 4. My password is MYPass and my compressed bz2 is FileCompressed.bz2
I need to only compress the file in Folder 4, assuming yes on all queries, showing no messages, maximum compression, with password, with deletion of File.txt (on Folder 4) after compression, with encription of the name of the file. I used the "rar -?" in windows prompt but I am still not knowing how to get the results I need. Can anyone help?
d:
\Folder 1\file.txt
\Folder 2\file.txt
\Folder 3\file.txt
\Folder 4\file.txt
#echo off
rar a -hpMyPass -m5 -y -df "d:\Folder 4\FileCompressed.bz2" "d:\Folder 4\File.txt"
Try this sample code :
#echo off
Title Zip Files with rar.exe in command line
color 0A & Mode 75,10
Set "Folder2Compress=D:\Folder 4"
If Not exist "%Folder2Compress%\" MD "%Folder2Compress%\"
(echo This is a test to see if the compression with encryption in winrar works or not)>"%Folder2Compress%\File.txt"
Set "CompressedFolder=%~dp0FileCompressed.bz2"
set "RAR_Password=MyPass"
Set "Log=%~dpn0_Log.txt"
Set "strProgramFiles=%ProgramFiles%"
if exist "%ProgramFiles(x86)%" (
set "strProgramFiles=%ProgramFiles(x86)%"
) else (
set "strProgramFiles=%ProgramFiles%"
)
Set RAR="%strProgramFiles%\WinRAR\RAR.exe"
If Exist %RAR% ( Goto :RAR ) else ( Goto :Fail )
REM -----------------------------------------------------------------
:RAR
%RAR% a -m5 -y -df -hp%RAR_Password% "%CompressedFolder%" "%Folder2Compress%\">nul 2>&1
IF "%ERRORLEVEL%" EQU "0" ( GOTO Succes ) Else ( Goto Fail )
REM -----------------------------------------------------------------
:Succes
Echo(
Echo All Files are zipped succesfuly ! in "%CompressedFolder%"
Echo All Files are zipped succesfuly ! in "%CompressedFolder%" > "%Log%"
Start "" /MAX "%Log%"
Timeout /T 3 /nobreak>nul
Exit /b
REM -----------------------------------------------------------------
:Fail
Color 0C
Echo(
echo There was an error !
echo There was an error ! >"%Log%"
Start /MAX "" "%Log%
Timeout /T 3 /nobreak>nul
REM -----------------------------------------------------------------

Batch script that monitors for file changes

I need to create a batch script that continually monitors a specific file for changes, in this case, LogTest.txt.
When the file is updated it will trigger a VBScript message box, which displays the last line from within LogTest.txt. The idea is that this will continue monitoring after the message box is cleared.
I have tried using the forfiles option, but this really only lets me deal with the date and not the time. I know that PowerShell and other options are available, but for reasons that are just too long to explain I am limited to being only able to use a batch and VBScript.
Batch File:
#echo off
:RENEW
forfiles /m LogTest.txt /d 0
if %errorlevel% == 0 (
echo The file was modified today
forfiles /M LogTest.txt /C "cmd /c echo #file #fdate #ftime"
cscript MessageBox.vbs "Error found."
REM do whatever else you need to do
) else (
echo The file has not been modified today
dir /T:W LogTest.txt
REM do whatever else you need to do
)
goto :RENEW
MessageBox.vbs:
Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox "This is an error", vbOkCancel + vbExclamation, "Error Found"
There is an archive attribute on every file. Windows sets this attribute on every write access to the file.
You can set it with the attrib command and check it for example with:
#echo off
:loop
timeout -t 1 >nul
for %%i in (LogTest.txt) do echo %%~ai|find "a">nul || goto :loop
echo file was changed
rem do workload
attrib -a LogTest.txt
goto :loop
timeout /t 1 >nul: small wait interval to reduce CPU-Load (never build a loop without some idle time)
for %%i in (logTest.txt) do... process the file
echo %%~ai print the attributes (see for /? for details)
|find "a" >nul try to find the "a"rchive-attribute in the output of the previous echo and redirect any output to nirvana (we don't need it, just the errorlevel)
|| goto :loop works as "if previous command (find) failed, then start again at the label :loop"
If find was successful (there is the archive attribute), then the next lines will be processed (echo file was changed...)
attrib -a LogTest.txt unsets the archive attribute of the file.

How can i copy selected text file using command "FOR" in batch file?

Hello guys as you read in topic how can i make a selected file to copy to another location.
Im using my own Lithuanian language in this, if some one find it hard to understand tell me ill translate it. Right now it only creates new file when i start " name.bat test.txt" its not full code since there is lots of copy paste of same thing any ideas since im realy bad at .bat files.
And i need to use command "FOR"
:DEKUPAZAS
echo Pasirinkote Dekupazo kursus
echo Bendrine informacija apie si bureli
echo.
type dekupazas.txt
echo.
set U=dekupazas.txt
echo Ar norite:
echo 1) Irasyti sia informacija i naujai sukurta faila?
echo 2) Grizti kitu bureliu pasirinkimu?
echo 3) Grizti prie srities pasirinkimo?
choice /C 123 /N /M "Iveskite savo pasirinkima(1,2 arba 3): "
if errorlevel 255 goto KLAIDA
if errorlevel 3 goto SRITIS
if errorlevel 2 goto KT
if errorlevel 1 goto IRASYMAS
goto PRADZIA
:IRASYMAS
echo Pasirinkote irasyti sia informacija i jusu sukurto pavadinimo faila
echo Failas bus perkeltas i aplanka Pasirinkimas
if exist Pasirinkimas rd /S /Q Pasirinkimas
md Pasirinkimas
for %%U in (U) do dir %%U >>%1
move %1 Pasirinkimas >nul
goto PAB
The FOR /F statement reads each line of the file then does a directory listing of it captured to the first parameter to the .bat script.
I also took the liberty of creating a variable for the new directory name so that it does not need to be hardcoded so many times. "Hardcode" is two, four-letter words.
echo Pasirinkote irasyti sia informacija i jusu sukurto pavadinimo faila
echo Failas bus perkeltas i aplanka Pasirinkimas
SET NEW_DIR=Pasirinkimas
if exist "%NEW_DIR%" (RMDIR /S /Q "%NEW_DIR%")
MKDIR "%NEW_DIR%"
for /F %%a in (%U%) DO (DIR "%%~a" >>"%~1")
move "%~1" "%NEW_DIR%" >nul
goto PAB

Windows XP Batch- IF EXIST FTP with Date Variable

I am writing a quick batch to see if a file exists after executing an exe.
The file is created with a YYYYmmDDnumbernumbernumber.xml file name according to the current date.
How do I check for the file with a variable in the beginning? Here is what I have so far:
#echo off
set mydate=%date:~10,4%%date:~4,2%%date:~7,2%
if not exist "ftp://FTPsite/%mydate%*.xml" (echo nah) else (echo yea)
pause
you cannot check existence of file on ftp server with IF.Instead try this after replacing the parameters that starts with MY_ :
!cls&echo off&setlocal ENABLEDELAYEDEXPANSION
!cls&goto :ftp_end
open MY_FTP_SERVER
user MY_USER
pass MY_PASS
cd MY_REMOTE_DIR
ls . local.file
bye
:ftp_end
ftp -s:%0
set mydate=%date:~10,4%%date:~4,2%%date:~7,2%
type local.file | findstr /B "%mydate%" | find ".xml" && echo FILE IS OUT THERE && goto :skip_file_is_not_there
echo FILE IS NOT THERE
:skip_file_is_not_there
del local.file /q >nul

Resources