Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1301.

Solve : Command Line: Did something cool today. Seems like there's more out there.?

Answer»

I actually don't really understand WHAT it is I did, but it worked like it was supposed to and I have to wonder what other efficiencies I could find with others tasks.

Back story: I had multiple text files, and I wanted to get all the contents merged into one text file, which I would then import into a spreadsheet to organize the data in columns.  I GOOGLED to see if there was a way to merge the text files rather than opening each one to copy / paste the contents and LOW and BEHOLD there was!  A thing that looked like code.  And a screen shot of that BLACK screen in my start menu.  I found the black screen.  I made a minor change to the code to find the files I wanted, in the location I needed.  And it worked beautifully.

For those of you who KNOW more about this, do you have a resource you can point me towards that will help me baby-step into how I can use the COMMAND line to be more efficient working with files or completing administrative tasks?

Thanks in advance!Hi 
First share with us your code and we will try to discuss what can be improved !
Have a nice day !Hi Hackoo,

It was this example: C:\> copy in*.txt Combined.txt  from this website https://windows.tips.net/T005670_Ways_to_Combine_Two_or_More_Text_Files.html.  Like I said, it worked great and did exactly what I needed.  Just looking for a book or "name" for this sort of thing so I can study/research if there are more/better ways to go about other administrative tasks.

You used the copy command which is a built-in command available at a command prompt.  The black screen you referred to is what is known as the command prompt.  If you wanted to read more about it I guess I would google "command prompt commands" to start with. Quote from: thatvlookupmagic on May 15, 2020, 07:40:20 PM

Just looking for a book or "name" for this sort of thing so I can study/research if there are more/better ways to go about other administrative tasks.
This a GOOD start from those web sites
https://ss64.com/
https://www.dostips.com/
1302.

Solve : Win/Batch: How to get the folder name from Var %1?

Answer»

Ive been cracking my HEAD the past few hours trying to figure out how to pull only the folder name from a path passed on by a varible.

%1 = C:/documents/spreadsheetNAME/filename.ext

I need only "spreadsheetNAME/filename.ext"

I can pull the filename and extension with %~nx1

But I can figure out how to pull the FOLDERNAME

Thanks
JPRockHi   
What about like this code 
Code: [SELECT]ECHO off
Set VAR=%1
for %%I in (.) do set CurrDirName=%%~nxI
for %%I in (%Var%) do Set FileName=%~nx1
echo CurrDirName\FileName = %CurrDirName%\%FileName%
pauseThanks that seemed to work.

1303.

Solve : batch file to move files into new folder based on artists name only before -?

Answer»

Hi all, I tried to modify this code for my situation, and think it's ok, but i'd ALSO like to add something else. I have about 60k of mp3 and .cdg KARAOKE FILES in one folder with multiple artists, I am looking to run a batch file to move all files by a particular artist into a new folder with the artists name and add "greatest hits" to each new folder that gets created. All files have a - after artists name, so I assume this is the delimeter. (coding novice) - would really appreciate and advice or help is getting the code right for the batch file please.....thanks in advance.

Hope this makes sense... and one last thing, do i just remove the text echo to get rid of the PAUSES ?

echo off
setlocal enabledelayedexpansion
for %%A in (*.mp3 *.cdg) do (
   echo file found  %%A
   for /f "delims=" %%B in ("%%A") do set fname=%%~nB
   for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
   for /f "tokens=1* delims=-" %%D in ("!fname!") do set folname=%%D
   echo folder name !folname!
   if not exist "!folname!" (
      echo Folder !folname! does not exist, creating
      MD "!folname!"
   ) else (
      echo Folder !folname! exists
   )
   echo Moving file %%A to folder !folname!
   move "%%A" "!folname!"
   )
echo Finished
pause

1304.

Solve : chkdsk C: /f/r/x not working?

Answer»

I think the HDD has a problem. When trying to clone to an SSD, the speed is around 4mbps. I enter the chkdsk command as above, say yes to check after reboot, and Windows 10 loads. Did an sfc/scannow and no problems were found. I don't think that command is the same as the chkdsk C: /f/r/x command. Does anyone know how to fix this?sfc is system file compare which checks your windows system files with a backup copy and restores any which are corrupt.

Chkdsk checks the file system, as stored on the hard drive for errors. This is done by checking the actual data on the drive. So the 2 commands do different things.

You should NEVER run chkdsk C: /f/r/x on a drive which you are un sure of it's health. It can do more damage.

You could check the hard drive with Hdsentinel    https://www.hdsentinel.com/

You may be better coping the drive outside of windows or on another computer. To copy the drive in windows it needs to create a virtual image either on the fly or completely which if the computer is running SHORT of memory like only 4 gb total  or the source drive is short of SPACE less than 30 gb the copy can be slow. 
Too many switches ...all you need IA chkdsk/rThanks. Will check out hdsentinel. I am using Samsung Data Migration software to clone the WD HDD onto a Samsung SSD.

Just used the /r switch but it didn't work. Using cmd to chkdsk after reboot just restarts Win 10.

I have recently cloned three laptop HDDs onto a Samsung SSD using the same method. One HDD had problems and would not copy. Ran chkdsk C: /f/r/x, repaired the HDD, and cloned the HDD. The computer I am working on now is a desktop. Using the Samsung Data Migration program, the clone speed is around 4 mbps, very slow. Had the same problem with the previous HHD that wouldn't copy. After repairing the HDD cloning went smoothly.

Apparently, chkdsk C: /f/r/x failing is a common problem and there are many work arounds. I don't know so asked here. Some say chkdsk has been replaced by Power Shell but I don't know about that either.

Any thoughts?   /r assumes /f so the added SITCH is redundant...Unless hdsentinel says there is bad sectors I wouldn't wait the hours the /r switch can take when checking large drives. Better to just use the /f switch. The /x should be added to dismount the drive before checking. This won't work on a boot drive which will need to run chkdsk on boot.

The other program which may help diagnose slow access is benchme from here  http://www.benchbench.com/
  Update: Cloned C: HDD to F: (USB) Samsung SSD using Samsung Data Migration program overnight. Booted from HHD, no problem. Booted from SSD, Win 10 would not load.

Get recovery message: PC needs repair. OS will not load. Missing file or has errors.
Missing file: \windows\system32\winload.exe  Error code 0xc000007b
Found winload.exe on SSD, Clicked on it, and got the message: App can’t run on this PC.
Any thoughts?

1305.

Solve : DOS 6.0 filetype underscore problem.?

Answer»

Hi,

Here is the problem.

On a dedicated DOS desktop that I use regularly. I recently wanted to compare two floppies. But couldn't activate the 'DISKCOMP.COM' .
Doing a DIR on my DOS files showed that DISKCOMP' is listed as 'DISKCOMP CO_'

Also I noticed that many of the files are so marked with only two letters and an underscore as the filetype.

The files on my original (genuine) DOS 6.2 discs are the same.

Why is this ? And how do I make the underscored files work ?

Thanks in anticipation.

Leo44

(I have looked through many FAQs and can't find an answer)Hi

These are compressed files. As dos INSTALLS increased in size microsoft made the switch to compressing the files to save on the number of disks needed for each install.
It is most likely when Dos was installed the compressed files were copied from the floppy disks instead of using setup.

You can still use setup which will copy un compressed versions of the files to the MSDOS directory.

Please note if you have any special configuration in Config.sys and Autoexec.bat files make copies of these files before doing the setup as they could be over written.Lisa_Maree,

Thanks for that.

There is NOTHING special in either config.sys or autoexec.bat.

I take it the best move will be to save anything I want onto floppy, format the HD and re-install DOS using the install program ?

Leo44Just run setup from the DOS folder and it will do the same as re installing. It only takes a few minutes either way.
I don't think the setup program can be used in that manner. If I run it from within the DOS folder I am merely instructed that I should run it from floppy.
Code: [Select]To install MS-DOS, insert Setup Disk 1 in
drive A and press CTRL+ALT+DEL. This will
restart your computer and begin the Setup
program.

Or press ENTER to return to your command prompt

Running setup from the diskette should do the trick. Would certainly be the easiest way of doing it.

It is also possible to install it manually. The instructions are either in the manual or the readme, though don't really go much further into it beyond telling you to use EXPAND.EXE on all the files, which would mean doing them one at a time.

One might be able to create a batch file for converting a file using EXPAND.EXE, then use that to batch-expand all the files needed. This can be done with two batch files. The first one would be called by the second one here, given the compressed extension and the expanded extension. it creates a temporary folder, copies the files with the specified extension to it, renames them to remove that extension, runs expand on those files and expands them to the second extension, then copies them back into the parent folder:

EXPLOOP.BAT:
Code: [Select]echo off
mkdir TMP%1
copy *.%1 TMP%1
cd TMP%1
RENAME *.%1  *.
for %%P in (*.) do C:\DOS\EXPAND.EXE %%P %%P.%2
copy *.%2 ..
REM del *.*
cd ..
REM rmdir TMP%1

The deletion commands are commented out here. DELTREE cannot be presumed available SINCE it might still be compressed and running a bunch of del commands in a batch never ends well in my experience, so if going this route probably better to erase the temporary folders manually afterwards.

EXP.BAT

Code: [Select]CALL EXPLOOP CO_ COM
CALL EXPLOOP EX_ EXE
CALL EXPLOOP DL_ DLL
CALL EXPLOOP HL_ HLP
CALL EXPLOOP SY_ SYS
CALL EXPLOOP CP_ CPI

Which covers most of the compressed files. Course typing these out into EDIT would take longer than just running setup from the floppy.I believe I know how this problem began.

Way back in time I put some old hard drive into this machine.  Formatted it from the A: drive using Format C:/s to get the system files onto it.

I then copied the three DOS 6.2 discs directly into c:

When I tried to do a proper install of the discs, the setup told me there was already a version of DOS on the hard drive.

I continued with the install, and thus CREATED a DOS directory in C:

The new (installed) version appears there.  That version has all the compresses files expanded.

So all I actually need to do is change directory to C:>DOS

And, at some time, remove the surplus DOS in C:.  Probably will just format c: as I mentioned above; clean start.


p.s.
 For some reason I am getting a '>' sign instead of the backslash.

1306.

Solve : How to start multiple instances of a command line application with a batch file??

Answer»

I'm using resample.exe for Flight Simulator to resample imagery that shows in the sim as photoreal terrain. You use an .inf to specify the sources (.tifs plus their respective geographic information) and output (path\to\output.bgl). Normally I use a "Send to" command on my right click menu where I can select an .inf, right click, and "Send to > resample.exe". That works fine but now I have multiple .infs that I'd like to resample simultaneously so I have to select each one in turn and send them to resample. Resample is very slow and uses only about 10% of one core on the CPU so it's possible to HURRY things along quite a bit by running multiple instances, each working on different parts of the project. I'm trying to come up with a BATCH file that will spin off multiple instances of resample.exe each in it's own window, here's what a typical batch file resample command looks like:

Code: [Select]"C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140308.inf
That command just causes resample to run in the same window the command was issued from and I use it with pause for troubleshooting. Pause holds the window open so you can read the error where when using the Send-to shortcut the DOS window just flashes and closes immediately in the event of an error.

...so I tried this:

Code: [Select]start "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140308.inf
start "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140309.inf

...but that merely opened each .inf in a separate Notepad window. I tried:

Code: [Select]start cmd "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140308.inf
start cmd"C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140309.inf

...and

Code: [Select]start cmd /"C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140308.inf
start cmd /"C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140309.inf

...and

Code: [Select]start "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe":klam_1m_WGS84_03140308.inf
start "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe":klam_1m_WGS84_03140309.inf

...all of the above did something, just not what I wanted, lol.

Obviously I don't know what I'm doing and Start /? merely caused my EYES to glaze over.


Can I get a little help from the experts here?

Thanks much,
JimIt seems I have this sorted:

Code: [Select]start cmd /k "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140308.inf
start cmd /k "C:\Microsoft Games\Microsoft Flight Simulator X SDK\SDK\Environment Kit\Terrain SDK\resample.exe" klam_1m_WGS84_03140309.inf

...spins off two NEW cmd windows each resampling different parts of the imagery.

More details if anyone's curious:
The entire project currently uses 92 sources (.tifs) at roughly 1.1 Gb apiece. The simulator has a limitation where a .bgl can't exceed 2 Gb or it won't show. Resample has an option for "SplitFileLOD" where it will split large projects like this up into smaller .bgls to avoid exceeding the 2 Gb limitation, I'm using SplitFileLOD=9 where it splits the .bgls at LOD9 boundaries which are approximately 13 miles across in both the X and Y directions. The 92 sources are split into 31 separate .bgls using SplitFileLOD=9. Resample also has an option for "BoundingCell" where you can constrain the output to a particular cell, BoundingCell=11,314,308 for example causes resample.exe to resample just one of the 31 .bgls that make up the project (klam_photo_1m_03140308.bgl). If I leave BoundingCell out of the .inf resample will start at the top left corner and resample each of the 31 .bgls in turn until it finishes the project. That means it's bedtime because last I checked it takes a little over 4 hrs to do that, lol.

Being ABLE to spin this off into multiple instances, maybe six instances at a time to get the CPU load up somewhere near 100%, I can cut that resampling time down significantly. Also if I make edits to just one or two .tifs I can resample only the .bgl affected by those .tifs I've edited rather than having to resample the whole lot at once.

Thanks for checking this thread out folks. I think I'm good to go now.
Jim

1307.

Solve : Compaq Presario 4784 strange problems...?

Answer»

I have a Compaq Presario 4784 MS-DOS/Windows PC, with the accompanying Presario 1585 CRT monitor.
The specs are as follows:
CPU: Intel Pentium with MMX 133 MHz
RAM: 32 MB
HDD: 4 GB Quantum Bigfoot IDE
GPU: Onboard S3 ViRGE chipset
Sound: Onboard ESS 1888 Plug and Play AudioDrive (missing drivers)
OS: MS-DOS 7.10 CDU and Windows 98 SE

I've taken the system apart several TIMES, usually to diagnose an issue or to clean it. Strangely, it's put together with Torx screws. I've always put everything back as I had it before using the system again. When I received the computer about a year AGO, it had Windows 95 on it. I formatted the hard drive and installed DOS 7.10 and Windows 98 Second Edition. This proved to be a mistake, as I lost all the Compaq OEM stuff, which included drivers. So it was a massive pain to get all the drivers back, and I can't seem to get any working for the ESS audio device. Other than no sound, the computer works fine. I should note that Windows does not start on bootup, I have to type "win" into the DOS prompt to start it.

The computer has been acting strange recently. The CD-ROM drive doesn't spin up discs anymore, and the fancy little MS-DOS 7.10 bootscreen sometimes has really messed up colors. However, now for some reason when I turn it on, it does nothing! The monitor will show a barely visible dull brown color as soon as the system is turned on, but nothing else will happen. The hard drive will be accessed briefly, the drives will do their thing, but nothing else will happen. There's no PC speaker beep, no display, nothing. Just to make sure it wasn't just a display issue, I typed "win" into the keyboard, to see if it would access the hard disk to start Windows. However, there was no response. Strangely enough, turning off the system will cause the dull brown color to remain on the screen until it is turned off.

Can anyone help me?EDIT: Made a small mistake and I don't know how to edit (or if I can at all, lol.) The monitor is a Presario 1525, not a 1585.Hi I suspect the problem is a dead CMOS battery which on your motherboard is soldered on. I have included a picture of the motherboard with the battery circled in read if you have a volt meter it should read 3 V with the power turned off.

Also check the AT power connector for the output voltages of the power supply particularly the orange wire to pin 1 that this is at 5 V  (Power Good, +5 VDC when all voltages have stabilized.)

Also check the capacitors circled in orange these should be flat across the top not bulged.

When you get the computer back booting then you could load these drivers from Dell for the ESS 1888 https://www.dell.com/support/home/en-si/drivers/driversdetails?driverid=r18791

You say the ESS 1888 is plug and play in the Compaq, when I look around the internet there is config.sys and Autoexec.bat with drivers loading for the sound card.

I don't have a voltmeter to test the battery, unfortunately. I checked the capacitors, they look fine. Also, I hate to argue with someone who LIKELY knows way more than I do, but wouldn't a dead CMOS battery still allow the computer to boot properly? In my experience, a dead CMOS battery will cause the computer to lose the BIOS settings and date/time, however the computer still boots up fine. MAYBE this Compaq works differently, it's a strange computer so that wouldn't surprise me.You are correct, in most cases a flat CMOS battery would cause a cmos checksum error display. Some computers will not post and there fore not display anything without a charged CMOS battery.
Have you tried the computer with the onboard VGA adapter, if you have a PCI video adapter you would need to remove it ?
If it works with the on board then it is still likely to be the cmos battery. As the bios has a setting for which VGA adapter is used.

1308.

Solve : Batch Script - Setup command then change parameters for each call?

Answer» HI,
I want to setup a batch file that will run a JAVA JAR file that REQUIRES a number of parameters. The tidiest way (I think) to do this is to setup the command first, then for each call, change the parameters for the specific call. However, since the file runs sequentially, the parameters need to be setup before the command is setup. This means the command needs to be setup multiple times (after each set of parameters is setup/changed). Is there a way to do this that allows me to setup the command without expanding/replacing the parameters until after I setup the parameters? I'm guessing not, but please confirm.

E.g. Simplified version to explain what I do and what I want. In reality there are many more parameters and many more calls. I use only 2 parameters and 2 calls below to explain.
:: Start of file
:: This is how it works now, but I need to set command twice using the same string
SET "param1=a1"
SET "param2=b1"
SET "command=java theJavaApp.jar %param1% %param2%"
%command%

SET "param1=a2"
SET "param2=b2"
SET "command=java theJavaApp.jar %param1% %param2%"
%command%

:: I want to be able to set command just once (at the start) like below
SET "command=java theJavaApp.jar %param1% %param2%"

SET "param1=a1"
SET "param2=b1"
%command%

SET "param1=a2"
SET "param2=b2"
%command%

:: End of File

I tried to set command by escaping the parameters like this...
SET "command=java theJavaApp.jar %%param1%% %%param2%%"
:: This sets command to what I want "java theJavaApp.jar %param1% %param2%", but it does not replace the parameters when I call the command. Is there a way to achieve this?
SET "param1=a2"
SET "param2=b2"
%command%

THANKS

1309.

Solve : Read multiple specific lines in txt file - save each line into a variable -Batch?

Answer»

Hello everyone, I'm writing a batch file to organize and manage my movies downloaded on my computer. The idea is simple, I start with the main page with 2 options, either watch a movie, or add one to the library. The library is basically a txt file with all the information about each movie. The add movie FEATURE asks users to insert movie name, year, description, and then opens a dialog box for the user to select the location where the movie is downloaded. it will then save the movie into movies.txt like this:

Code: [Select]Name: Test 1
Year: Test 1
Desc: Test 1
Path: C:\Desktop\Movie1.mp4
----------------------------------------------------------------
Name: Test 2
Year: Test 2
Desc: Test 2
Path: C:\Desktop\Movie2.mp4
----------------------------------------------------------------
Name: Test 3
Year: Test 3
Desc: Test 3
Path: C:\Desktop\Movie3.mp4
----------------------------------------------------------------

My batch file already counts how many movies there is in the library, but I need it to:

1)Read the names of the movies
2)List only the movie names with a number next to each one
3)Let the user type the number he wants (for example if he chooses the second movie, he types 2)
4)Take the user to a new page showing the information of the movie(name,year,desc)
5)Have the option to directly start the movie using a command from the batch file ( for example, if the user types "w" the batch file will open the movie in whatever media player)

The library will be constantly updated by the user depending on the movies he has. So the program should be able to show all the movies in the library, and make a page automatically for each movie in the library which does what I wrote above.

I will add the whole code I have written since I don't care about anything except help. I know it's messy but I'm new to this thing.

Code: [Select]echo off
title DanFlix 1.3

:main
cls
echo -------------------------
echo       DanFlix 1.3
echo -------------------------
echo What do you want to do?
echo Press W to Watch
echo Press A to Add Movie/TV Show to database
echo Press S to go to Settings
echo Press Q to Quit
set /p act2=
if %act2% == W goto Watch
if %act2% == A goto add
if %act2% == S goto set
if %act2% == Q exit
if %act2% == w goto Watch
if %act2% == a goto add
if %act2% == s goto set
if %act2% == q exit


:set
cls
echo We are updating our program to support more Features
echo ----------------------------------------------------
echo                    Coming Soon
echo ----------------------------------------------------
PAUSE
goto main

:Watch
cls
echo Press M to watch a Movie
echo Press T to watch a TV Show
echo Press B to go back
set /p watchact=
if %watchact% == M goto movie
if %watchact% == T goto tvshow
if %watchact% == B goto main
if %watchact% == m goto movie
if %watchact% == t goto tvshow
if %watchact% == b goto main

:movie
echo Select a Movie from your Library
set file=Movies.txt
set /a moviecnt=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a moviecnt=%%a
set /a movienumber=%moviecnt%/5
echo You have %movienumber% Movies
echo ---------------------------------------------------------------------------
more Movies.txt
PAUSE


:tvshow
CLS
echo Select a TV Show from your Library
set file=TVShows.txt
set /a tvshowcnt=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a tvshowcnt=%%a
set /a tvshownumber=%tvshowcnt%/7
echo You have %tvshownumber% TV Shows
echo ---------------------------------------------------------------------------
more TVShows.txt
PAUSE



:add
cls
echo DanFlix allows users to add Movies and TV Shows to their local database for easier organization and viewing
echo ___________________________________________________________________________________________________________
echo Let's add a file to your database
echo Is your file a Movie or a TV Show?
echo If Movie: Enter M
echo If TV Show: Enter T
set /p addact=
if %addact% == M goto addmovie
if %addact% == T goto addtvshow
if %addact% == m goto addmovie
if %addact% == t goto addtvshow

:addmovie
echo ---------------------
echo    Adding Movie
echo ---------------------
echo What is the name of the movie?
set /p MOVIENAME=
cls
echo ---------------------
echo    Adding Movie
echo ---------------------
echo Movie Name: %moviename%
echo What is the release year of the movie?
set /p movieyear=
cls
echo ---------------------
echo    Adding Movie
echo ---------------------
echo Movie Name: %moviename%
echo Movie Year: %movieyear%
echo Insert a Movie description?
set /p moviedesc=
cls
echo ---------------------
echo    Adding Movie
echo ---------------------
echo Movie Name: %moviename%
echo Movie Year: %movieyear%
echo Description: %moviedesc%
echo Please Find Your Video File, make sure you don't move it in the future
PAUSE
cls
goto filedialogmovie

:filedialogmovie
FOR /F "tokens=*" %%A IN ('OpenFileBox.exe ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET File=%%A
IF "%File%"=="Cancel" (
    ECHO You clicked "Cancel"
    PAUSE
    goto main
) ELSE (
    IF "%File%"=="Error" (
        ECHO An error OCCURRED
    ) ELSE (
        ECHO You SELECTED "%File%"
    )
)

PAUSE

(echo=Name: %moviename%) >> Movies.txt
(echo=Year: %movieyear%) >> Movies.txt
(echo=Desc: %moviedesc%) >> Movies.txt
(echo=Path: %File%) >> Movies.txt
(echo=----------------------------------------------------------------) >> Movies.txt
PAUSE
cls
echo ---------------------
echo     Movie Added
echo ---------------------
PAUSE
echo Press A to add another movie or tv show
echo Press G to go back to the main menu
set /p addedmovieact=
if %addedmovieact% == A goto add
if %addedmovieact% == G goto main
if %addedmovieact% == a goto add
if %addedmovieact% == g goto main




:addtvshow
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo What is the name of the TV Show?
set /p tvshowname=
cls
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo TV Show Name: %tvshowname%
echo What is the start and end year of the TV Show?
echo Example: 2015-2020 or 2020- if still renewing?

set /p tvshowyear=
cls
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo TV Show Name: %tvshowname%
echo TV Show Year: %tvshowyear%
echo Which season are you adding?
set /p tvshowseason=
cls
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo TV Show Name: %tvshowname%
echo TV Show Year: %tvshowyear%
echo TV Show Season: %tvshowseason%
echo How many episodes does this season have?
set /p tvshowepisodes=
cls
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo TV Show Name: %tvshowname%
echo TV Show Year: %tvshowyear%
echo TV Show Season: %tvshowseason%
echo TV Show Season: %tvshowepisodes%
echo Insert a TV Show description?
set /p tvshowdesc=
cls
echo ---------------------
echo    Adding TV Show
echo ---------------------
echo TV Show Name: %tvshowname%
echo TV Show Year: %tvshowyear%
echo TV Show Season: %tvshowseason%
echo TV Show Season: %tvshowepisodes%
echo TV Show Description: %tvshowdesc%
echo --------------------------------------------------------------
PAUSE
cls
echo Please Find Your Video File, make sure you don't move it in the future
PAUSE
cls
goto filedialogtvshow

:filedialogtvshow
FOR /F "tokens=*" %%A IN ('OpenFolderBox.exe ^|^| ECHO Error^& IF ERRORLEVEL 2 ECHO Cancel') DO SET FileTV=%%A
IF "%FileTV%"=="Cancel" (
    ECHO You clicked "Cancel"
    PAUSE
    goto main
) ELSE (
    IF "%FileTV%"=="Error" (
        ECHO An error occurred
    ) ELSE (
        ECHO You selected "%FileTV%"
    )
)

PAUSE



(echo=%tvshowname%) >> TVShows.txt
(echo=%tvshowyear%) >> TVShows.txt
(echo=Season %tvshowseason%) >> TVShows.txt
(echo=%tvshowepisodes% Episodes) >> TVShows.txt
(echo=%tvshowdesc%) >> TVShows.txt
(echo=%FileTV%) >> TVShows.txt
(echo=----------------------------------------------------------------) >> TVShows.txt
PAUSE
cls
echo ---------------------
echo    TV Show Added
echo ---------------------
PAUSE
echo Press A to add another movie or tv show
echo Press G to go back to the main menu
set /p addedtvshowact=
if %addedtvshowact% == A goto add
if %addedtvshowact% == G goto main
if %addedtvshowact% == a goto add
if %addedtvshowact% == g goto main

Note, everything is basically done, except the watch feature. The watch feature goes in the :movie and :tvshow. The :movie should show the movies in the libraries with the ability for the user to click the specific number to open the movie's page and view the movie from there.

Thanks everyone in advance.

And, if any of you knows an application for android or windows that lets me do what I'm trying to do in batch, I would really love a SUGGESTION. I've been looking for an app that lets me make a library and add my movies to it and watch the movies, but I cant find any. I dont want a normal media player, I want an app that lists the movies and lets me open the media player through it or whatever.This is written as a stand alone batch file, but you can remove any duplicate code and copy it into your existing code. Batch language does not support collections, so this steals an idea from Classic Rexx using a stem.tail construct.

Code: [Select]echo off
setlocal enabledelayedexpansion
set x=0
echo.

for /f "tokens=1* delims=:" %%i in (g:\wfc\testlib\movies.txt) do (
  if %%i==Name (
    call set /a x+=1
    call set name.%%x%%=%%j
    call echo !x!. %%j
  )

  if %%i==Year call set year.%%x%%=%%j
  if %%i==Desc call set desc.%%x%%=%%j
  if %%i==Path call set folder.%%x%%=%%j
)

echo.
set /p sel=Enter Selection:
if %sel% EQU 0 goto :eof
if %sel% GTR !x! goto error
if %sel% LSS 0 goto error

cls
echo You Selected:
echo    Name: !name.%sel%!
echo    Year: !year.%sel%!
echo    Desc: !desc.%sel%!
echo.

set /p view=Type "w" to Watch Movie:
if %view%==w !folder.%sel%!
goto :eof


:error
  echo Selection Out Of Range

You will need to change line 6 to point to your movie file, but other than that you should be good to go.

Happy Viewing 

1310.

Solve : Concatenate two BAT commands to single line output?

Answer»

Hello! 

Thanks in advance for any help you can provide, I have what I THINK should be a simple issue but I cannot seem to find the solution.  I have a very small batch file that i use to select two random WORDS from a text file of thousands of words.  Currently, it returns results in two separate rows, such as:

RandomWordOne
RandomWordTwo

I would instead like it to return these on one line with a space in between, like this:

RandomWordOne RandomWordTwo

Below is the simple code I am using, I have connected the commands on one ROW with & but cannot get the output on one line:

echo off

set /a rnd=%random%%%370103
set /a rnd2=%random%%%370103
for /f "tokens=1,2" %%a in (list.txt) do if %rnd%==%%a echo %%b & for /f "tokens=1,2" %%a in (list.txt) do if %rnd2%==%%a echo %%b

pauseIn all honesty I couldn't really determine what your code was doing so I invented my own that may give you some IDEAS. I used a list of 1000 words (one per line) and used the batch file below to randomly choose two of them.

Code: [Select]echo off
setlocal enabledelayedexpansion

set x=0
for /f %%i in (list.txt) do (
  call set word.%%x%%=%%i
  call set /a x+=1
)

set min=1
set max=1000

set /a rnd=%random% %% (%max% - %min% + 1)  + %min%
set /a rnd2=%random% %% (%max% - %min% + 1)  + %min%

call echo !word.%rnd%! !word.%rnd2%!

If you do run the code, be aware of the lag time while the code loads an array of the words.

Good luck  Thank you for the reply!  I tried this but there was what I would consider an extreme lag in processing this way, the list of words and PHRASES I'm using is ~370k entries long and the intention of this file is to produce multi-word sentences at a rate of around 5 seconds each, give or take.After smashing my head into my desk a few times I found the solution, I just added a "set XX=%%b" to each "do if" statement, then echoed each XX on one line at the end.  Thanks everyone for reading and thanks for the response!

1311.

Solve : Collect all IPs For online workstations only on my domain?

Answer»

Hi All,

I want to collect the IPs for  online workstations on my DOMAIN and i have TWO scripts the FIRST script to only display which is the online  and the other script to collect the IPs for any host name inside the input file named (hosts.txt).
and i want to merge this two scripts to do what i want which is to ping any host name taken for the input file then try to ping on it and if it's online try to bring it's IP then insert the result into output file but i couldn't

Can Any professional here to assist
here is the mentioned two scripts.

First one to ping all host names and separate them inside two output files.

Code: [Select]echo off
for /f %%i in (hosts.txt) do (
   SET bHOSTUP=0
   ping -n 1 %%i -w 2000 |find "TTL=" > NUL && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      set g=%%i
      CALL :HOSTUP %%i
   ) else (
      set g=%%i
      CALL :HOSTDOWN %%i
   )
)

GOTO EOF


:HOSTUP
Echo %g% : Is Pingable
Echo %g% : Is Pingable>>Online_workstations.txt
GOTO EOF


:HOSTDOWN
Echo %g% : is Offline or Not Exist
Echo %g% : is Offline or Not Exist>>Offline_workstations.txt
GOTO EOF


:EOF
exit /B


And Here is the second script which used to collect the IPs for all host names located in the input file also
Code: [Select]
echo off
for /F "tokens=* delims=" %%C in (hosts.txt) do (
for /f "tokens=1,2 delims=[]" %%A in ('ping %%C ^| find "Pinging"') do set ipaddress=%%B && echo %%C : %%B
)


I want to merge these two scripts into one batch (one step)( separate online workstations and offline workstations and if found that the workstation is online try to get its IP and insert this information inside the output file.Hi 
Just give a try for the combined script and tell me the results on your side !

Scan_Hosts_IP.bat
Code: [Select]echo off
Title Collect all IPs For online workstations only on my domain
Set "HOSTS_File=%~dp0hosts.txt"

IF NOT EXIST "%HOSTS_File%" (
Color FC
ECHO(
Echo( Please Check this "%HOSTS_File%" location with this script "%~nx0"
TimeOut /T 8 /NoBreak>nul
EXIT
)

Set "LogFile_OnLine=%~dp0_Online_workstations.txt"
If Exist "%LogFile_OnLine%" Del "%LogFile_OnLine%"
Set "LogFile_OffLine=%~dp0_Offline_workstations.txt"
If Exist "%LogFile_OffLine%" Del "%LogFile_OffLine%"

SetLocal EnableDelayedExpansion
for /f %%i in ('Type "%HOSTS_File%"') do (
SET bHOSTUP=0
Ping -n 1 %%i -w 2000 |find "TTL=">NUL && SET bHOSTUP=1
IF [!bHOSTUP!] equ [1] (
set "HostName=%%i"
Call :GET_IP %%i
CALL :HOSTUP %%i
) else (
set "HostName=%%i"
CALL :HOSTDOWN %%i
)
)

START "Log" /MAX "%LogFile_OnLine%"
GOTO EOF
::----------------------------------------------------------------------
:HOSTUP
IF defined IP (
Echo !HostName! : Is Pingable - IP = !IP!
Echo !HostName! : Is Pingable - IP = !IP!>>"%LogFile_OnLine%"
) Else (
Echo !HostName! : Is Pingable
Echo !HostName! : Is Pingable>>"%LogFile_OnLine%"
)
GOTO EOF
::----------------------------------------------------------------------
:HOSTDOWN
Echo !HostName! : is Offline or Not Exist
Echo !HostName! : is Offline or Not Exist>>"%LogFile_OffLine%"
GOTO EOF
::----------------------------------------------------------------------
:GET_IP <HOST> <IP>
Set "IP="
for /f "tokens=2 delims=[]" %%b in ('ping -n 1 %1') do Set "IP=%%b"
Exit /B
::----------------------------------------------------------------------
:EOF
exit /B
::----------------------------------------------------------------------Hi 
For who is still interested for any improved of this Batch script : You can found it here for any update : Scanner_IP_MAC_Colors.bat
Have a nice day 
Thanks, Hackoo for appreciate helping

1312.

Solve : I'm getting blue screens every few hours, what can I do??

Answer»

My PC gets blue screens every few hours "Your PC has run into problems and needs to restart".

I had a 120 gb SDD inserted last YEAR and it works fine for the most part before the crashes take place.

ATTACHED is a screenshot from Blue Screen View. Hi
For some reason I can't open the attachment but most likely the SSD is is running out of space. You should with windows 10 keep about 25 Gb FREE space on the hard drive and to get the best life from an SSD only half fill it with data. So say you have 120 Gb of data then at least a 240 gb SSD. This leaves plenty of space to for wear leveling.

1313.

Solve : Reading text file line by line and do some operations - Windows Batch File?

Answer»
What I am TRYING to do here is to parse every row in filename.txt file and then run 2nd FOR loop to output it into another text file.

Filename.txt has multiple rows which looks something like this:

[email protected]|Filename.csv
[email protected]|Filenam1.csv
[email protected]|Filename.csv
and so on.

I need help in building a script to read the lines one by one for example I want to read [email protected]|Filename.csv 1st and then do some operations and after the operations are done, I want to to goto the next line and do the same operations. The output of the operations will be stored in a file and will be overwritten every time the loop counter increments and goes to the next line.

My output file should contain only 1 row at a time and not all the rows. What I am thinking is to create a counter and then use that counter in the for loop and then do the operations but I am not getting the desired output.

I went through the threads where something similar was asked but could not solve my issue.One more important point there is a pipe ('|') in the text file.

I have tried this, till now:
set /a count=0
for /F "tokens=*" %%a in (C:\filename.txt) do (
         
         Set /a count+=1
         Set output[!count!]=%%a
         echo %output[!count!]%
         Pause
         )
I am not ABLE to call or access this outside the loop, like I would like to use the 1st row which will be represented by counter=1 first in a different for loop do some operations and then  come back and increment the counter=2 pointing to the 2nd row and do the same operations.Lets say we have a file called file.txt.

Within that file I have the following rows: [email protected]|Filename.csv [email protected]|Filenam1.csv [email protected]|Filename.csv

So what I want is to read/access each line one at a time. For instance, 1st we access [email protected]|Filename.csv then do some operation where I will be inputing [email protected]|Filename.csv into a temp file and use this file in a different for loop for some other operations.

After this is done I want to goto [email protected]|Filenam1.csv and do the same operations and finally [email protected]|Filename.csv.

   
Every time the increment happens, the temp file will be overwritten with the current row field and we will exit out of the loop when %1 = ''.

I hope I have explained my problem clearly.Hi 
We can do like this script without using a temp file :
Code: [Select]echo off
set "File=C:\filename.txt"
set /a count=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File%"') do (
         Set /a count+=1
         Set "output[!count!]=%%a"     
)

For /L %%i in (1,1,%Count%) Do (
Call :Action "!output[%%i]!"
pause
)

Exit
::*******************************************************
:Action
echo We treat this line : %1
exit /b
::*******************************************************I've subscribed to this forum just to thankyou "Hackoo" for your solution.
Worked like a charm.

Cheers! Quote from: jonasgozdecki on September 03, 2019, 08:01:52 AM
I've subscribed to this forum just to thankyou "Hackoo" for your solution.
Worked like a charm.
Cheers!
jonasgozdeck
You are very welcome and anytime too Bro 
Have a nice day  I have JOINED this form because this is as close to what I'm looking for as I can find... I want to take what you've created here and be able to select a line by choice and then use those variables only on that line... My objective is to take something like the following -

Code: [Select]Variable1    Variable2     Variable3     Variable4
Description1 ComputerName1 ComputerUser1 ComputerPassword1
Description2 ComputerName2 ComputerUser2 ComputerPassword2
Description3 ComputerName3 ComputerUser3 ComputerPassword3
Description4 ComputerName4 ComputerUser4 ComputerPassword4
Description5 ComputerName5 ComputerUser5 ComputerPassword5
Description6 ComputerName6 ComputerUser6 ComputerPassword6

And then use it for creating something that would look like this -

Code: [Select]Variable1's listed from text file -

Description1
Description2
Description3
Description4
Description5
Description6

Make a selection: ((User ENTERS Variable1))

cmdkey /generic:"<line1variable2>" /user:"<line1variable3>" /pass:"<line1variable4>" <-------from a specific line a user selects
mstsc /v:"<line1variable2>" /f <-------from a specific line a user selects
Any help would be greatly appreciated...



Quote from: Hackoo on June 13, 2017, 08:26:55 PM
Hi 
We can do like this script without using a temp file :
Code: [Select]echo off
set "File=C:\filename.txt"
set /a count=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File%"') do (
         Set /a count+=1
         Set "output[!count!]=%%a"     
)

For /L %%i in (1,1,%Count%) Do (
Call :Action "!output[%%i]!"
pause
)

Exit
::*******************************************************
:Action
echo We treat this line : %1
exit /b
::*******************************************************
I had reposted this question as my own and Sidewinder answered!

Here's his perfect reply -- thanks!

Quote from: Sidewinder on May 21, 2020, 12:03:41 PM
Batch language is truly ugly. That said, the batch LOGIC here is to create an in-memory array (of sorts), let the user make a selection and then create the parameters for the cmdkey and mstsc commands.

Code: [Select]echo off
setlocal enabledelayedexpansion
set x=0

for /f "skip=1 tokens=1-4" %%i in (%~dp0\Choices.txt) do (
  call set /a x+=1
  call set item.%%x%%.1=%%i
  call set item.%%x%%.2=%%j
  call set item.%%x%%.3=%%k
  call set item.%%x%%.4=%%l
)

for /l %%i in (1,1,%x%) do (
  call echo %%i. !item.%%i.1!
)

echo. & set /p sel=Enter Selection:

cmdkey /generic:"!item.%sel%.2!>" /user:"!item.%sel%.3!" /pass:"!item.%sel%.4!"
mstsc /v:"!item.%sel%.2!" /f

The batch file uses a file named Choices.txt for it's input. The name is negotiable, just be sure to change the batch file accordingly.

The descriptions, computername, computeruser and computerpassword fields cannot contain any embedded spaces or special characters. This is not negotiable.

Hope this gives you some ideas
My data in txt file is paths. I used command
Code: [Select]start %1% to open a file, but it don't work.
This is my code:
Code: [Select]echo off
set "File=D:\listpathfile.txt"
set /a count=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File%"') do (
         Set /a count+=1
         Set "output[!count!]=%%a"     
)

For /L %%i in (1,1,%Count%) Do (
 Call :Action "!output[%%i]!"

 pause
)

Exit
::*******************************************************
:Action
echo We treat this line : %1
start %1%
exit /b
::*******************************************************Any help I appreciate and welcomelinhkythuat
You should try something like that :
Code: [Select]echo off
set "File=D:\listpathfile.txt"
set /a count=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File%"') do (
Set /a count+=1
Set "PathFile[!count!]=%%~a"
)

For /L %%i in (1,1,%Count%) Do (
Call :Action "!PathFile[%%i]!"
pause
)
Exit
::-----------------------------------
:Action
echo We treat this line : "%~1" to start "%~nx1"
start "%~nx1" "%~1"
exit /b
::-----------------------------------
1314.

Solve : Editiing hosts file...why so difficult??

Answer»

It used to be a simple process to add a line to the hosts file either manually or by some third party software. Now it seems that all this has changed.
There are MANY "how-tos" on the net, but not that I have tried has worked. In the end, it always comes down to the following ERROR when overwriting the existing hosts file (write protected or not):

The process cannot access the file because it is being used by another process.

Why do I KEEP getting this error message and how can I fix it?

Thanks
Quote from: iONik on January 10, 2021, 04:01:41 PM

It used to be a simple process to add a line to the hosts file either manually or by some third party software. Now it seems that all this has changed.
There are many "how-tos" on the net, but not that I have tried has worked. In the end, it always comes down to the following error when overwriting the existing hosts file (write protected or not):

The process cannot access the file because it is being used by another process.

Why do I keep getting this error message and how can I fix it?

Thanks

FIXED!
There was an OPTION in my antivirus/firewall software that blocks access to the hosts file!
1315.

Solve : Need backup/rar for mysql at Windows?

Answer»

hello friends

i need backup script. i will use with cobian backup shelude. this backup will be execute per 8 hours in day

(sorry... i dont know how i can close/shutdown later re-start Win-MySql... if you know that.. pls add to script)

my source directory = c:\PDKS\DB\

first target/backup path =  e:\PDKS\

second target path = c:\Backup\PDKS\

rar execute path =  C:\Program Files\WinRAR\rar.exe       (sorry)

i need date time stamp before backup --Year ; Month(count  JANUARY = 01 - april = 04 - agust = 09 - december = 12) ; Day (count 01,02,03....29-30-31) ; time (00:30:15; 23:12:59)

what i need?
i wanna copy all DB files from (c:\PDKS\DB\*.*)  to  (e:\PDKS\PDKS__%YEAR%_%Month%\PDKS__%year%_%month%_%date%_%hour:min:sec%\*.*)

if all files copyed to target directory... i need COMPRESSED file with target directory name.. example  "PDKS__%year%_%month%_%date%__%hour:min:sec%.rar"  (PDKS__2021_01_08__17:07:43.rar)

if db files compressed, must delete that directory from path
mean; i dont need this SUB directory (PDKS__%year%_%month%_%date%__%hour:min:sec%\) at   e:\PDKS\PDKS__%YEAR%_%Month%\

if; first target path is down or protected for write, i need backup file at localpath...  ( this   "e:\"  path is my NAS)

mean; 

backup files must c:\Backup\PDKS\ with same directory name

c:\Backup\PDKS\PDKS__%YEAR%_%Month%\PDKS__%year%_%month%_%date%__%hour:min:sec%\*.*

and compressed file name must be "PDKS__%year%_%month%_%date%__%hour:min:sec%.rar"   (PDKS__2021_01_08__17:07:43.rar)

next step must delete sub directory ; i need just compressed files at (c:\Backup\PDKS\PDKS__%YEAR%_%Month%\)

rar file compress status enough "classic-normal" type; i dont need password for rar file.. this is only backup file

could you help me?


thank you very much

Hi 
Note : This format can't be saved as file "PDKS__%year%_%month%_%date%__%hour:min:sec%.rar"
You need to replace : by underscore _ for example 

Here is an example using powershell to format your date as you want !
Code: [Select]echo off
Title Get Date format as [yyyy_MM_dd__HH_mm_ss] with Powershell in batch file
for /f %%a in ('powershell -COMMAND "Get-Date -format yyyy_MM_dd__HH_mm_ss"') do set datetime=%%a
echo "PDKS__%datetime%.rar"
pausehello... i dont know powershell with cobian backup

date format not importand ":" or "_"

i can accept ur offer about this backup

my needs compressed file with date&time format and faster backup.

coudl help me ?


Quote from: Hackoo on January 09, 2021, 09:07:55 AM

Hi 
Note : This format can't be saved as file "PDKS__%year%_%month%_%date%__%hour:min:sec%.rar"
You need to replace : by underscore _ for example 

Here is an example using powershell to format your date as you want !
Code: [Select]echo off
Title Get Date format as [yyyy_MM_dd__HH_mm_ss] with Powershell in batch file
for /f %%a in ('powershell -Command "Get-Date -format yyyy_MM_dd__HH_mm_ss"') do set datetime=%%a
echo "PDKS__%datetime%.rar"
pause
1316.

Solve : batch file to restart all hosts included in text file with a random timeout?

Answer»

Hi all
I want to restart a package of machines located in text file Through the below steps:
- Firstly ping for each one of them .
-IF the hosname is available
       - Create a random NUMBER between 0 and 15 seconds and store it in a VARIABLE.
       - Execute the remote shutdown command usinge a random timeout stored in the PREVIOUS variable.
       - Store the result in an output file "Result.txt" in the same folder.
-IF the hostname is not available
        - Also store the result in an output file "Result.txt" in the same folder.

here is my batch file content
echo off
for /f %%H in (hosts.txt) do (
   echo %%H
   ping -n 1 -l 32 -w 2000 -i 32 %%H >nul
   echo %errorlevel%
   pause
   IF %ERRORLEVEL%==0  (
      set /a "rand=(%RANDOM%*15/32768)+1"
      echo %rand%
      shutdown -r -t %rand% -c "Made by Eng Amin" -f -m \\%%H
      echo.[%%H is restarted]>>Result.txt
   )
   IF %ERRORLEVEL%==1  echo.[%%H is --- Offline]>>Result.txt
)


and this is the content of the hosts.txt and located in the same directory
C3I3C331
C3I3C332
C3I3C333
C3I3C334

by the way I'm still beginner
Can any one advice , CORRECT my code and till me where is the bug
Hi All

Kindly don't ignore my question and Can anyone help me, please?

I want to restart any pc over my network using the shutdown command with a random timeout between 1 to 15 seconds.

Ex.
shutdown -r -f -t %random time from 1 to 15 sec% %hostname Or Ip%
as it didn't work with me ever
My point here is to give any pc a random timeout for shutdown command as all PCs included in a text file and I will use for LOOP to pass through them
and if you know a better solution kindly help

1317.

Solve : How to "nest" the FOR command?

Answer» THANKS to Sidewinder, I now have an automated process for getting the IP Addresses for 120+ machines using a file that has a list of all the computers I manage by name.  I even got the info to pipe into another file so I can use the IP Addresses for something else.

Here's the code for anyone else who may need it.  I modified it so it prints the machine name with the IP address next to it.  Thanks go out to Sidewinder for the initial coding, I just modified it to include the machine name and pipe it to a .txt file.

Code: [Select]ECHO OFF
IF EXIST IP_List.txt del IP_List.txt
For /f %%a in (Computer_List.txt) do (ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do (echo Workstation is %%a IP Address is %%k >> IP_List.txt))

To quote Sidewinder when he provided it to me "Yeah yeah, it's *censored* ugly but so is batch code." or something very close to that.

What I'd like to figure out next is the process for "nesting" the FOR command.  I see it in the code above but don't really understand the syntax.  If anyone (including you, Sidewinder) can help me with this by replying or pointing me to an ONLINE resource that specifically deals with nesting FOR commands, I'd appreciate it.  I'm trying to combine the "ping" command with another command (nbtstat -a most likely) that will allow me to strip out the MAC Address of the machines as well.  I want to have all three pieces of info "pipe" into the text document

Example
Code: [Select]blah blah blah ECHO The Machine Name is %%a the IP Address is %%k and the MAC Address is %%x >> IP_List.txt

Ordinarily I'd go direct with Sidewinder but I figure, just like the code at the top of this POST, someone could probably use the same info I'm looking for so I'll ask the question here and everyone else can benefit from the replies I get. Code: [Select]
ECHO OFF
IF EXIST IP_List.txt del IP_List.txt
For /f %%a in (Computer_List.txt) do (
     ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do (
           nbtstat -a %%a | for /f "tokens=1-2 delims=^=" %%x in ('find "MAC Address"') do (
           echo Workstation is %%a IP Address is %%k Mac Address is %%y >> IP_List.txt
           )
     )
)


Good luck with finding documentation on nested FOR statements. Even the MS documentation for a single FOR is severely LACKING. Personally, I find it easier to write them backwards...start with the innermost FOR and develop the outer FORs around it. On the other hand, if I were administering 120+ machines I would seriously consider using Windows Script but that's for another day.

Good luck.   Quote
On the other hand, if I were administering 120+ machines I would seriously consider using Windows Script but that's for another day.

Good luck.  


Ordinarily, so would I but "The Powers that Be" limit how much us "Powers that Wanna Be" have access to.  Besides, I know even less about scripting that I do .bat but that'll change too if I have any say in the matter.

EDIT: It looks like the | is used after each do (XXX) statement to bring the next FOR command online before it goes to the next item in computer_list.txt.  I had thought this was the case but wasn't sure how to tie it in.  Thanks for the help.  I can use this for other similar things where I want to pull a list of things and run a process on it.  Dude, you RULE! Quote
It looks like the | is used after each do (XXX) statement to bring the next FOR command online before it goes to the next item in computer_list.txt.


Not quite. Nesting FORs is much like creating loops within loops, each with its own defined variable(s). Your first FOR sets up a loop to read the Computer_List file one record at a time. Each record (computername) is fed into a PING command (that's the purpose of the | aka: a pipe). The PING then pings a computer by name and returns an IP address, which the next FIND will parse according to the rules setup by the preceeding FOR. At this point you have a computername and an IP address. Next up, you take the computername and pass it to NBTSTAT, which returns a boatload of output and again, you go thru and search  for "MAC Address". When it's found, the preceeding FOR has setup the parsing rules, and you can extract the  the MAC address which is assigned another variable. Finally, you have variables (%%a, %%k, and %%y) with info you want, and output them to a file. The closing parens just close each FOR loop and it's BACK to the beginning to get another computername.

When passing data thru the pipe from one command to another, it's easier if you run each command from the command line, check it's output and then setup the parsing rules accordingly. Of course its also a good thing if you know what command produces what output.

Well, I'm sufficently dizzy. I sure hope DOS is not back to the future. But wait, Microsoft's new MSH/Monad is gonna make batch coders wish they never heard of batch language (think: batch language scripting on steroids).

How we can add the serialNumber of these devices also
1318.

Solve : How to Auto Run Keyboard Shortcuts at Windows Sartup after a pause?

Answer»

What .bat file command run at startup ACCOMPLISHES the following:

1. PAUSE 60 seconds to give time for a program to auto start at Windows Startup.
2. Run combo key command CTRL and ` pressed simultaneously.
3. Pause 5 seconds.
4. Run key combo key command CTRL and Enter pressed simultaneously.

Thank you.I started looking into this for you -  by the way I have limited knowledge of DOS + basic programming in various languages.

This command will pause for 60 seconds: timeout /t 60 /nobreak > NUL
I have tested it out and it works ok (the nobreak command prevents interruptions if a key gets pressed)

Then I started looking for the next part, combo key command CTRL and `
From what I have read, batch script cannot send KEYS to external windows, and there are reports that Microsoft removed SendKeys from Windows PowerShell in Windows 10.

Also, I didn't notice you had not said what those key commands were going to control - a program of some sort?

I THINK your best bet would be to use something like AutoIt - https://www.autoitscript.com/site/autoit

This can do what you require and more.

1319.

Solve : Need help trying to start old IBM computer running DOS?

Answer»

I'll keep it short: I have in IBM computer from the 90's running on DOS driver 2.77 with data I would like to access and ideally move to a current computer. When I turn it on, with the original hardware, I only GET "161" and "163" and a error picture telling me to check the manual, which says a dead battery on the motherboard (likely due to sitting in a garage since 2006). When I connect the HDD to current hardware (like 2010) via female IDE to male SATA adapter, I instead get stuck on the attached pic (cropped to be <700KB). I don't know what to try so any help would be appreciated.This probably isn't relevant, but the originally this is an IBM Personal System/2, model 35 SX.There is no attached picture so we can't see what you are encountering with the drive attached to another PC.  However, just to be SURE, you attached 2 cables to the drive, right?  One is the IDE ribbon cable and the other a power cable.  When everything is attached, can you hear the drive spinning?  Does it make any noise or have any VIBRATION?
Yes, all cables and ribbons are attached, and the drive is spinning. I had a picture attached when I clicked post, but the screen I'm stuck on is all text so:

HIMEN: DOS XMS Driver, Version 2.77 - 02/27/91
XMS Specification Version 2.0
Copyright 1988-1991 IBM Corp.

Installed A20 handler number 2.
64K High Memory Area is available.


IBM Expanded Memory Manager 386 Version 4.20.06X
(C) Copyright IBM Corporation 1986, 1991

_Replace the battery...part # Cr2032I think those PS/2 models used a Dallas Clock chip.

But more so than that, they require the IBM Reference diskette.

Quote

When I connect the HDD to current hardware (like 2010) via female IDE to male SATA adapter, I instead get stuck on the attached pic
I'm not quite sure I understand, but are you trying to *boot* from that drive on new hardware?

Typically you connect the drive you want data from to another PC as an additional drive, then you can copy or image the drive as desired from Windows or Linux.

I'd guess it is crashing because of how much memory the modern system has.

From the picture it looks like you are trying to boot from that disk, you don't want to boot from that disk.  You should boot from the normal C: drive and then the attached drive should show up in File Explorer as maybe the D: or E: drive (It might even appear as a different drive letter depending on how many drives the system has).  That way you can copy the data files you want from the attached drive to the C: (or wherever) drive in your current PC.   

Quote from: BC_Programmer on January 29, 2021, 06:16:44 PM
I think those PS/2 models used a Dallas Clock chip.

But more so than that, they require the IBM Reference diskette. ...

That's one reason why I haven't suggested he try booting from the ps/2 system itself.  ACCORDING to this website: https://www.ardent-tool.com/disks/disks.html, the model 35 requires a Starter Disk for setup as opposed to a Reference Disk (I'm not sure what the difference is).  The Starter Disk image can be downloaded from the site above but you will need a computer with a 3.5" floppy drive and image writing software like WinImage to create the Starter Disk.You probably know this already, but those pictures (approval must've been pending) is what I got when trying to boot from the drive. And when I connect it to another computer, the drive doesn't come up in "this pc" but it does in disk management. Disc 3, Unknown, Not Initialized. Would the data get wiped if I initialized the drive? Because similar to searching if it's safe to open a hard drive, some results say yes while others say no.Initialize is another word for format so, no, you don't want to initialize the disk.  Doing so will make it difficult to recover the data you are trying to save.So initializing/formatting is off the table, what are my options? It doesn't show up with my other drives in "this pc" but does in disk management and DEVICE manager.Hi

A couple of things
1. the drive is unlikely to auto detect, when the IBM system 35 was made you needed to get the drive geometry off the drive label  and then load the hd's, cdy's, Sectors into the cmos setup. There being 46 standard drive settings and a 47th where you could load the settings in manually. The setup disk did this for you.
What is the make and model of drive ?

2. As the drive is booting with the SATA to IDE adapter you should be able to access it if you get the correct parameters in the cmos.
The serial number is UL00075698, according to the bios. Probably not relevant, but there is a barcode 180 degrees opposite the power and data connections: B1 QG5 022654. The (hopefully) attached pic is of the top of the drive.
And on the back of the drive, I found:
IBM PN64F8560
MODEL DT531B-8I
1320.

Solve : set command escape character?

Answer»

I've got the contents of a batch variable and I'd like to change "~" to "&#7E;" (without the QUOTES). I THOUGHT this would work:

set J=blah~blah
set J=%J:~=^&#7E;%<br><br>but alas, it does not. <br><br>Thanks in advance for any insight you can provide.Thinking you might need to set variable as a string as the escape CHARACTER only escapes the first single character of <STRONG>&amp; </strong>and the rest is unexpected syntax. More at this link on the SET command.<br><br><a href="https://ss64.com/nt/set.html" class="bbc_link" target="_blank" rel="noopener noreferrer">https://ss64.com/nt/set.html</a>Thanks much.<br><br>The 8191 character limit for environment variables will likely bite me in the future, any experience with workarounds? I know of a DOS-based sed, and I "could" write a very small Java program...I prefer to keep it simple, and reduce dependancies (as if .bat files are "simple")<br><br>Thanks again.Curious if there is a need to use batch at all in what your trying to achieve? I have used system calls to DOS environment from within programs that aren't in the root of the system, so for example with C++ and PERL I have used system calls and these languages allow for far more than Batch Files themselves.  *System Calls from C++ etc, some see as poor programming practice though, but they work. They are ok for applications where you yourself are using them and others dont interact with them.<br><br>SED is GOOD, but I have used mostly PERL for making batched like scripts do what I want and without the limits of batch itself.The problem is the tilde.  If you read the help file for the SET command you will notice that the tilde and equals symbol both have special meanings.  The tilde is used for substrings and the equals symbol is used for string replacement.  You cannot escape the tilde or equals symbol in the SET command which means you cannot do string replacement on either symbol with the SET command.<br>

1321.

Solve : Finding the DOS "Short path"?

Answer»

I was originally looking to get a simple batch script to DISPLAY the DOS short-path via right-click context menu and perhaps I still am.
But I found some code via a search that LOOKED promising, but it would need to be compiled.....I think to make an actual .exe file.

Perhaps someone can compile this or tell me how to use it??!


Form1.cs
Code: [Select]using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace ToShortPath
{
    public partial class Form1 : Form
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public static extern int GetShortPathName(
                 [MarshalAs(UnmanagedType.LPTStr)]
                   string path,
                 [MarshalAs(UnmanagedType.LPTStr)]
                   StringBuilder shortPath,
                 int shortPathLength
                 );
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Show the dialog and get result.
            var openFileDialog1 = new OpenFileDialog();
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var openFileDialog1 = new FolderBrowserDialog();
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
                textBox1.Text = openFileDialog1.SelectedPath;
            }

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            StringBuilder shortPath = new StringBuilder(65000);
            GetShortPathName(textBox1.Text, shortPath, shortPath.Capacity);
            textBox2.Text = shortPath.ToString();
        }

    }
}

Form1.Designers.cs
Code: [Select]namespace ToShortPath
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(69, 13);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(516, 53);
            this.textBox1.TabIndex = 0;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            //
            // textBox2
            //
            this.textBox2.Location = new System.Drawing.Point(69, 72);
            this.textBox2.Multiline = true;
            this.textBox2.Name = "textBox2";
            this.textBox2.ReadOnly = true;
            this.textBox2.Size = new System.Drawing.Size(516, 53);
            this.textBox2.TabIndex = 1;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(7, 35);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Long Path";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(7, 95);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(57, 13);
            this.label2.TabIndex = 3;
            this.label2.Text = "Short Path";
            //
            // button1
            //
            this.button1.AutoSize = true;
            this.button1.Location = new System.Drawing.Point(591, 13);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(40, 53);
            this.button1.TabIndex = 4;
            this.button1.Text = "File";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // button2
            //
            this.button2.AutoSize = true;
            this.button2.Location = new System.Drawing.Point(637, 12);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(46, 53);
            this.button2.TabIndex = 5;
            this.button2.Text = "Folder";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(687, 135);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "Short Path";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
    }
}Hi 
Perhpas this can help you : How can I find the short path of a Windows directory/file?

Code: [Select]echo off
for %%i in (%*) do echo %%~si
pause
Save it as shortpath.bat , and then drag files on it

1322.

Solve : How to extract nth word from a list?

Answer»

I would like to extract the nthe word from a list.
As an example, if I have a list "one two three four" and would like to extract word 3, how would I do this in a batch?Hi 
Please be more explicit !
What's the delimiters of your list and where this is located on text file or from another command ??
The word is in a phrase with one line or with newline ?

The word is in a phrase with one line
Code: [Select]one two three four
Or with newline
Code: [Select]one
two
three
four

Can you provide us a real example and what code did you tried until now ?

Here is an example :
Code: [Select]echo off
Title Extarct word from list
set "Line=one two three four five"
set "Num=3"
SetLocal EnableDelayedExpansion
for /f "tokens=%Num%" %%i in ("%Line%") do set "word_%Num%=%%i"
echo The extracted word is = !word_%Num%!
pauseI think I over simplified my question.
Here is the script I have been working on with your addition now:

SETLOCAL EnableDelayedExpansion
set attribs=--a------
echo Attributes: %attribs%
FOR /L %%G IN (0,1,8) DO (
   set val=!attribs:~%%G,1!
   set num=%%G
   if not !val!==- (
   echo Attribute: Got here with !num!
   set line="DIRECTORY Read_Only Archived Hidden System_File Compressed_File Offline_File Temporary_File Reparse_point"
   for /f "tokens=%Num%" %%i in ("%Line%") do set "word_%Num%=%%i"
   echo The extracted word is = !word_%Num%!
        )
)

The "Got here with !num!" is correct as "Got here with 2".
Then the !word_%Num%! is a blank.
This of course is inside a loop and needs expansion but I am lost here since I had to use !num! first but if I use !num! with the token I receive an error.
How do I work around this?Just give a try for this modification
NB : I choose ; as delimters

Code: [Select]echo off
Title Extarct word from list
SetLocal EnableDelayedExpansion
set "attribs=--a------"
set "line=Directory;Read_Only;Archived;Hidden;System_File;Compressed_File;Offline_File;Temporary_File;Reparse_point"
echo Attributes: %attribs%

for /L %%G IN (0,1,8) DO (
set val=!attribs:~%%G,1!
if not "!val!"=="-" (
set "num=%%G"
)
)

echo Got here with %num%

for /f "tokens=%num% delims=;" %%i in ("%Line%") do (
set "word=%%i"
echo The extracted word is = !word!
)
Pause &AMP;  EXITThank you Hackoo.

Your code works but NEEDED to add:
set /A num+1
after set "num=%%G" to extract the correct word in the second for loop.

There is a problem though. I originally placed the 2nd loop inside the first to be able to display multiple words for files that exhibit multiple attributes (eg. Read only and System file [-r--s----]).
This code only displays the last attribute.I think I have it worked out now.
Rather than use a second loop after the first, call the second loop as a subroutine from inside the first loop as follows:

echo off
Title Extarct word from list
SetLocal EnableDelayedExpansion
set "attribs=-r--s----"
set "line=Directory;Read Only;Archived;Hidden;System File;Compressed File;Offline File;Temporary File;Reparse point"
echo Attributes: %attribs%

for /L %%G IN (0,1,8) DO (
   set val=!attribs:~%%G,1!
   if not "!val!"=="-" (
      set "num=%%G"
      set /A num+=1
      call :reit
   )
)
pause
exit

:reit
for /f "tokens=%num% delims=;" %%i in ("%Line%") do (
   set "word=%%i"
   echo The extracted word is = !word!
)
goto :eof
Pause &  EXIT

Just on the side, how do you insert code into the post as you have done Hackoo?
 Hi Frank 
I Just have one question :
How did you OBTAIN this format, i mean which command exactly can you get this ?
Code: [Select]-r--s---- Quote from: Frank on February 23, 2021, 04:20:53 PM

Just on the side, how do you insert code into the post as you have done Hackoo?
I'm glad that you have solved your issue !
Did you mean how to format code into [ code ][ /code ] ?
Just put your entire code between [ code ][ /code ] (Just trim the extra spaces between brackets) or select all your code and hit the button # for code !
And if you want to thanks someone , you have just a little link Thank member name  Hi Hackoo,
The format for the file attributes (-r--s----) I obtained while searching the internet here:

https://stackoverflow.com/questions/9252980/how-to-split-the-filename-from-a-full-path-in-batch

See the code extract:
Code: [Select]set "filename=C:\Folder1\Folder2\File.ext"
For %%A in ("%filename%") do (
    echo full path: %%~fA
    echo drive: %%~dA
    echo path: %%~pA
    echo file name only: %%~nA
    echo extension only: %%~xA
    echo expanded path with short names: %%~sA
    echo attributes: %%~AA
    echo date and time: %%~tA
    echo size: %%~zA
    echo drive + path: %%~dpA
    echo name.ext: %%~nxA
    echo full path + short name: %%~fsA)
Note the line 'echo attributes: %%~aA
I have now noted the link 'Thank member'.
Thank you for your patience.
1323.

Solve : How to create folders based on "PARTS" of file names and put them in there.?

Answer»

So, i'm not a computer engineer. just a regular man without knowledge in computer. I downloaded a torrent full of comic books, around 5000 of them, my problem is that, want to segregate them by author. the author was included in the file NAME with braket enclosure ( e.g. [Asamine Tel] ) but it takes too much time to make folders myself and move them all to those folders.

here are some examples of the file names:
[Aramaki Echizen] Active ❤ Passive
[Araiguma] Loss of Innocence (COMIC #70)
[Asamine Tel] Twin Healing
 
i tried searching for solutions online and i saw someone use batch files.. But i'm not knowledgeable in computer field. can someone help me please?Hi, my dad had a similar problem to yours, he too is not computer savvy.
He would get several episodes of different series, and want to put them in individual series folders, but he was not very good with cut & paste.
I looked around for a solution for quite a while until I came across this program, which is truly brilliant at automatically sorting files once you set up some associations - sounds harder than it is, the interface is very USER friendly.

The program is called DropIt, it is open source and completely free, and has a portable version as well so you don't need to install it.

The main page for it is here - http://www.dropitproject.com

I have attached 3 pictures: Making an association for[Aramaki Echizen]; Dropping a file onto the drop target; The progress complete window.
I don't know if your files are .pdf, .epub, or something else so I used .pdf as an example.

To move any file with[Aramaki Echizen] in the file name, you need to use the star * symbol in the rule.
The * means any amount or type of letters or symbols before (or after, DEPENDING where the * is) that point.
So the name [Aramaki Echizen] could APPEAR anywhere in the file name - at the beginning, part way along or at the end.
Because you have used the * character in the rule, it basically ignores everything else apart from the [Aramaki Echizen] text.
The program then identifies the file as being "that author" and moves it to the folder you chose in the association.

Have a quick read of this page:
http://www.dropitproject.com/dokuwiki/doku.php?id=howto:start_with_dropit

If you want some help setting up the associations, reply here and I will help you along.Thanks for responding my guy. I just have one question. Will this process create its own folder automatically or just transfer the files to the folder with some parts of it's name but you need to make the folder yourself?Sorry for delay replying, was away from PC.

I read through the examples on how to move files and create directories, tried 5 or 6 variations, but the solution was the most obvious one, just put the name you want at the end of the path and it will make the folder for you.

Have attached pic

I tested it out: on the first run it had to make the folder and then move the file =ok
I then manually put the file back where it was, but I did not delete the folder it just made
Ran it again, the file was moved into the folder with no fuss =ok

So now, to add the the associations for the other authors, in the Manage Associations window you can right click on the first one in the LIST, and click on Duplicate. Double click on it to edit it, now copy and paste the next authors name into boxes 1,2 and 4, then click Save.

I like to keep any utilities like this visible in the system tray - right click on the taskbar, click Taskbar settings, click Select which icons appear on the taskbar, make sure DropIt is turned on.
i appreciate the help, but i think it's not quite the one im looking for. since in this app, you'll be manually putting the name of the folder. what i'm looking for is the one that automatically create a folder, and also name it automatically according to the parts of the name of the file, then put all those files inside the folder. i got 500 authors here so i will need to do your process 500 times, which is still inconvenient. I found a program called File Juggler, I have uploaded a video to YouTube on how I used it:
https://www.youtube.com/watch?v=OVTWxVaStyU

File Juggler has a feature in it where you can use a list that can be compared against file names, and then do actions on them.
it's a 30 day demo, but on their website it says "After 30 days become a little annoying and start telling you that you should buy it, if you want to keep using it. But it won't stop working at any point, and is not limited in features.

Here is a link to download the small utility called Directory List & Print that I used at the start of the video:
https://drive.google.com/file/d/1gAl4yJ8Rz-Wb8H2G90cgljTfTWwax1zY/view?usp=sharing
Roughly something like this.
Untested
Code: [Select]echo off
FOR %%G IN (*.tor) DO (
FOR /F "TOKENS=1 delims=[]" %%H IN ("%%G") DO (
MD "%%H"
move "%%G" "%%H\"
)
)

1324.

Solve : *.BAT script needed please help me.?

Answer»

ok HERES my script.

ping ls890.hostcentris.com -n 1

IF Ping request COULD not find host ls890.hostcentris.com. Please check the name and try again

"ECHO The server is currently offline"

"IF Pinging ls890.hostcentris.com [65.254.51.138] with 32 bit of data:"

"ECHO The Server is currently online"
"Pause"

What I want it to do is to: Ping that URL and if the host is unreachable then I want it to say "the server is currently offline" and if it starts to ping I want it to say "the server is currently online"

when it gets executed in WINDOWS XP it auto closes the bat file and I want it to stay open for at least 30sec.

can anybody help me please?

Thanks in advance.  That is easy! You have to open the file in the command prompt, not DOUBLE click it. (Don't use the Start command to open it.)

1325.

Solve : Fullscreen Batch files?

Answer»

How do i start a batch file in fullscreen MODE? Please help!!!  Right click on it and SELECT properties. Click the screen tab. Select full screen. Click apply. Click OK.There is no Screen tab (this is a batch file)Not in 2k or XP - unless you know how. All VERSIONS of 9x have a screen tab.I use a Win2k system... thats the problem. I don't have a screen tab for batch filesAnother Microsoft inovation. It is in the manual under
Z. Unpublished appendix
    1. Removed options
         a. No screen tab in DOS properties dialog BOX
              1. We don't want people to use DOS but they keep finding ways around it.

Do you need or want the option, or just want to know how to get it? I had that problem on a 2k pro machine but needed it for other people who use a special purpose batch file that I wrote originally for W9x. With MS, you sometimes have to go through the back door to catch BILLY Bob Gates with his pants down.Right-click on the minimized Command Prompt and choose properties, then choose Full Screen under Options. I want the batch file to be fullscreen when they start

1326.

Solve : Batch file to find a word on my drive?

Answer»

Hi Guys,
I don’t know if this is possible.

I would like a batch file that when clicked would prompt for a drive letter then prompt for the word to search for, if the word is found, list all files on that drive that contain that word.

The word or part of the word could be in  txt, DOC, xls, xlsm, csv, eml or pdf, infact any file that I can view.

Thanks
Keith
Hi 
Just give a try for this old batch script  Local_Search_Engine.bat

Code: [Select]ECHO OFF
REM This Script is written by (c) Hackoo 2016 on 19/09/2016
Title Scan a folder and Search a string in multi-files by (c) Hackoo 2016
mode con cols=75 lines=2
Call :init
rem Call :CountingExecution
Call :inputbox "Please enter something to search :" "Search a string in multi-files by (c) Hackoo 2016"
If  "%input%" == ""  Color 0C & (
echo(
echo           You must enter a string to continue with this program
pause>nul & exit
) else (
Call :Browse4Folder "Choose source folder to scan for %input%" "c:\scripts"
)
::******************************************************************************************
Set "ROOT=%Location%"
::Does string have a trailing back slash ? if YES, so, we remove it !
IF %ROOT:~-1%==\ SET ROOT=%ROOT:~0,-1%
:: txt vbs js JSON hta php htm html xml csv rtf
SET "EXT=txt vbs js json hta php htm html xml csv rtf"
SET "COUNT=0"
set "Word2Search=%input%"
Set "NewFolder2Copy=%userprofile%\Desktop\CopyFiles_%Word2Search%"
Set "LogFile=%~dp0%~n0_%Word2Search%.txt"
SETLOCAL enabledelayedexpansion
REM Iterates throw the files on this current folder and its subfolders.
REM And Populate the array with existent files in this folder and its subfolders
For %%a in (%EXT%) Do (
Call :Scanning "%Word2Search%" "*.%%a"
Call :PS_Sub 'information' 10 '"Scanning now for """%Word2Search%""" on """*.%%a""" . . . "' "'Please wait. . . Scan is in progress on all """*.%%a""" . . .'" 'info' 5
FOR /f "delims=" %%f IN ('dir /b /s "%ROOT%\*.%%a"') DO (
( find /I "%Word2Search%" "%%f" >nul 2>&1 ) && (
SET /a "Count+=1"
set "list[!Count!]=%%~nxf"
set "listpath[!Count!]=%%~dpFf"
)
) || (
( Call :Scanning "%Word2Search%" "%%~nxf" )
)
)
::*******************************************************************
:Display_Results
cls & color 0B
echo wscript.echo Len("%ROOT%"^) + 20 >"%tmp%\length.vbs"
for /f %%a in ('Cscript /nologo "%tmp%\length.vbs"') do ( set "cols=%%a")
If %cols% LSS 50 set /a cols=%cols% + 24
rem If %cols% LSS 50 set /a cols=%cols% + 15
set /a lines=%Count% + 17
Mode con cols=%cols% lines=%lines%
echo(
Call :color 0A " ------------------------------------------------" 1
ECHO   Folder : "%ROOT%"
Call :color 0A " ------------------------------------------------" 1
rem If Exist "%LogFile%" Del "%LogFile%"
rem Display array elements
for /L %%i in (1,1,%Count%) do (
set "msg=[%%i] - !list[%%i]!"
echo !msg!
)
ECHO(
ECHO Total of [%EXT%] files(s) that contains
Echo the string "%Word2Search%" is : %Count% file(s)
echo.
Call :color 0D "Type the number of file that you want to explore" 1
echo(
Call :color 0C "To save results into a LogFile just type 'LOG'" 1
echo(
Call :color 0A "To copy all files found just type 'Copy'" 1
set /p "Input="
For /L %%i in (1,1,%Count%) Do (
    If "%INPUT%" EQU "%%i" (
        Call :Explorer "!listpath[%%i]!"
    )
IF /I "%INPUT%"=="Log" (
Call :Save_Results
)
IF /I "%INPUT%"=="Copy" (
Call :CopyFiles
)
)   
Goto:Display_Results
::****************************************************************************
:Save_Results
If Exist "%LogFile%" Del "%LogFile%"
rem Display array elements and save results into the LogFile
(
Echo   ------------------------------------------------
ECHO   Folder : "%ROOT%"
echo   ------------------------------------------------
)>"%LogFile%"

for /L %%i in (1,1,%Count%) do (
set "msg=[%%i] - !list[%%i]!"
echo !msg! -- "!listpath[%%i]!" >> "%LogFile%"
)

(
ECHO.
ECHO Total of [%EXT%] files(s^) : %Count% file(s^) that contains the string "%Word2Search%"
)>> "%LogFile%"
Start "" "%LogFile%"
Goto:Display_Results
::****************************************************************************
:Scanning <Word> <file>
mode con cols=75 lines=3
Cls & Color 0A
echo(
echo      Scanning for the string "%~1" on "%~2" ...
goto :eof
::****************************************************************************
:Explorer <file>
explorer.exe /E,/select,"%~1"
Goto :EOF
::****************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::****************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
    <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
    echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::***************************************************************************
:Browse4Folder
set Location=
set vbs="%temp%\_.vbs"
set cmd="%temp%\_.cmd"
for %%f in (%vbs% %cmd%) do if exist %%f del %%f
for %%g in ("vbs cmd") do if defined %%g set %%g=
(
    echo set shell=WScript.CreateObject("Shell.Application"^)
    echo set f=shell.BrowseForFolder(0,"%~1",0,"%~2"^)
    echo if typename(f^)="Nothing" Then 
    echo wscript.echo "set Location=Dialog Cancelled"
    echo WScript.Quit(1^)
    echo end if
    echo set fs=f.Items(^):set fi=fs.Item(^)
    echo p=fi.Path:wscript.echo "set Location=" ^& p
)>%vbs%
cscript //nologo %vbs% > %cmd%
for /f "delims=" %%a in (%cmd%) do %%a
for %%f in (%vbs% %cmd%) do if exist %%f del /f /q %%f
for %%g in ("vbs cmd") do if defined %%g set %%g=
goto :eof
::***************************************************************************
:CountingExecution
Setlocal enabledelayedexpansion
Title Count the number of times my BATCH file is run
Mode Con Cols=60 lines=5 & color 0E
set /a count=1
set "FileCount=%tmp%\%~n0.txt"
If Not exist "%FileCount%" (
echo !count! > "%FileCount%"
) else (
For /F "tokens=*" %%a in ('Type "%FileCount%"') Do (
set /a count=!count! + %%a
echo !count! > "%FileCount%"
)
)
echo.
echo This batch script is running for "!count! time(s)"
echo(
Call :Color 0C "           - - - Hit any key to continue - - -" 1
EndLocal
pause>nul
::***************************************************************************
:InputBox
set "input="
set "heading=%~2"
set "message=%~1"
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do (
set "input=%%a"
)
exit /b
::***************************************************************************
:PS_Sub $notifyicon $time $title $text $icon $Timeout
PowerShell  ^
  [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
 [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
 $notify = new-object system.windows.forms.notifyicon; ^
  $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  $notify.visible = $true; ^
  $notify.showballoontip(%2,%3,%4,%5); ^
  Start-Sleep -s %6; ^
  $notify.Dispose()
%End PowerShell%
exit /B
::****************************************************************************
:MakeCopy <Source> <Target>
If Not Exist "%~2\" MD "%~2\"
Copy /Y "%~1" "%~2\"
goto :eof
::****************************************************************************
:CopyFiles
cls
mode con cols=80 lines=20
for /L %%i in (1,1,%Count%) do (
echo Copying "!list[%%i]!" "%NewFolder2Copy%\"
Call :MakeCopy "!listpath[%%i]!" "%NewFolder2Copy%">nul 2>&1
)
Call :Explorer "%NewFolder2Copy%\"
Goto:Display_Results
::*****************************************************************************Thanks for you input.

I tried you file on my S drive for a word I know is in multiple xlsm files,  multiple Word documents and  multiple txt files, but it only returned 1 hit from a csv file. Yes! with a batch file you can only scan those type of files: txt vbs js json hta php htm html xml csv rtf
xls ; xlsx and pdf are like exe, you can not search on itOk Hackoo thanky you for your time and input.

1327.

Solve : REMOVING n' CHARACTERS FROM THE END OF A DOS FILE?

Answer»

Hi... I am trying to find a way to remove 'n' characters fro ALL files in a DOS directory. I found this on the web but it doesn't work.
I am not overly familiar with DOS and CMDS so any HELP will be greatly appreciated..  MANY thanks

tried:echo off
        setlocal enabledelayedexpansion
        set FOLDER_PATH="D:\Some DOS CMDS\NEW FOLDER"
        for %%f in (%FOLDER_PATH%*) do if %%f neq %~nx0 (
            set "filename=%%~nf"
            ren "%%f" "!filename:~0,-26!%%~xf"
)
PAUSESometimes I can be a bit slow on the uptake, but why ELIMINATE characters from file NAMES on a mass scale? While you ponder that, this little piece of doggerel may just help.

Code: [Select]echo off
setlocal enabledelayedexpansion
set folder=c:\temp

for /f %%f in ('dir /b /a-d %folder%') do (
  set input=%%f
  set output=!input:n=!
  ren %folder%\!input! !output!
)

pause

Be sure to change the folder name in the third line.

Happy Coding 

1328.

Solve : to get the PID from a process?

Answer»

I would like to start a PROCESS and capture the PID from this process, USING a batch file.
How can I do it?Do U mean a log of when the process is STARTED and ended?

1329.

Solve : Batch File - Ctrl+Break/Ctrl+C?

Answer»

I would like to ask, if there's a WAY to disable CTRL+Break or Ctrl+C while running autoexec.bat?
THANKS for your help.  what does that do?Break SCANNING allows INTERRUPTING a batch file with hex 03 (Ctrl C or Ctrl Pause).

break=off in the batch file is supposed to disable the scanning for hex 03. break=on reactivates it.

1330.

Solve : using one batch file as a command in another?

Answer»

I've only just started using batch files and I think I've gotten a little to tricky for myself.

I created a batch file in which to dump the filenames  after a replace command so that the file looks like this:

replacing G:\filename1
replacing G:\filename2

etc...

I then created a new batch batch file to move the newly replaced files to another directory for a short TIME:

move %1 G:\directory1\

I named this second batch file "replacing.bat" so that when I ran the first one, it saw "replacing" as a command and the file as the variable.

Now to my delight, this worked perfectly for the first file, but to my disappointment, the first file is all that it did.

It seems that after running the replacing command the first time, control is not returned back to the first batch file so that the second line can be run.

Does anybody know why this would happen and how I can fix it?

THANKS in advance,
Jono

Use the command CALL before each nested batch file, so it opens in its own command shell before it executes, then returns to the controlling file.

Or you can make the routines you want to use subroutines in the main batch files and use GOTO or GOSUB and RETURN or an if-then or for-in-do to run it. This latter is a bit more stable than CALL but requires that you do some actual programming.  I need to call a couple of batch files from within the one file.  The first one starts JBoss which doesn't actually "end".  My problem is that even when I use the CALL command to call the batch file to start JBoss, it starts in the same window and hence never reaches the rest of the initialising batch file.  I'm completely flumoxxed (sp?) here.  Any help would be appreciated.      Please email me if you have any IDEAS at [email protected]

Thanks
KimNesting batch files has always been a problem since Windows started. The batch processor has always been a single-thread function. CALL runs a second batch file in a SEPARATE COMMAND.COM shell, but doesn't return control to the first until the second file exits.

Using a subroutine will show similar behaviour. GOSUB to a section with a copy of JBOSS content will still hang the instruction pointer in the subroutine until the JBOSS file continues and reaches the RETURN statement.

Best option here is either to do all the setup before running JBOSS as a subroutine, or to do a setup batch file, then hand off to JBOSS, which itself has a handoff to a cleanup routine. (A handoff is simply making the last line of a batch file another batch file.)

You MAY also get better results by replacing COMMAND.COM with JP Software's 4DOS command shell.

1331.

Solve : How to from Windows7 start a Dos file to run a Lotus123 spreadsheet program.?

Answer»

I am using Windows7 in 32 bits.

At present I would shut down windows and restart at command.com, then run my Dos file of c:\autoexec.bat.

This autoexec.bat will open the spreadsheet in Dos of Lotus123, for me to retrieve my spreadsheet file and work on it.

How do I start from windows as to get the whole procedure above started, that should save me labor with FIRST shutting down windows etc etc etc.


Try simply opening a Command prompt while still in Windows and type in your bat and hit Enter...
Create a shortcut on the Windows desktop that points to the batch file.  Then you would be able to double-click on the shortcut from the desktop and have it run. This is what I am doing to get Windows 7 (in 32 bits) to work like the DOS OPERATING system for RUNNING the old old Lotus123 spreadsheet program.

1. Reboot Windows by clicking on a reboot shortcut

2. When shut down has completed, press F8

3. F8 brings up a LIST of choices

4. Click ↓ ↓ ↓ down arrow three times

5. That brings cursor to Safe Mode with Command Prompt line

6. I press enter on this line and this prompt appears, C:\Windows\system32&GT;

7. Now I annex to this prompt my old dos batch file, autoexec.bat, thus C:\Windows\system32>c:\autoexec

8. That brings up my old old Dos Lotus123 spreadsheet program.

 If only I can produce the procedure as described above, with one click on a shortcut file in Windows, that should be terrific!

1332.

Solve : Move files based on Date?

Answer»

Hello all,

For archiving purposes i need to move files > 1month old.

I read all topics but this seems hard to perform in DOS, can anyone help me out?

Thx,
J.J.J.J. why do you have to do it in DOS ?

dl65  Hello dl65,

I need the script to run on WIN2K. The script will be executed by a WMS scheduler.
Why in DOS: Basicly all additional scripting (ftp, file moves, sql kickoffs, ..) is currently DONE in DOS and i like to keep it that way for the near future.

I tried but my DOS knowledge is nothing more than the basics so the 'date selection' is too much for me.

J.J.I am also in this same boat.  I need to write a batch file that will be run by WINDOWS Scheduled Task.  I need the batch file to look at a DIRECTORY and move files that are older than the current date - 3, or 72 hours.  Can this be done in DOS?  Thanks!!

1333.

Solve : Script To Map Network Drives?

Answer»

Hi All,

I am trying to write a dos script that will prompt a User for a server name, then prompt for a Share name. It will then use these INPUTS WITHIN a NET use etc command to map a DRIVE to that share.

Any help appreciated.

Many TIA

Leei think U should use ddeshare

1334.

Solve : Formatting batch file?

Answer»

I'm trying to make a batch file that will format the c: drive instantly, without prompting the user.  I tried:
Format c: /y /u
However it will not work since the c: drive is currently being used.  Is there any other way to do this?  Thanks.!!!caution n00bs!!!!

format /autotest

format /backup will prompt you for a volume labelyou can also add the /X to your command.

see results of format /? > format.txt

Formats a disk for use with Windows XP.

FORMAT volume [/FS:file-system] [/V:label] [/Q] [/A:size] [/C] [/X]
FORMAT volume [/V:label] [/Q] [/F:size]
FORMAT volume [/V:label] [/Q] [/T:tracks /N:sectors]
FORMAT volume [/V:label] [/Q]
FORMAT volume [/Q]

 volume          Specifies the drive letter (followed by a colon),
                 mount point, or volume name.
 /FS:filesystem  Specifies the type of the file system (FAT, FAT32, or NTFS).
 /V:label        Specifies the volume label.
 /Q              PERFORMS a quick format.
 /C              NTFS only: Files CREATED on the new volume will be compressed
                 by default.
 /X              Forces the volume to dismount first if necessary.  All opened
                 handles to the volume WOULD no longer be valid.
 /A:size         Overrides the default allocation unit size. Default settings
                 are strongly recommended for general use.
                 NTFS supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K.
                 FAT supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
                 (128K, 256K for sector size > 512 bytes).
                 FAT32 supports 512, 1024, 2048, 4096, 8192, 16K, 32K, 64K,
                 (128K, 256K for sector size > 512 bytes).

                 Note that the FAT and FAT32 files systems impose the
                 following restrictions on the number of clusters on a volume:

                 FAT: Number of clusters <= 65526
                 FAT32: 65526 < Number of clusters < 4177918

                 Format will immediately stop PROCESSING if it decides that
                 the above requirements cannot be met using the specified
                 cluster size.

                 NTFS compression is not SUPPORTED for allocation unit sizes
                 above 4096.

 /F:size         Specifies the size of the floppy disk to format (1.44)
 /T:tracks       Specifies the number of tracks per disk side.
 /N:sectors      Specifies the number of sectors per track.

1335.

Solve : Boot problem... plz hlp?

Answer»

I'm having problem whit my computer I cant start it. It worked just fine before just a little slow so I thought It needs to be rebooted so I did that but now i will not start... I come as far as to the Win XP loading screen then I get a blue screen for about 0.001 sec and then i reboot itself...  

I cant formate it either...   When i try I get a massage "cant load command.com"  why?? why?? plz HELP...

                                                                  //RunNerBoot from the XP CD (go into BIOS and set the CD as FIRST boot device, put your XP system CD in the drive, and reboot) and re-install XP with 'repair' option to fix corrupted files.Yeah, but first THINK about this...
Do you have backups of your files somewhere?

1336.

Solve : Batch files in win2K?

Answer»

How do I use the set command to cause a batch FILE to pause for a given time (10 seconds) and then TERMINATE automatically? Do I need to create a PIF to do this? If so, how?

The batch I use in w98 has the lines:

echo Window will close in 10 seconds
TYPE NUL | CHOICE.COM /N /CY /TY,10 >NUL

In the PIF properties it is set to close on exit. The window stays on screen for 10 seconds and CLOSES. HELP will be greatly appreciated.I solved my own problem. Thanks for the "expert" help (not).It probably meant that during the 10 seconds, u could still exit the program by clicking on the X in the corner.Thats true. You can do that, but that was not the desired function. The ten second pause was to allow the user the read the on screen message and then close the DOS box automatically. No user interaction required nor desired other than a double click  on the shortcut to batch file.I don't think u can use a PIF for batch files, only for .com files. That's why I cant make my batch file fullscreen.

1337.

Solve : SHELL=in config.sys->File Creation Error @ boot?

Answer»

In Windows 98, I've added  

SHELL=C"\command.com /E:1024

to Config.sys.

When I  boot to Windows 98 , the splash screen appears very briefly, the boot process stops at the
C:> prompt, and File Creation Error" is displayed.

IF I remove the SHELL= LINE from config.sys, the error goes away.


If I boot straight to DOS (via F8), this doesn't happen.

What is causing this ?

I need to EXPAND my environmentThe SHELL= should only be used if you intend to use a command interpreter other than command.com. When you boot to windows, W98 looks to the copy of command.com located in C:\windows. An old DOS method to expand the environment is to use the SET command in config.sys or autoexec.bat. I haven't used it with windows because I have had no need, but there is no reason that it shouldn't work.

SET COMSPEC = C:\WINDOWS\COMMAND.COM /E:1024

If you are running a DOS program from inside a windows DOS BOX, create a shortcut to it and you can set any memory requirements from the properties dialog box under the memory tab, including the initial environment space. Most of the time these settings are best LEFT set to AUTO.

1338.

Solve : open/Close com ports?

Answer»

New User,Thanks for reading this;
I'm trying to setup a bat FILE to open com2 4800b 8n2
and SEND 2 commands to my radio.But Ive forgotten how
to "OPEN" port,or maybe the command "OPEN" is usable
?  Any HELP appreciated.

Nick A.mode com2:48,8,n,2,b should be the command you're looking for, I think... Then you can COPY a file to the port containing your commands.

Find a full copy of DOS 6.22 and copy the QBASIC*.* and HELP*.* files to your Win9x c:\windows\command directory, and you'll have a nice reference to DOS commands, most of which WORK the same between DOS 6.22 and DOS 7.

1339.

Solve : Delete specified multiple lines of a not in use batch file through another batch?

Answer»

For example let's SAY i have the following program:

Code: [Select]echo off

start notepad.exe "C:\Users\Giovanni\Desktop\New folder\file1.txt"
echo FILE was opened

:flag
start notepad.exe "C:\Users\Giovanni\Desktop\New folder\file1.txt"
echo file was opened
And i want to delete only the first Code: [Select]start notepad.exe "C:\Users\Giovanni\Desktop\New folder\file1.txt" and Code: [Select]echo file was opened


How can i do that?? i'm a COMPLETE NEWBIE so go EASY on me.

1340.

Solve : Read text file and save to a variable?

Answer»

Hi All,

I'm new to batch and I want to automate my NUnit Script to be dynamic. I'll explain this in a basic question.

My text file contains

     test1
     test2
     test3

I want to read those multiple LINES and save it into a variable. Here's my current script

for /f "delims=" %%x in (test.txt) do set params=%%x

Though I'm only getting the last line which is test3. I want this OUTPUT:

test1 test2 test3


Code: [Select]echo off
setlocal enabledelayedexpansion
set "params="
For /f "delims=" %%x in (test.txt) do set "params=!params!%%x "
Squashman wow you woke up hungry....

How ya been ? Quote from: patio on March 27, 2021, 05:45:28 AM

Squashman wow you woke up hungry....

How ya been ?
PRETTY Good.  Staying Safe. I doubt any of the original users will come back to all the questions I answered but at LEAST they have an answer for posterity's sake.
1341.

Solve : Can i create a batch that ends at a specific date which means it will be a trial?

Answer»

I want to create a bat file that will end at a specific date
The first idea I found is to store the current date inside the variable.
And store the expiration date inside another variable.
Then compare between the two dates and if they are equal it will display a Message then will exit from the batch.
but it didn't work.
Appreciate any helpI think this question can be found here : How to set an expiration date on a batch file?

Try this. Example dates are used in the IF conditions in a format YYYYMMDD (you can set your own values) :
For the new YEAR 2021 this batch dos not work any more 

Code: [Select]echo off
Title EXPIRATION DATE WITH BATCH
for /f "tokens=* delims=" %%a in ('wmic OS get LocalDateTime /value') do for /f "tokens=* delims=" %%# in ("%%a") do set "%%#"
set "LocalDateTime=%LocalDateTime:~0,8%"
REM echo %LocalDateTime%
:: EXPIRATION DATE ::
set "EXP_DATE=20201231"
:::::::::::::::::::::

if %LocalDateTime% GTR %EXP_DATE% (
color 0C
echo this wont work anymore
Timeout /t 5 /NoBreak >NUL
exit /b
)

START "" "Chrome"
Exit
Happy New Year 2021  Thanks, Hackoo

You ALWAYS help me better .
Just a FYI... anyone who knows how to open the batch file in notepad etc can extend the date that it expires or remove the expiration completely! Only way around this would be to compile it to protect it from editing. There was a Batch to EXE compiler years ago, but I haven't messed with that in ages to say how strong it is to protecting contents from view or alteration when in EXE form. Quote from: DaveLembke on January 03, 2021, 02:21:36 PM

Just a FYI... anyone who knows how to open the batch file in notepad etc can extend the date that it expires or remove the expiration completely! Only way around this would be to compile it to protect it from editing. There was a Batch to EXE compiler years ago, but I haven't messed with that in ages to say how strong it is to protecting contents from view or alteration when in EXE form.

Thanks, DaveLembke

I already found some programs to compile my batch from any manipulate content
but also thanks for your reminderI highly recommend using Dave Benham's Obfuscate Batch instead of the Bat to Exe files that really don't hide anything. Quote from: Squashman on March 30, 2021, 09:30:10 AM
I highly recommend using Dave Benham's Obfuscate Batch instead of the Bat to Exe files that really don't hide anything.


Thanks, Squashman for your ASSISTANCE and What is the difference between Dave Benham's Obfuscate Batch and the normal converter? Or Do you mean that we can use this batch as an intermediate step between my bat file and the conversion step? Quote from: Abo-Zead on April 11, 2021, 06:05:01 PM

Thanks, Squashman for your assistance and What is the difference between Dave Benham's Obfuscate Batch and the normal converter? Or Do you mean that we can use this batch as an intermediate step between my bat file and the conversion step?
Bat to EXE converters are not compiled.  They are a self extracting executable.  It extracts the contents of the program to a temporary folder and then executes the batch file. Not hard to find for any remotely computer savvy person.

Dave's Obfuscation code keeps the bat file as a bat file but in a pseudo encrypted format.  While it is possible to decrypt the bat file it will take a bit of thinking or brute force to do so.  Dave and I had a discussion about keeping the encryption key separate from the batch file itself and we did a proof of concept on that as well.  Sort of like need for the private key of a pgp pair.  If you don't have the decryption code you would have even a more difficult time decrypting the batch file.
1342.

Solve : How to find file in Zip files... Help please?

Answer»

Hi could nned some help here, please....

I wonder if it is possible to search for specific files on a drive which are included in a zip file.

So fare I try to find the files with the Dir command but cannot find files in ZIPS

Is there a WAY??

Thank you for your helpWell, the only way is to unpackage the files first and then search for them.  With Windows, a tool like WinZip, PowerArchiver, or (in XP) the enhanced CABINET viewer, will open ZIPs and LET you examine and EXTRACT the content files.

In DOS, you use PKZIP to unpack the ZIP to a directory, then view it with DIR or a filebrowser.

1343.

Solve : Isn't it good to have DOS??

Answer»

Who likes DOS? I love DOS, because it is so easy to use.Some of the low level STUFF I like to customise would be harder WITHOUT DOS. Thus I stick with Win98SE vice UPPING to XP or NT.

COUNTRY= (in Config.Sys) is great!

1344.

Solve : How do I use Edlin??

Answer»

How do I use Edlin?  EDLIN /? will get you the list of commands. Searching for the term will get you ASSORTED references to its use.

It's a sort of VI THING... heh. It's a rudimentary text edittor intended to use with DEBUG to produce MINIMAL assembly code and compiled programs. For an easier tool, try ELVIS (VI for the PC), it's more USEFUL. For best results, get a decent text edittor (like NOTEPAD or E88) that doesn't rely on arcane commands to just edit text... or is at least self-documenting.

1345.

Solve : *.com files?

Answer»

How do I create a .com file? I don't want to CONVERT a .bat file to .com, i want to create a .com file itself.With knowledge of hex code and a hex edittor. Or you can use an ASSEMBLY LANGUAGE TOOL or EDLIN and DEBUG to compile assembly code to EXE or COM.

1346.

Solve : freeing up space?

Answer»

not sure if this is ok to do in this area but i have a problem. im in dos and am trying to free up space to download windows 95 but because i only have a prompt on screen i am not sure how to do it. can anyone help? thank you in advanceTo free up space in DOS... Copy stuff you want to some convenient storage MEDIA (CDRW drive, tape drive, floppy...) before deleting it. Put the line set dircmd=/a /p in AUTOEXEC.BAT so your dir command shows all files and displays them a page at a time, and use ATTRIB command to clear Readonly, SYSTEM, and Hidden bits from superfluous files (like in the %temp% directory) before deleting them. Check the %temp% directory (should be c:\temp or c:\windows\temp, but some setups ACTUALLY use the c:\dos directory...) and delete all TMP files. Empty any 'delete catcher' or 'recycle bin' directories.

Downloading Win95? If you're trying to get a pirate copy of an OS, give it up and get Linux...THANK YOU MALIKTOUS FOR YOUR QUIICK REPLY, BUT I AM SO STUPID WHEN IT COMES TO COMPUTERS. AND AM STILL HAVING THE PROBLEM. I DIDNT MAKE A BACK UP CAUSE THERE ISNT ANYTHING IN THERE NEED. OK ON C: I PUT IN ATTRIB ANDIT SHOWS STUFF LIKE SETUPLOG.TXT THEN NEXT TO IT IT SAYS C:\SETUPLOG.TEXT BUT IF I PUT THAT IN THE C PROMP SPACE IT SAYS BAD COMMAND. SO THERE I AM, IM SURE YOUR THINKING OH GOODNESS WHAT A DIP BUT IM REALLY NOT. JUST KIND OF PUTER ILLITERATE.  AND NO IM NOT GETTING A PIRATE COPY, I BOUGHT THE DISC FROM A COMPUTER STORE.   THANKS AGAIN FOR YOUR HELP.Please fix the sticky shift key or disable the caps lock, that's just annoying...

What size hard drive is this? If you have a HD over 2 GB, you should have Win95 OSR2 or later, and use the option for 'Large' hard DRIVES when you repartition so you get FAT32 partitions.

You use attrib like this:
attrib -r -h -s setuplog.txt

Then you can use
type setuplog.txt /p

to view the file, or you can delete it, or whatever else you want to do with it. DIR /a just lets you see all the files regardless of whether they are hidden or system flagged.

Entering a command like
attrib /?
will cause it to display a set of instructions. If you have a copy of DOS 6.22 with the QBASIC and HELP files, you have a better reference than the '/?' option.

1347.

Solve : Batch conversion issue?

Answer»

Hi all,
I have a Batch file to ping for all hostnames inside my domain by brings these hostnames from an external text file (hosts.txt) and it works properly while using it as a bat file, but after converting this file to an executable file (exe) and try to use it, its display an error message contain that (The system cannot find the file "hosts.txt" )
why does this happen? And how can fix this issue?
Here is the mentioned code:

Code: [Select]echo off
title Ping Batch using "External Text File"
setlocal enableextensions enabledelayedexpansion
color 0a
Rem mode 125,35
mode con:cols=105 lines=30
TIMEOUT /T 1 /NOBREAK >nul
ECHO. ====================================================================================================== && ping -n 1 localhost >nul
ECHO. ^|^| ------====^<({ Welcome to AMIN Muhammad Batches })^>====------ ^| ---===^<({ Created By :- })^>===--- ^|^| && ping -n 1 localhost >nul
ECHO. ^|====================================================================================================^| && ping -n 1 localhost >nul
ECHO. ^| - This tool will help you wherever you are,                   ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|   just you must be an administrator on your domain.           ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^| - Ping Package Menu:-                                         ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^| - Now You can Ping Bulk Machines, just insert the text file   ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|   (hosts.txt)that contains all hosts you need to ping it and  ^| Compatible with Windows 7 and later^| && ping -n 1 localhost >nul
ECHO. ^|   be sure that the file located in the same directory.        ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|  (Write related choice to do what you want)                   ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ^|                                                               ^|                                    ^| && ping -n 1 localhost >nul
ECHO. ====================================================================================================== && ping -n 1 localhost >nul
ECHO.
TIMEOUT /T 1 /NOBREAK >nul
echo.  You are about to Ping the whole machines in your file , Are you sure?
TIMEOUT /T 1 /NOBREAK >nul
echo.
echo.  You have 30 Seconds to choose Or the program will terminate
choice /c YN /t 30 /d n /m  "    PRESS 'Y' to Continue or press 'N' to Cancel "

If %ErrorLevel%==1 GoTo y
If %ErrorLevel%==2 GoTo n

:y
cls
TIMEOUT /T 1 /NOBREAK >nul
echo This Operation has been Confirmed.
TIMEOUT /T 1 /NOBREAK >nul
echo Now it will start after the below timeout.
TIMEOUT /T 5 /NOBREAK
cls

set /a "countOn=0"
set /a "countOff=0"


for /f %%i in (hosts.txt) do (
   set SERVER_ADDRESS_I=UNRESOLVED_IP
   set SERVER_ADDRESS_L=UNRESOLVED_IP
   SET bHOSTUP=0
   ping -n 1 %%i -w 2000 |find "TTL=" > NUL && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      set g=%%i
      CALL :HOSTUP %%i
   ) else (
      set g=%%i
      CALL :HOSTDOWN %%i
   )
)

pause
GOTO EOF

:n
cls
color fc
TIMEOUT /T 1 /NOBREAK >nul
echo.  This Operation has been canceled
TIMEOUT /T 3 /NOBREAK
GOTO EOF


:HOSTUP
Rem add 1 number to countOn variable for each online machine
set /a "countOn+=1"

for /f "tokens=1,2,3" %%x in ('ping -a -n 1 %g% ^&^& echo SERVER_IS_UP') do (
    if %%x==Pinging set SERVER_ADDRESS_L=%%y
    if %%x==Pinging set SERVER_ADDRESS_I=%%z
    )

Echo %g% : %SERVER_ADDRESS_I% : Is Pingable

set /a "rand+=5"
if %rand% geq 181 set /a "rand=0"
echo.[%g% : %SERVER_ADDRESS_I% : is Online and Pingable]>>"Online Workstations Result for Ping.txt"
GOTO EOF


:HOSTDOWN
Rem add 1 number to countOff variable for each offline machine
set /a "countOff+=1"

for /f "tokens=1,2,3" %%x in ('ping -a -n 1 %g% ^&^& echo SERVER_IS_UP') do (
    if %%x==Pinging set SERVER_ADDRESS_L=%%y
    if %%x==Pinging set SERVER_ADDRESS_I=%%z
    )

Echo %g% : %SERVER_ADDRESS_I% : Is Offline or Not Exist
echo.[%g% : %SERVER_ADDRESS_I% : Is Offline or Not Exist]>>"Offline Workstations Result for Ping.txt"
GOTO EOF

:EOF
exit /B

and You must have another text file named "hosts.txt" contain at all hostnames separated by Enter button and this file located in the same directoryI converted your file using Bat To Exe Converter v3.2 and using an empty hosts.txt ran your script with no errors. It may have to do with the converter you are using. In line 54 the hosts files is referenced with no path, so the current directory is used, but the converter may have either changed it or put it in a different variable.

Try inserting:
Code: [Select]echo %cd%
pause
prior to line 54, so you can check where the hosts.txt file is actually being SEARCHED for.

Also, why the secrecy? Your batch script is 6K, but the exe file is 96K.

 

BTW, I used the converter from here: https://www.softpedia.com/get/System/File-Management/Batch-To-Exe-Converter.shtmlThe last line is your ffmpeg command, so any parameters you want to feed to ffmpeg would go there.

So for instance, if you're working with H.265, you could remove the -c:v copy and replace it with

-vcodec libx265 -crf 28
This is just one example, mp4 containers can have any number of codecs...

Effectively, you can think of all of the lines before the last line as figuring out the parameters to feed your ffmpeg command. Quote from: Cook869 on March 27, 2021, 06:06:10 AM

The last line is your ffmpeg command, so any parameters you want to feed to ffmpeg would go there.

So for instance, if you're working with H.265, you could remove the -c:v copy and replace it with

-vcodec libx265 -crf 28
This is just one example, mp4 containers can have any number of codecs...

Effectively, you can think of all of the lines before the last line as figuring out the parameters to feed your ffmpeg command.
Your comments have nothing to do with this thread at all.  Did you mean to post this in a different thread? Quote from: Abo-Zead on March 23, 2021, 09:26:10 AM
You must have another text file named "hosts.txt" contain at all hostnames separated by Enter button
How about we call it what it is.  A carriage return and line feed.  Or hex 0D 0A.  Or for you really big nerds: 0000110100001010 Quote from: Sidewinder on March 25, 2021, 01:13:52 PM
I converted your file using Bat To Exe Converter v3.2 and using an empty hosts.txt ran your script with no errors. It may have to do with the converter you are using. In line 54 the hosts files is referenced with no path, so the current directory is used, but the converter may have either changed it or put it in a different variable.

Try inserting:
Code: [Select]echo %cd%
pause
prior to line 54, so you can check where the hosts.txt file is actually being searched for.

Also, why the secrecy? Your batch script is 6K, but the exe file is 96K.

 

BTW, I used the converter from here: https://www.softpedia.com/get/System/File-Management/Batch-To-Exe-Converter.shtml




Thanks, Sidewinder for your help and no secrecy in my question it's just simple bat file
1348.

Solve : Found spaces in my output inside created file ....why??

Answer»

hi all I have a batch to create an output text file containing all serial number of all workstations  With the help of an external file that contains the names of the hosts
but after I run it found that the output file has two kinds of situations
the first situation is my static output which contains the file information and written in normal form
the second situation is my dynamic output which contains the information I needed (the serials ) but it is written with spaces between each letter and looks like so strange form
Any help to fix this issue, please

Attached my code
Code: [Select]echo off
title Super Restart Batch using "External Text File"
setlocal enableextensions enabledelayedexpansion
color 0a
Rem mode 120,35
mode con:cols=90 lines=30
TIMEOUT /T 1 /NOBREAK >nul
ECHO.
ECHO.            *******************************************************************
ECHO.                                                                         
ECHO.                        Welcome to Amin Muhammad Batches                 
ECHO.                                                                         
ECHO.             This Batch to Get the Serial Number of all hosts located inside           
ECHO.               ( hosts.txt ) file which located in the same DIRECTORY   
ECHO.                                                                         
ECHO.            *******************************************************************
ECHO.
TIMEOUT /T 1 /NOBREAK >nul

echo.  You are about to Get the whole machines serial number in your file, Are you sure?
TIMEOUT /T 1 /NOBREAK >nul
echo.
echo.  You have 30 Second to choose Or the program will terminate
choice /c YN /t 30 /d n /m  "    Click 'Y' to Continue or click 'N' to Cancel "

If %ErrorLevel%==1 GOTO y
If %ErrorLevel%==2 GoTo n

:y
cls
TIMEOUT /T 1 /NOBREAK >nul
echo This Operation has been Confirmed.
TIMEOUT /T 1 /NOBREAK >nul
echo Now it will start after the below timeout.
TIMEOUT /T 5 /NOBREAK
cls


set Online="Online Workstations Result.txt"
set Offline="Offline Workstations Result.txt"
set /a "countOn=0"
set /a "countOff=0"
set /a "rand=0"

echo.Welcome Everyone, >%Online%
echo.Welcome Everyone, >%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.Serial Number Report File for online workstations >>%Online%
echo.Serial Number Report File for offline workstations >>%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.This Process Started at %date% , %time% >>%Online%
echo.This Process Started at %date% , %time% >>%Offline%
echo.>>%Online%
echo.>>%Offline%
echo.[  HostName  :  Status                                       >>%Online%
echo.[  HostName  :  Status                ]>>%Offline%
echo.[            :                                               >>%Online%
echo.[            :                        ]>>%Offline%


for /f %%i in (hosts.txt) do (
   SET bHOSTUP=0
   ping -n 1 %%i -w 2000 |FIND "TTL=" > NUL && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      set g=%%i
      CALL :HOSTUP %%i
   ) else (
      set g=%%i
      CALL :HOSTDOWN %%i
   )
)

echo.>>%Online%
echo.>>%Offline%
echo.Total Online Machines is: %countOn% >>%Online%
echo.Total Offline Machines is: %countOff% >>%Offline%
echo. >>%Online%
echo. >>%Offline%
echo.This Process Ended at %date% , %time% >>%Online%
echo.This Process Ended at %date% , %time% >>%Offline%
GOTO EOF

:n
cls
color fc
TIMEOUT /T 1 /NOBREAK >nul
echo.  This Operation has been canceled
TIMEOUT /T 3 /NOBREAK
GOTO EOF

:HOSTUP

Rem add 1 number to countOn variable for each online machine
set /a "countOn+=1"

Rem: get the serial number
wmic /node:%g% path win32_bios get serialnumber /format:csv

Rem: get the serial number and store it into text file
wmic /node:%g% path win32_bios get serialnumber /format:csv>>%Online%

set /a "rand+=5"
if %rand% geq 181 set /a "rand=0"
echo.[%g% : is Online and we GOT  the serial successfully>>%Online%


GOTO EOF

:HOSTDOWN

Rem add 1 number to countOff variable for each offline machine
set /a "countOff+=1"

Echo %g% : is Offline or Not Exist
echo.[%g% : is Offline or Not Exist]>>%Offline%
GOTO EOF

:EOF
exit /B

Example for hosts.txt content
host1
host2
host3
.........etcAll WMIC output is UNICODE.
Pipe the output to the MORE command and it will change it to ASNI
Code: [Select]wmic /node:%g% path win32_bios get serialnumber /format:csv|MORE>>%Online%

1349.

Solve : Still get output to file if no file exists?

Answer» WRITTEN a simple batch file that runs every minuet and will ftp files to another machine and outputs results to a log file.
Unfortunately with using *.* it still tries to ftp and outputs to the log that no files where copied.
We want it to only write to the log file if it does something. This is fine if you put *.pdf but not *.*
This is the batch file as it is now.
------------------
ECHO off
E:
cd "\workflow\administration\direct input"

if exist *.* goto COPY

goto END

:COPY

FTP -n -i -s:d:\scripts\workflow.scr >>d:\scripts\logs\workflow.log

move /Y *.* ..\postftp
:END

How can we still have all files rather than specify a type and get it to skip to END when the folder is empty?

Thank you for your time.
Mia  If there is a specific file that is always existent in the directory when it is used (such as TOC.TXT), have the test check for that vice *.* Or if you generate PDF or DOC or TXT files invariably to the directory every time it is in use, key on the extension (*.PDF) for the initial test.

Testing for *.* is like testing for nul: in a directory, it only verifies that the directory exists.

You MIGHT ALSO use an if loop and ERRORLEVEL to report on attempts to copy and move, and skip reporting and FTPing if there are no files that way.
1350.

Solve : Find Network Adapter name and store this name inside a variable?

Answer»

Hi all
after some research for a command that can get NIC name for windows OS for EXAMPLE "Ethernet" or "Local Area Connection" etc
I found that command and it works properly but how we can store the output value "I mean the name of NIC" inside a variable.

here is that command
Code: [Select]wmic nic get NetConnectionID
Hi 
Refer to this : Pass netconnectionid to a netsh interface command in batch
Code: [Select]echo off
:: tokens=2 indicates that of all the tokens that would normally be returned, we only want the second one
:: delims== indicates that the string should be split up wherever there is an = symbol
for /f "tokens=2 delims==" %%A in ('wmic nic where "netconnectionid like '%%'" get netconnectionid /value') do (
    call :dhcp "%%A"
)
pause
exit /b

:dhcp
echo %1
:: %~1 refers to the first parameter passed into the function, but without the quotation marks
::netsh interface set address %1 dhcp
We can store and set all variables into an array like this code :

Code: [Select]echo off
Title Find Network Adapter name and store this name inside a variable
SetLocal EnableDelayedExpansion
for /f "tokens=2 delims==" %%A in ('wmic nic where "netconnectionid like '%%'" get netconnectionid /value') do (
for /f "delims=" %%B in ("%%A") do (
Set /A Count+=1
Set "NET_CONN_ID[!Count!]=%%B"
)
)

for /L %%i in (1,1,%Count%) do (
echo NetConnectionId%%i = "!NET_CONN_ID[%%i]!"
)
pause
As a result, you can GOT some thing like me :

Code: [Select]NetConnectionId1 = "Ethernet"
NetConnectionId2 = "Wi-Fi"
NetConnectionId3 = "CONNEXION réseau Bluetooth"Thanks, Hackoo for your usual help but can we enable these detected Network cards also for example by using the below command.
Code: [Select]netsh interface set interface name="Name of detected network" admin=ENABLED&GT;nul

as I tried to use this command but it doesn't work for me, so could you help.All the examples I see on the web say this is proper syntax

Code: [Select]netsh interface set interface "Ethernet" disable
netsh interface set interface "Wi-Fi" enable Quote from: Squashman on April 21, 2021, 07:24:24 AM

All the examples I see on the web say this is proper syntax

Code: [Select]netsh interface set interface "Ethernet" disable
netsh interface set interface "Wi-Fi" enable

Thanks, Squashman Your opinion is correct but also I saw the previous code on the web, kindly look into this link As PROOF
https://stackoverflow.com/questions/19831023/enable-disable-network-connection-from-command-line.
, so I'm trying to merge between two this command and Hackoo array