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.

2651.

Solve : windows 95 trouble?

Answer»

???could SOME1 please help... my mums comp keeps showing the message " 1/0 error accessing boot SECTOR file multi(0)rdisk(0)partition(1)\BOOTSECT.DOS " when windows 95 tries to load , ive tried alot of things but nothing seems to work.It seems you have a DUAL Boot System with Windows NT/2000/XP and Windows 95.

You could save the bootsector of a Windows 95/98ME bootdiskette to a file called BOOTSECT.DOS and simply COPY this to to C:\ drive

There are some TOOLS you could use to save Bootsectors.
Norton Utilities has a Partition Table Editor/Browser that does nicely.

2652.

Solve : QChecker and dos?

Answer»

Hello,

I would like to use the QChecker software in BATCH mode but to use this software it’s necessary to show him the way of the file to be TREATED, its environment, its PROFILE and the way of the file where I WANT to record the output this. How can I launch a software and give him these indications, with dos.

Thank you for your assistance
Traditional Screenshots saved as BMP files can do. No DOS required, unless the program runs in DOS.
Use ALT+P to capture ACTIVE window/prog.

2653.

Solve : Mike.log?

Answer»

Hi, can anyone tell me how to make a log of the actions of a batch FILE please?

I've written a batch file and someone told me that by putting >mike.log at the END of it in the command prompt screen this will work. Usually tho I just double click the batch file off an image server or desktop and this runs it. How would I hang it all together in command prompt?

Many thanks.You could try to add the redirection ( > mike.log) to the command line in the program properties screen.

Usually users add echo statements inside their batch files and redirect the output to a log file.

If redirection is used with programs that prompt the user, the prompts will go to the log and not be visible on the screen. Sort of like an invisible wait state.

Hope this helps. If you want to debug your batch file and your script does not require any input, you could simply disable the @ECHO OFF command in your batch file to @ECHO ON then, at the prompt, simply run your batch with redirection.

Example: TEST.BAT >DEBUG.LOG

Doing this will create a TEXT file with each command executed by per line. You would have to use NOTEPAD to replace the directory lines with ZERO string.

Example result:

D:\mediacntr\$OEM$\$$\System32>cls

D:\mediacntr\$OEM$\$$\System32>REM Split all the requested users up into seperate variables.

D:\mediacntr\$OEM$\$$\System32>REM We do this because the FIND works only with single search strings.

D:\mediacntr\$OEM$\$$\System32>set user1=

D:\mediacntr\$OEM$\$$\System32>set user2=

D:\mediacntr\$OEM$\$$\System32>set user3=

D:\mediacntr\$OEM$\$$\System32>set user4=


Replace the PATH info "D:\mediacntr\$OEM$\$$\System32>" with a ZERO (no text) string under notepad.

2654.

Solve : adding a network printer in dos?

Answer»

I wonder if any one can tell me a way of installing a networked printer through DOS

thanksNET USE LPT1 \\SERVER01\PRINTER_1 /PERSISTENT:YES
LPT2 \\MY_PC\HP780C /PERSISTENT:YES
LPT3 \\OUR_PC\LEXMARKX /PERSISTENT:YES

PERSISTENT:YES is optionalwould this then SHOW the printer in the print setting in windows ?

cos i have tried it and this has'nt worked ?It should display the newly created printer as a network printer. Be aware that any firewall could block netbios browsing. Try connecting based on IP address.

example net use lpt1 \\192.168.0.2\lemarkx

{ I had to complete disable my firewll for this. Be wise and allow netbios browsing }

You could use an exported REGISTRY file and use DOS COMMANDS to silently insert the entry on the disred machine.
REGEDIT /S REGFILE.REG

Typicaly the exported registry keys would only be for the printer (default) etc

2655.

Solve : Autoexec help!?

Answer»

I need to launch a program automatically on bootup. I know I need to edit my autoexec.bat FILE, in wich I have but cannot seem to get the commands right to get my program to launch properly. These are the commands I use once the c: prompt appears.

C:>cd XYZ

C:/XYZ> XYZ


Thanks, Dan.

The commands you enter from the prompt are the same ones you put in your file:

cd xyz
xyz

In what way is your program not properly launching? Are there any error messages?

Need more info for a definitive answer. When the program "properly " launches it searches for a setup file and COULD not find it when I got it to do so upon bootup. Could my problem be with the echo command? I am using DOS 6.2 and have not modified the file any further other than adding this to the end.


c:>cd xyz
c:/xyz>xyz

Do I need the c: prompts? Sorry for the elementary question and thanks for the help.http://www.robvanderwoude.com/index.htmlWhat echo command? What startup file? There seems to be more to this than you're telling us. No, you don't need the prompts in the autoexec.bat (if fact it will fail if you do), but we can force the ISSUE:

c:
cd \xyz
xyz

Is this startup file in the xyz directory? Do you need to pass a reference to the startup file on the command LINE?

Get back to us. I have noticed that you typed the following commands.

c:>cd xyz
c:/xyz>xyz

C:/XYZ> (all of this is wrong to start with)
If this is just YOUR typo on this post, then ignore this reply.

It should be: C:\XYZ\XYZ.EXE or C:\XYZ\XYZ.COM or C:\XYZ\XYZ.BAT
Dont use the ">" at the end either. You actually dont need to type "C:\XYZ" as you already did CHANGE into the directory.

2656.

Solve : trying to install games and get autoexec error?

Answer»

I have TRIED to download several games, and one which is brand new, never installed, and there are some conflicting things going on that will not let it install on my computer. The message C:\WINDOWS\SYSTEM32\AUTOEXEC.NT. The system file is not suitable for running MS-DOS and Microsoft Windows applications. Choose 'Close' to terminate the application., appears everytime. If you click on close or ignore, it closes the installation and won't let you install the game! Is this the forum to help me or do I need to try someone else? Please help me!!This seems to be an increasingly frequent problem. It would be interesting to KNOW the cause.

To fix RUN the following from the command prompt:

copy c:\windows\repair\autoexec.nt c:\windows\system32

After you copy the file, find it in Windows Explorer, click properties and lock it down by giving it a read-only attribute.

Hope this helps. Cindy, next time post in only one section.ty darlin, problem solved, and i too would luv to know what caused this!!You might want to look at this site. It has a program managing old dos applications that would not normally run under XP too well. It supports sounds cards, joysticks, memory configurations etc. It creates its own CUSTOM PIF file that helps a lot. This could liberate your program from AUTOEXEC.NT configurations.

http://ntvdm.cjb.net/.

The App you are looking for is "VDMSOUND"

2657.

Solve : How to run multiple batch files from single batch?

Answer»

hi all,
is it possible to run multiple batch files from one batch files. I have tried it using call keyword before each batch files. But I need that those batch files should be exceuted one after the another in SINGLE command window. I know it sounds something which is impossible but u see there is nothing like impossible in DOS. There must be something that can serve my purpose.


regards
Nitin
As far as I know, the call keyword is exactly what you you should be using. PERHAPS if you posted your code it would be easier to debug. What results are you getting now? Do you want the batch files to run sequentially or simutaneously?

Get back to US. Have you ever tried using the start keyword? I believe it would start a new instance of DOS with the program executing inside this new instance, but I'm not sure that the parent (original batch file) would wait until the child (newly executed batch file) had finished. Must try it myself.If you want to use START, use the /WAIT switch. A new instance of DOS will only be created if you start a DOS PROCESS. Yes, the original batch file will wait. Unless you need a fresh environment for the started task, I fail to see the difference between the CALL and START /WAIT statements.

Batch files are fine for MS-DOS machines, but Windows Script comes with all versions of Windows (except 95A) and is a BETTER tool for any job.

2658.

Solve : bat2exe.com?

Answer»

I have a .BAT file that has been running great. However someone got into it and altered the code and it now crashes. I fixed the code and ran it through the bat2exe.com download that I found on this site. The problem is, the .bat file works fine but when it is converted to the .com format and ran, I get "Bad Command or File name" for each line of code. I would appreciate any insight. Without knowing what was in your batch file it's impossible to give an answer. Bat2exe is an old PROGRAM (1990) and batch files have CHANGED greatly since then. I did find that bat2exe only handles files in 8.3 format, can't handle FOR statements and is iffy with IF statements.

Just for fun, I TRIED it with one of my old batch programs. I got a virus alert "Contains signature of the virus VGEN/26436.0" for my troubles.

Apparently you found other batch commands that are not handled by the program.

:-/Is there any chance of the source code for the original bat2exe program? I am writing a batch file myself and would to compile it to an exe and as being a programmer I would like to know how this is done. I know it has something to do with assembler and the debug command, but apart from that I'm clueless.http://www.robvanderwoude.com/index.htmlCan you please give me the exact url for the source code? it's a large site.http://www.fsref.com/pr/dos98.shtmlI could only find the author (Doug Boling) and the fact that he first wrote an article for PC magazine where the program first APPEARED. Other than that you will need all your Google skills.

There are a lot better Batch Compilers then BAT2EXE.

I use Quick Batch File Compiler from
http://www.abyssmedia.com

2659.

Solve : MS DOS -- AT COMMAND?

Answer»

Dear List,

I am trying to use AT COMMAND in MS DOS. I have created a batch FILE with following command in it :

"c:\progra~1\spss\spssprod.exe" "c:\SPSS MONTHLY REPORTv2.spp" -s

The batch file works perfectly ok if i CALL it from command line by command :

c:\test.bat

Now, if I schedule this batch file by AT COMMAND then it's not running the JOB properly. I used following AT COMMAND :

at 13:48 "C:TEST.BAT"

I am running this job locally on my computer and I WANT my computer to run this job even if I am logged off.

Can anyone please shed some light on this problem ??

Thanks,
Vishal.What problem? The AT command is correct and assuming the parameters for SPSSPROD are correct then everything should be OK. What is happening that indicates an error? Any error messages?

Get BACK to us.

2660.

Solve : Access path and Variable?

Answer»

To the beginning of each ONE of my scripts, I would like to return in variables such as %a, %b... the access paths which I use in my script in order to facilitate the possible moving of my script.
How then I to make?
I try to WRITE %a=D/.../..
And to replace D/../.. in my script by %a
but it does not seem to go...
what could I do?Variable name primer:

Code: [Select]
%0 thru %9
exists in batch files as command line parameters

%a thru %z and %A thru %Z
yes they are different! exist only WITHIN an active FOR
statement at the command line

%%a thru %%z and %%A thru %%Z
exists within an active FOR statement within a batch file

%variablename%
exists as the RESULT of a SET statement


Pick your poison.

2661.

Solve : Set Question?

Answer»

Hey,
Im trying to use set to change a variable REPRESENTING a servername. Currently there are about 20 batch files that all have a SET servername=WHATEVER. This makes it annying to change these everytime we want to change the servername. I was thinking I could just do a GLOBAL SET servername=whatever from cmd. However as soon as I exited the command line the server was no longer set. MAYBE im doing something wrong? Hopefully I explained this well enough. (OS is windows xp). Thanks for any info.Right click My Computer-->Properties-->Advanced-->Environment Variables

Define a variable NAMED servername

then OK your way out.

Hope this helps.

2662.

Solve : date in dos bat file?

Answer»

Can someone help me create a dos bat file that will copy files that have todays date and yesterdays date as part of the file name? The dates should NOT be hard coded into the bat file. I will schedule the bat file to run AUTOMATICALLY each night.

Example: If the bat file was run today, 6/8/2005 I would like it to copy the following two files:

Membership_YYYYMMDD2246.bak where YYYYMMDD is yesterdays date 20050607
and
Membership_tlog_YYYYMMDD0816.trn where YYYYMMDD is todays date 20050608

Any help will be greatly appreciated.The technique involved is OS dependent. What OS are you using?

The current OS is NT 4.0sp6a but I will eventually have to move it Windows 2003
This little piece of doggerel will work with any Microsoft OS:

Code: [Select]
@echo off
For /f "tokens=1-7 delims=:/-,. " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,.() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set mo=%%j
set dd=%%k
set yyyy=%%l
)
)


This will give you today's variables. Batch does not do date calculations. If NT supports the /a SWITCH for the SET statement, you could do some crude processing by subtracting 1 from the DD variable but that opens a whole can of worms on the first of each month. Otherwise you're SOL.

Personally I would write a script which has excellent date handling routines.

Good luck. THANKS for the example and yes the set command does support the '/a' option so if you have any other suggestions using the /a let me know.

You are right, the problem comes into play with the first of each month.

Thanks again for your help.
Normally I would just code:

set /a yesterday=%dd%-1

but dd is not numeric and the SET will fail. PC-DOS (IBM) used to have a C2D FUNCTION that would be most helpful here but I guess it never made it to MS.

The best I can do is recommend you try scripting (very cool).

PS. If you still insist on using batch, check out:

http://www.robvanderwoude.com/datetiment.html

Scroll down to Yesterday.bat to see what's involved.

Good luck.

2663.

Solve : how to launch a .SCR file with a batch file in XP?

Answer»

I am TRYING to launch a screensaver on an XP machine and I KEEP GETTING the setup insteed of RUNNING. Any SUGGESTIONS?

2664.

Solve : Searching for most recent files?

Answer»

Hi

Is there a way that I can SEARCH for a file base on it's name or date/time stamp. The file name is like this "Detail ETL Performance Data-8332-20091022-000002.csv"

20091022 : Date
000002: Time (00:00:02)

This file contains the date and time created. I only want to extract files that were created today meaning that I want the most recent created files.

PLEASE help.

What is your %date% or date/t format please?

the date format is YYYYMMDDAre you sure about that?

At the Command Prompt enter ECHO %date% and post the outcome.

Or, at the Command Prompt enter date /t and post the outcome.For a USER all recent files have shortcuts in "recent documents"

2665.

Solve : format computer?

Answer»

i want to format my com but when i go to ms-dos command prompt i get a message saying c:\folders documentes alex. when i try to format from here it will not format ive tried to format from "my com." im running xp.You cannot format from within the OS. Boot to the XP CD and begin the installation process. You'll be offered an option to format from there.hi,ive tried formatting from xp disc but i dont get any options,,it goes direct to "setup xp"it just reinstall xp...kind regards theted Is it an original XP CD full version? If so, you should be given the option to delete/create partitions and format before the installation actually begins. Are you BOOTING to the XP CD?hi allan,no it isnt a xp copy,it just goes straight to xp install..is there any other way to format my c drive..any help would be appreciated...One more time. Are you BOOTING to the cd or are you trying to start the format from within Windows?hi allan,how do i" boot to xp cd"..do i have to go into safe mode...what i did was insert xp disc into SLOT and reboot computer,but as i said there is no options..i must be doing something wrong..theted Go into the bios and set the cd as the FIRST boot device in the boot order section. Then reboot to the cd.i think my brov will have to TAKE a wee trip down to his local pc repair shop...thank for all your help allan...theted You don't need to PAY anyone, just FOLLOW the instructions. Go into the bios and make sure the cd drive is at the top of the boot order. Then insert the XP CD in the drive and reboot. It's that simple. What part are you having trouble with?hi,i'll get my brother to get in touch with u...thanks ...theted

2666.

Solve : Need Advice with this Backup Script?

Answer»

Below is an Outlook backup script I have compiled through much searching and trial and error. This script will close Outlook on a networked client computer where the user is still logged on; then backup his/her Outlook .pst files to a shared user folder on a Win 2003 server. After the backup is done the script will RESTART Outlook minimized to the system tray. Some users Outlook needs to be restarted so a third party "Out of Office" application can run.

This works for my users that have Outlook already open and then need it to be reopened for the reason stated above. However, for the users who do not have Outlook open and don't need it to be reopened this script (even though it does backup their Outlook files) is lacking and needs some tweaking.

What I would like it to do (but don't know how to do it) is to use some kind of statement that will do the following:

Check first to see if the users Outlook is open
If it is then taskkill / IM outlook.exe - and run %backupcmd%
If it is not open then just run %backupcmd%

After the .pst files are saved back to the server, then reopen Outlook on the users that had Outlook open in the first place and/or leave Outlook closed on the users that never had it open to begin with.

The way the script stands now it does work but if a user does not have Outlook opened then an error occurs - ERROR: The process "outlook.exe" was not found - but the script still runs and completes. Also the users that did not have Outlook opened now do after the script has finished

I will be putting this script on each users computer and then using XP's scheduler to schedule the backups. My knowledge of scripting as you've no doubt guessed is next to none, so this is the only way that I know how to do it. I am open to SUGGESTIONS and help. Thank you in advance
Below is the script thus far.
--------------------------------------------------------------
@echo off
:: variables
set drive=\\Droopy\user_emails$\bbking
set backupcmd=xcopy /s /c /d /e /h /i /R /y

echo Closing Outlook...
taskkill /IM outlook.exe
echo.
echo Pausing...
ping 1.1.1.1 -n 3 -w 1000 >nul
echo.
echo Backing up Outlook Files...
echo.
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"
echo.
echo Backup Complete!
echo.
echo Restarting Outlook...
@echo off
start /d /MIN "C:\Program Files\Microsoft Office\OFFICE11" OUTLOOK.EXE
------------------------------------------------------------

Thanks Again.
DougOne way would be to iterate thru all the running processes.

Code: [Select]@echo off
:: variables
set drive=\\Droopy\user_emails$\bbking
set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo Closing Outlook...

for /f "tokens=2" %%i in ('tlist') do (
if /i %%i==outlook.exe taskkill /IM outlook.exe
)

echo Pausing...
ping 1.1.1.1 -n 3 -w 1000 >nul
echo.
echo Backing up Outlook Files...
echo.
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"
echo.
echo Backup Complete!
echo.
echo Restarting Outlook...
@echo off
start /d /MIN "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"

Depending on which version of XP (Home or Pro) you have, you may have to use tasklist instead of tlist. In that CASE change tokens=2 to tokens=1.

Good luck.

PS. I also changed the start command. For some reason, yours LOOKED too funky to be correct.Thanks Sidewinder. This will work. I know that there is probably an easier way to do this but so far we don't have to many clients on our network so this will work. We have all XP Pro so I changed to tasklist and tokens=1. As for the start line I first tried it the way you have it (i.e. quotes around the whole path) and got a Path not found error (something like that). Did some digging on line and tried the way I currently showed in the first post and that worked! Not sure why, though.

Thanks again.
Doug

2667.

Solve : how to do stringtokenizer in batch file (DOS Command)?

Answer»

how to do stringtokenizer in batch file (DOS Command)
for Example
set Str1=Log,error,java
i want a method that will split this strings and want to iterate through each sting using for loop .the STANDARD WAY natively, is to use for loop and set the token , DELIM params. see for /? for more info.
Here is another way in biterscripting.

Code: [Select]var str str1 ; set $Str1="Log,error,java"
set $wsep = "," # Set token separator
wex -p "1" $Str1 # Will get the first token "Log"
wex -p "2" $Str1 # Will get the second token "error"
wex -p "l" $Str1 # Will get the last (l) token - java
wen $Str1 # Will get the token count - 3

cat "x.txt" > $Str1
wex -p "2" $Str1 # Will get the second word from file x.txt.
Help page on wex command at http://www.biterscripting.com/helppages/wex.html

2668.

Solve : Need help Writing Batch File Code.?

Answer» OKAY I made a Batch File saving notepad with .bat. So can someone show me what the code needs to be to Copy and Zip files older then 2 days and move the Zip to ANOTHER folder?Quote
Okay I made a Batch File saving notepad with .bat

You stand a better chance of getting help if you show US your code. It gives us a better UNDERSTANDING of where you're going with the code.

Double Post.
Topic Closed.

See your other Post for replies...
2669.

Solve : Deleting Directory Dynamically?

Answer»
          Hello All,

          I need help on deleting directories;
          I have a particular ETL session, which will load data for each country from a particular folder called "TempData"

          This folder, CONTAINS
sub-folders with names like,

ABCxxxxx_CNTRY_DDMMYYYY, where
  • xxxxx re-presents some unique numbers,
  • ddmmyyy re-presents day, month year
  • eg. ABC12345_JP_26102009
  • The folder names can't be hard-coded as the numbers, country name, and DATES keep changing
Once the data is loaded, I need to delete the contents (of a particular country) from this "TempData" folder.

I've tried using the following,

RMDIR /s /q X:\TempData\*_JP_*
DEL X:\TempData\ABC?????_JP_*

BUT both don't work.

any help would be highly appreciated.
Thanks.

Try using ROBOCOPY

http://en.wikipedia.org/wiki/Robocopy

It can HANDLE sub folders

2670.

Solve : How to judge whether the specified directory or file exists or not??

Answer»

Hi All:

In BATCH programming, how to judge whether the specified directory or file exists or not? Thanks a lot in advance!check the EXIST part of IF - do IF /? at the command PROMPT ... it works for directories tooCould you please paste some code snippet? Thanks!Quote

IF EXIST FILENAME. echo found filename.
ELSE echo filename. missing
Hello,

if exist C:\Test\nul echo It is there

will make an output "It is there" when the directory is present.


if not exits C:\Test\nul echo Dir not found

will make an output "Dir not found" when the directory ist not present.


Instead of "nul" you can use filenames, too.

Ciao.



Brain
2671.

Solve : How to use the "find" command with extended ASCII characters ??

Answer»

Hi everyone,

I am currently trying to use the "find" command with extended ASCII characters, such as "é" but I can't make it. The solution may be quite simple but I am not an expert of DOS.

For academic purposes, I am trying to use DOS to find specific strings in a huge .txt file and export the results into a new .txt file. The first problem I encountered was I couldn't find extended ASCII characters at all. But then I understood it must be a encoding problem, so I converted this huge file from ANSI to "UCS-2 Litte Endian", the only one that works correctly. With the file being in UCS-2 Little Endian, DOS does find extended ASCII characters. If I don't specify an output file, then DOS displays the result list and this list IS correct. But what I need, of course, is to save the results in a new file, so I specify it in the command line. Here is an example of what I type (say I am looking for "é" in the a.txt file):

find "é" d:\a.txt > d:\results.txt

The problem is that extended ASCII characters are not preserved in the results.txt file. For example, instead of getting "fiancé" I get "fianc,". So I guess it is an encoding problem because it seems that I can't get 128+ ASCII characters in the output file whereas I do get them directly on my SCREEN if I don't ask for an output file.

Could you HELP me preserve the extended ASCII characters in the output file ? I really don't know how to do ...

I hope you can understand my problem correctly; I'm not USED to using computer-related terms in English (I'm French) so I may not be using the right ones.

Thanks a lot in advance !

Jérémy


edit: I'm realising that it's not really related to the find command. To put it more simply, if I type "echo fiancé > d:\test.txt" then the test.txt file does not contain "fiancé" but "fianc,". How can I do ? Thanks !What code PAGE are you using? Type chcp (without any parameters) to see which one you are using

I think maybe you need to set your console code page to 1252:

chcp 1252

or try

chcp 863







Hi,

I'm using code 850.

I tried the ones you mentioned but it doesn't change anything.
But I'm not sure my message really was clear. If I type "echo é" I do get "é" correctly. The problem is only if I want an output file, that is, if I type "echo é > d:\test.txt". In this case, test.txt does not contain "é" but ",".
I take the example of "é" but it's not restricted to letters with accents, I get the same problem with all 128+ ascii characters.Strange.

Code: [SELECT]
C:\>chcp

C:\>Active code page: 863

C:\>echo maquillé comme mon fiancé>indochine.txt

C:\>type indochine.txt
maquillé comme mon fiancé

I do get the same thing as you but only if I use the "type" command. If I go fetch the file and open it manually then I get "," instead of "é". What about you ? Have you tried opening the file manually (not via DOS but via Windows) ?

2672.

Solve : How do I create a batch file to delete log files older than 2 weeks?????

Answer»

Can anyone help me create a batch file that will delete log files in a certain directory that are older than 2 WEEKS?

Thanks!!!!! hefe, were not here to just make stuff for people. we are here to help people make stuff.

if have your "blueprints" or the code you are trying to make it out of, we can help you with thatBatchFileBasics:

hefe posted:
Quote from: hefe on July 22, 2009, 09:08:38 AM

Can anyone help me create a batch file

You said:
Quote from: BatchFileBasics on July 22, 2009, 11:13:34 AM
we are here to help people make stuff.


Isn't that what hefe asked for?Quote from: manadude2 on July 22, 2009, 11:32:10 AM
BatchFileBasics:

hefe posted:
You said:

Isn't that what hefe asked for?

but where is his progress so far?Quote from: manadude2 link=topic=88144.msg591102#msg591102
Isn't that what hefe asked for?
[/quote
you can ASK for help, but sometimes people want to see effort before helping.
Have a nice day. Have a nice day. Hi guys, it's not a batch file, but I've found a program that will delete files in a specific FOLDER that are older than the specified time.

It's called Cyber-D's Autodelete 2.15 and can be downloaded from here, here or here.I've seen this question (or one like it) a zillion times on this and other DOS sites, but never a pure DOS solution... thought it was about time I contributed. It looks a lot more complicated than it really is, but any comments or suggestions are welcome.


First the basics:
Code: [Select]@ECHO OFF
CLS

VERIFY OTHER 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
ECHO Cannot enable Command Extensions
GOTO EndError
)

VERIFY OTHER 2>NUL
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
ECHO Cannot enable Delayed Environment Variable Expansion
GOTO EndError
)
Which directory, and how many days of stuff do you want to keep? These are the only two variables you need to set.
Code: [Select]SET RetentionDays=14
SET TargetDirectory=C:\Temp
Obviously, you could change this variable usage to input parameters instead, to make this script more flexible. Also, consider a third argument for the filename.extension mask you want to keep/move/delete/whatever with this script. In this example, I am including ALL files.

Next, set a group of date variables to today:
Code: [Select]FOR /F "tokens=2-4 delims=/ " %%d IN ('ECHO %DATE%') DO (
SET dMonth=%%d
SET DDAY=%%e
SET dYear=%%f
)
The XCOPY command we are eventually going to use requires the format mm-dd-yyyy. Set the "Retention Date" and start with today:
Code: [Select]SET RetentionDate=%dMonth%-%dDay%-%dYear%
Main DATE logic -- see internal REMarks:
Code: [Select]IF %RetentionDays% GTR 0 (
REM --------------------------------------
REM Set the working date, start with today
REM --------------------------------------
SET fooMonth=%dMonth%
SET fooDay=%dDay%
SET fooYear=%dYear%

REM -----------------------------------------------------------------
REM Loop N times, where N=%RetentionDays%,
REM and subtract one from the Working Date.
REM
REM The called PreviousDay.cmd script is attached as a TXT file. I
REM adapted it from another script I found somewhere on the
REM interwebs. Credit to the original author, whoever s/he is.
REM
REM PreviousDay takes one input argument in the format mm dd yyyy
REM and echoes the previous day in the same format
REM -----------------------------------------------------------------
FOR /L %%l IN (1,1,%RetentionDays%) DO (
FOR /F "tokens=1-3" %%p IN ('CALL %COMSPEC% /E:ON /V:ON /C PreviousDay.cmd !fooMonth! !fooDay! !fooYear!') DO (
SET fooMonth=%%p
SET fooDay=%%q
SET fooYear=%%r
)
)

REM ---------------------------------------------------------------
REM Now set the Retention Date to the Working Date we've calculated
REM ---------------------------------------------------------------
SET RetentionDate=!fooMonth!-!fooDay!-!fooYear!
)

Main CLEANUP Logic -- see internal REMarks:
Code: [Select]REM -----------------------------------------------------
REM First, build a List of ALL files in %TargetDirectory%
REM -----------------------------------------------------
FOR /F "tokens=1 delims=|" %%b IN ('DIR /B %TargetDirectory%') DO (
REM optionally use FOR /F "tokens=1 delims=|" %%b IN ('DIR /B %TargetDirectory%\*.foo') DO (
REM -------------------------------
REM Store each filename in the list
REM -------------------------------
SET ThisFileName=%%b
SET ThisFile=%TargetDirectory%\!ThisFileName!
SET DeleteThisFile=TRUE

REM ----------------------------------------------------------------------
REM Next, build a list of files where datestamp >= (TODAY - RetentionDays)
REM ----------------------------------------------------------------------
FOR /F "tokens=*" %%k IN ('XCOPY %TargetDirectory%\*.* %TEMP% /L /D:!RetentionDate!') DO (
SET KeepFile=%%k

REM --------------------------------------------------
REM Exclude the "n File(s)" echo by testing with EXIST
REM --------------------------------------------------
IF EXIST !ThisFile! (
REM --------------------------------------------------------
REM If ThisFile = KeepFile then KeepFile will NOT be deleted
REM --------------------------------------------------------
IF /I "!ThisFile!"=="!KeepFile!" (
SET DeleteThisFile=FALSE
)
)
)

REM ---------------------------------------------------------------------------------------
REM Finally, test KeepThisFile and DELETE ThisFile if it was not found in the KeepFile list
REM ---------------------------------------------------------------------------------------
IF /I !DeleteThisFile!==TRUE (
ECHO DELETING !ThisFile!
DEL /F /Q !ThisFile! > NUL
)
)
That's it! Please note that this example deletes all files older than 14 days. In other words, it will keep all files date-stamped within 14 days, inclusive. Example: Today is 07/25/2009. That date minus 14 = 07/11/2009. Any files date-stamped 07/11/2009 (or 07/12, or 07/13, etc.) are not touched. Any files date-stamped 07/10 (or 07/09, or 07/08, etc.) are deleted.

Also, this does NOT perform \Folder\ deletion, and I haven't gone out of my way to handle path\filenames with embedded spaces, but it won't take much to incorporate either of those features.

Hope it helps!


[attachment deleted by admin]excellent solution, if I say so myself! Thanks! Every line makes me like my sig more n more. Quote from: hefe on July 22, 2009, 09:08:38 AM
Can anyone help me create a batch file that will delete log files in a certain directory that are older than 2 weeks?

Thanks!!!!!
you can see here (Example 2) for an example using vbscriptSee also http://home.mnet-online.de/horst.muc/wbat32.htm

DelAge32 deletes or moves files with a mimimum age given by the number of days, © 2003-2008, Horst SchaefferQuote from: gh0std0g74 on July 25, 2009, 10:48:20 PM
you can see here (Example 2) for an example using vbscript


Ghost,
The Batch solution is much better and they are on the right Board.Quote from: billrich on October 22, 2009, 11:51:16 AM

Ghost,
The Batch solution is much better and they are on the right Board.
date manipulation is always not better using cmd unless you have tools like GNU date , or GNU find or even vbscript , period.
GNU find, just one line does the job
Code: [Select]c:\test> gnu_find.exe c:\path -type f -mtime +14 -delete # delete files older than 14 days
vbscript does date OPERATION better than batch (cmd)...period.
Code: [Select]Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\temp")
For Each efile in objFolder.Files
If DateDiff("d",eFile.DateLastModified,Now) >= 30 Then
WScript.Echo "file found that is 1 month old: " & efile
WScript.Echo eFile.DateLastModified
objFSO.DeleteFile(eFile)
End If
Next

in the real world, one do not have to waste time doing unnecessary things when there are tools already there to help make one's job easier.

Lastly, why do you reply after 3 months...? You are so bored because nobody is nitpicking with you?
2673.

Solve : batch file with ASCII art?

Answer»

Hi guys,

I have a little batch file created which runs fine as attended.
But after adding just a SIMPLE ASCII art (as introduction) it's failing. It's just STARTED up for a tiny second and is closed again immediately?!

This I added:

echo _
echo _( )_
echo (_(%)_)
echo (_)\
echo | __
echo |/_/
echo |
echo |

... and nothing else. :-/
Is there anybody being able to help out?

Thank you!
Quote from: belka

echo _
echo _( )_
echo (_(%)_)
echo (_)\
echo | __ <------
echo |/_/ <------
echo | <------
echo | <------

You are using the 'pipe' so the Command Interpreter expects a valid command after it but finds __ instead. This is invalid so the script fails the first TIME the 'pipe' is used. To correct this Escape the pipes.

& Welcome to the CH forums..Quote
You are using the 'pipe' so the Command Interpreter expects a valid command after it but finds __ instead. This is invalid so the script fails the first time the 'pipe' is used.

Aah, and I've already been AFRAID of that stuff.

Quote
To correct this Escape the pipes.

I had to prefix them with carets?! I did that for all pipes but failed again.
What are all relevant special characters and symbols in this regard?

Quote
& Welcome to the CH forums..

Thanks. :-)


Thank you.I Escaped the pipes using the caret and the script ran without problem.

echo ^|__
echo ^|/_/
echo ^|
echo ^|


... I failed. But after prefixing also '<', '>' and '_' it ran! :-)

Maybe there is a whole bunch of special characters needing a such special treating?!

Thanks so far!
There's a list here..


Quote from: Dusty on October 23, 2009, 01:18:34 AM
There's a list here..

Thank you!

Quoting from there:
When piping or redirecting any of these charcters you should
prefix with the escape character: \ & | > < ^
e.g. ^\ ^& ^| ^> ^< ^^
end of quoting

As you can see this shouldn't be a _complete_ list because I had to prefix ' _ ' in my batch, too?!

No. the underscore has no special meaning to the command interpreter and therefore does not require escapement.Quote from: BC_Programmer on October 23, 2009, 10:31:29 AM
No. the underscore has no special meaning to the command interpreter and therefore does not require escapement.

Well, that may be or not. In fact I had to prefix even all underline characters (not 'underscore') in order to get my batch running. But maybe there is a 'hidden truth'?
That's why here again what I did for another example:

echo ^_^_ ^_^_
echo .' `...' `.
echo ^_^_^| ^| ^|^_^_
echo .' \ . / `.
echo ^| ./###\. ^|
echo ^>---- ^|#####^| ----^<
echo ^| `\###/' ^|
echo `.^_^_ / . \ ^_^_.'
echo /^| ^| ^|
echo / `.^_^_^_.^.^_^_^_.'
echo ^|
echo ^|
echo \
echo \ )\
echo `. /' ^|
echo \ /' )
echo \ /' /'
echo \ /' /'
echo \( /'
echo ) /'
echo ^| /'
echo ^|(
echo ^|^|

Thank you.
Belka - your script works perfectly without the underline (underscore) characters being escaped.


Try this, works for me, tested on Win2k, Win2k.Pro, Win XP.HE and Win XP Pro.
Code: [Select]@echo off
cls

echo __ __
echo .' `...' `.
echo __^| ^| ^|__
echo .' \ . / `.
echo ^| ./###\. ^|
echo ^>---- ^|#####^| ----^<
echo ^| `\###/' ^|
echo `.__ / . \ __.'
echo /^| ^| ^|
echo / `.___..___.'
echo ^|
echo ^|
echo \
echo \ )\
echo `. /' ^|
echo \ /' )
echo \ /' /'
echo \ /' /'
echo \( /'
echo ) /'
echo ^| /'
echo ^|(
echo ^|^|
Although when you do escape them, it has a bunch of anime smiley's... Quote from: Dusty on October 23, 2009, 03:07:55 PM
Belka - your script works perfectly without the underline (underscore) characters being escaped.

I admit you're right. I checked it renewed. Ago I got a failing, no idea what happened.

Okay, in this way we both learned something new.
Thank you for reliable supporting.

2674.

Solve : Did you know??

Answer»

Did you know that WSH or wsh is an alias for the wscript object in VBScript? So that e.g. wsh.echo works just like wscript.echo does, and WSH.Echo WSH.FullName, WSH.Version works just like wscript.Echo wscript.FullName, wscript.VersionI have been aware of this, but my VBScript editor (VBSEdit) does not OFFER to help with intellisense unless I spell out WScript. SOMETIMES readability OUTWEIGHS KISS.

2675.

Solve : Issues with batch file reading input.txt?

Answer»

Hello everyone. I can tell you now that I'm a complete NEWB to this.

I have a .exe file that reads a .raw file from a laboratory machine. The .exe file works just fine: you tell it what file to read then tell it what record to read in the file, and it displays the data. The .raw file contains 350 records, each record contains 1000 rows of data. I can get all the data I need by manually feeding the .exe file the numbers 1-350 BUT I would like this automated through a BATCH file. This is what the batch file looks like now:

*RUN
read-raw.exe < input.txt >> results.txt


The input.txt file looks like this:

hao01.raw
1
2
3
4
0


The problem is, when I run the batch file, the results file generated only displays the first record, and doesn't even complete the record by displaying all 1000 rows. It displays up to 998 just fine, and only display a "1.0" for the 999th row (which is not the correct data values).

Can anyone help me out? I just noticed that it's giving the first 3 characters for the 999th row. So "1.0" was actually the correct value, but it just cuts off after that. I tested it with record 2 and it does the same thing, runs properly through row 998 and gives the first 3 characters of row 999.

What could be causing it to cut off after the first three characters on that 999th row?No ideas? it could be that fact that notepad has a limited number of character per row, and you're exeeding it, but i'm not sure if a batch file would continue WRITING in the next line (WORD wrapping). I suggest making a loop that writes a character a number of times (a large number of times) to the file....

but the echo command goes to the next line after execution, so maybe making a long string with a loop and writing it to the txt file would work.

I havn't tested this, but playing AROUND this idea might get you somewhere

Hope this helps

regards
Two-Eyes %

EDIT/UPDATE:
I tried this, and word wrapping DOES occur, so now i'm stumped.
Maybe It's the code in the read-raw.exe file... do you have access to it? A more informed person than me might help you better...need to know what is the 4th character of row 999.
Two-eyes, I'm trying to see if I can get the code for the read-raw.exe now. I'll post it if I can get it. But I wonder could that really be the problem if the read-raw.exe works perfectly when it's fed in the row #'s individually, by hand?

Salmon Trout, the 4th character of row 999 for record 1 is a "4". Well actually the rows displays "999 1.0" so I guess it technically cuts off after the 7th character. (The 999th row in it's entirety should read "999 1.048 0.697 155.93")

But it's cutting off at that point on any record I select. For example, if I have the input file start with record 2 The last line displays "999 0.6". When the full row should read "999 0.624 0.278 30.00".



Thanks so much for your help.

Another question: How is a batch file supposed to close out on it's own? This thing doesn't close on it's own, I have to close it and click "End Now." It just seems like it should close on it's own. I wait for a while before I close it, to try and let it finish, but it doens't matter how long I wait; it still hangs up at the same point. Could this be realted, or no?Quote

the read-raw.exe works perfectly when it's fed in the row #'s individually
woops, didn't get that part in your first post, sorry. So my "fix" wouldn't be related.

Quote
I'm stumped

I just checked and I can't get the code for the .exe anyway.


Anyone else have other ideas?Quote from: Salmon Trout on October 20, 2009, 01:41:34 PM
need to know what is the 4th character of row 999.

2676.

Solve : Creating a Batch File...?

Answer»

I am in a Computer Networking Systems course. Our teacher wants us to create a Batch file that takes files from one folder that are older then 2 days and zips them and moves them to another folder. How do I create the batch file that does this?does your teacher ask you to do things that he or she hasn't taught yet? If yes, you should ask your teacher how its done. If not, show us what you have so far I don't have anything so far. I just know how to create the file by making it .bat I don't know how to get it to perform the commands he wants.Quote from: ItalianOnEdge on October 22, 2009, 11:34:28 PM

I just know how to create the file by making it .bat I don't know how to get it to perform the commands he wants.
so where is that .bat file since you say you know how to create it. does it have any commands in it ? or is it a blank .bat file?? you can go to here for some dos tips...or here

on a side note, seriously if you aren't learning anything out from your teacher, you might as well stay at home and learn from internet.

by the WAY, you are not SUPPOSED to post homework questions here ... (without putting in effort)

Actually I have put effort. I just cant get it to perform the commands. I been checking on sites to get a general idea on how to write the command script. But what I getting if a million different ways and i know how to get them to work the way I want them to. I just saved the .bat file to the desktopQuote from: ItalianOnEdge on October 22, 2009, 11:51:18 PM
Actually I have put effort.
and where is it? post it here so that the so called "batch gurus" can GUIDE you alongListen I am modifying this cause I over reacted. Dude if I knew what I was doing I wouldn't be asking here. I tried to make it and it didn't work. Not even close, so I deleted it. So if you are gonna insult me by questioning my being lazy or not then just don't respond.Quote from: ItalianOnEdge on October 23, 2009, 12:13:24 AM
Dude if I knew what I was doing I wouldn't be asking here.
if you don't know anything, ask the teacher again. or revise your notes. If the teacher had asked you to do things that he hasn't teach, then ask for his advice on how to go about doing it..
Quote
I tried to make it and it didn't work. Not even close, so I deleted it.
if you really put in effort and it didn't work, you should post it and let others take a look and POINT you to right direction. However, you have not done that. It leads me to deduce that what you say about putting in effort is bull.

Quote
So if you are gonna insult me by questioning my being lazy or not then just don't respond.
At least i did not specifically call you a lazy bum in my posts. all i did was ask you to show what you have. It is hard to believe that you attend a course, and learn nothing at all from it.


Another hint for you, you can search this forum on "DELETING file more than X number of days". There are similar posts which you can learn how to do it from .
2677.

Solve : GUI for copying file names to text file?

Answer»

This was asked on Facebook and I'm not FAMILIAR with any GUI, so CURIOUS if anyone else has ideas.

---

OK, here's a question... I know in DOS you can do a

dir /t:a &GT; file.TXT

to send the LISTING contents of a directory into a .txt file with the timefield of Last Access. So I start thinking... Do you know of any windows compatible software tools that give me a GUI interface and allows me to export file names/locations with multiple timefields?

For example, the DOS command would be:

dir /t:c /t:a > file.txtsee this thread. The vbscript shows you how to get file properties. As for GUI, you can use HTA..Or use VBA or VB to query file properties..

2678.

Solve : calling .bat from another .bat fails with invalid login. why??

Answer»

Hi all,
I am running BATCH file (main.bat) from which I call 2 other batch files. Both files have to login to the servers (different servers).
First file runs fine, but next one fails to login. I've tried to run second file by itself and it runs just fine. I am not sure if is .bat file "issue".
Anyone aware of such behavior?

main.bat
----------------
call batch_1.bat
call batch_2.bat

batch_1.bat
-------------------
echo Database backup
rman target user/pwd @ log

batch_2.bat
--------------------
echo CommVault backup
qlogin -cs "server_name" -u "user" -p "pwd"


Thanks,
Eugene
exit /b * see below


C:\>type twobatch.bat
Code: [Select]@echo off

call batch_1.bat
echo return to main after batch one
call batch_2.bat

echo return to main after batch two

pause
OUTPUT:

C:\> twobatch.bat
Database backup
return to main after batch one
CommVault backup
return to main after batch two
Press any key to continue . . .
C:\>


C:\>type batch_1.bat

Code: [Select]echo Database backup
rem rman target user/pwd @&LT;path_to_file_to_run> log <path_to_log_file>
exit /b
C:\>type batch_2.bat

Code: [Select]echo CommVault backup

REM qlogin -cs "server_name" -u "user" -p "pwd"

exit /bC:\>


*below
C:\>exit /?
Quits the CMD.EXE program (command interpreter) or the current batch
script.


*below
EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of
CMD.EXE. If EXECUTED from outside a batch script, it
will quit CMD.EXE

exitCode specifies a numeric NUMBER. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.

C:\>Thanks billrich,
I will give it a try tonight and LET you know if it worked.

2679.

Solve : Runas error 267??

Answer»

I'm attempting to run explorer as a different user, however when I run the batch, I get error 267, invalid DIRECTORY. The directory I specified is C:/WINDOWS/explorer.exe

Any idea what the problem might be?Can you please post your code. MAKE sure to blank out passwords. see next postError 267 description
Error 267 Definition: Error 267 is also known as ERROR_DIRECTORY .

Error 267 is a common Windows error. Error 267 is usually CAUSED by missing system files, wrong system settings or a corrupted registry file. Run a registry scan to check for registry errors & other system problems. 90% of the time this will fix the cause of the error.



http://onecare.live.com/site/en-us/center/cleanup.htmI mean can you please post the TEXT from your BAT file?

2680.

Solve : Create batch file that deny access to certain websites?

Answer»

Hi everyone, I'm trying to create a batch file that stop the end user surfing some specific website such as adult website. I heard that we have to find the ip ADDRESS of that website and copy it to the batch file with some commands but I don't know how to do that. I'm new to MS-DOS. If you have any good resources that can help, it would be great. I don't mind reading.
Thanks!!!What is My IP Address?

http://whatismyipaddress.com/?gclid=COapzPqSzJ0CFQ8MDQodHC4_rA

khuynh, you want to find out the ip addresses of adult websites? hmmm.....

Seriously, it is easy to block ACCESS to a web url such as www.bikinbabes.com, less easy to block access to an ip address.

It seems that Billrich thinks you want to find out your own ip address, but I am sure that when he gets around to actually reading your post properly he'll want to tell you to add the urls of the adult websites to your HOSTS file. If you search on Google for "Windows HOSTS file format" you will see lots of information about how to block access to a given web site this way.

However since the HOSTS file can be manipulated by people such as hackers many system admins (and all SENSIBLE ones) deny access to ordinary users


Quote from: SALMON Trout on October 20, 2009, 01:40:05 PM

khuynh, you want to find out the ip addresses of adult websites? hmmm.....

Seriously, it is easy to block access to a web url such as www.bikinbabes.com, less easy to block access to an ip address.

Add the urls of the adult websites to your HOSTS file. If you search on Google for "Windows HOSTS file format" you will see lots of information about how to block access to a given web site this way.

However since the HOSTS file can be manipulated by people such as hackers many system admins (and all sensible ones) deny access to ordinary users


Thank you Salmon Trout on how to block access to Porn sites. If I understand your instructions: We don't need the IP address of the porn site.
URL ( the site address ) is what is blocked.

A grandson or son can easily reverse the Block. The Porn sites are out of control and a better screen is needed.

Thanks again Salmon Trout for your professional advise.So what is your suggestion? To block an ip address requires additional software such as a firewall.

Quote from: The OP
I'm trying to create a batch file that stop the end user surfing some specific website such as adult website.

Add the url that you wish to block to HOSTS then make HOSTS readonly and hidden, finally deny admin provileges to the relevant users.
i believe this wiki page has the right information of hosts and blocking sites, as well as other information of hostsThanks everyone. I'll give it a shot... Alright!!!! I did it. Thanks alot everyone. Quote from: khuynh on October 21, 2009, 09:40:40 PM
Thanks everyone. I'll give it a shot...

How did you block all Porn sites? Can anyone remove your Block?


http://www.netdogsoft.com
2681.

Solve : Saving variables for re-use?

Answer»

Gudday all
I am WRITING a batch that that will use lines from a file, parse as appropriate and use the PARSED infromation as parameters for the copy or move command.
The input file looks like
Code: [SELECT]\TestingTiffMoves\AU\PICKLIST\0000544B.TIF
\TestingTiffMoves\AU\PICKLIST\0000544C.TIF
\TestingTiffMoves\AU\PICKLIST\0000544D.TIF
\TestingTiffMoves\AU\PICKLIST\0000544E.TIF
\TestingTiffMoves\AU\PICKLIST\index.dat
I wish to extract the file name at the end of each line and the whole line itself and save as variables called file_name and file_path. These variables become the parameters for copy/move.
My code looks like
Code: [Select]@echo off
cls

set var file_name =
set var file_path =

for /f "eol=;" %%i in (moveTIFF.dat) do (set %%i=%file_path%
echo %%i)
for /f "eol=; tokens=4 delims=\" %%j %%k in (moveTIFF.dat) do (set %file_name%=%%j
echo %%j)
copy %file_name% %file_path%
At the moment only the last file (index.dat) is ACTUALLY moved or copied. I am sure that the error(s) are PAINFUL obvious but i cannot find it (them).
Any advice?

2682.

Solve : Escaping \?

Answer»

How does one escape the '\' in a path.
I wish to use the \ as a delimiter in the for command but it won't accept the \ in its location.

The code is
Code: [Select]for /f "eol=; tokens=4 delim=\" %i in moveTIFF .dat do @echo %i
and the error message is
Code: [Select]delim=\" was unexpected at this timeThe moveTIFF.dat format is
Code: [Select]\TestingTiffMoves\AU\PICKLIST\0000544B.TIF
\TestingTiffMoves\AU\PICKLIST\0000544C.TIF
\TestingTiffMoves\AU\PICKLIST\0000544D.TIF
\TestingTiffMoves\AU\PICKLIST\0000544E.TIF
\TestingTiffMoves\AU\PICKLIST\index.dat

What I want to do is extract initially the *.TIFF and index.dat to echo them. Once I have done that I will replace the @echo will the copy command..
(I had originally done a lot of work like this but whem we migrated from XP to Vista somehow or my batch files and notes got lost )Code: [Select]
for /f "eol=; tokens=4 delims=\" %i in (moveTIFF.dat) do @echo %i

it's delims, not delim ALSO you need brackets around the filename.

You don't need to escape a backslash. You just need to use delims with an 's'.

Code: [Select]"delims=\"
However the more usual way to get at the various parts of a file data (full path, drive letter, path, FOLDER, file name, file extension, size, date etc) is to use the FOR variable modifiers. These can be viewed at the prompt by typing FOR /?

Quote from: BC_Programmer on October 21, 2009, 12:56:45 AM



it's delims, not delim also you need brackets around the filename.


*censored* fat fingers. Thank youQuote from: Salmon Trout on October 21, 2009, 01:04:43 AM
You don't need to escape a backslash. You just need to use delims with an 's'.

Code: [Select]"delims=\"
However the more usual way to get at the various parts of a file data (full path, drive letter, path, folder, file name, file extension, size, date etc) is to use the FOR variable modifiers. These can be viewed at the prompt by typing FOR /?


I will try those variable modifiers. Thank you.
2683.

Solve : SET CLASSPATH?

Answer»

I am trying to set a CLASSPATH variable to compile an application, the script should look for all .jar files in a directory and add the results on a local variable to give that variable to a JAVAC and compile the java classes...

I have the following script in a bat file but is not working

FOR /R D:\PATH\libs %%i IN (*.jar) DO SET CLASSPATH=%CLASSPATH%;%%~nxi;

When a put echo %CLASSPATH% I only SEE the last package found

D:\PATH&GT;echo %CLASSPATH%
;mylib99.jar;

Could anyone tell me what am I doing wrong...

MANY THANKS IN ADVANCEIt is not CLEAR what you want to do.
How many jar files are there?
Why do you need to compile all at once?
If you were to do it manual, how long does it take?
What is the command line to do just one jar file?
And what did you want CLASSPATH to be?
There are many jar files, also I will need to use this script to set another jar files in other directories, if I had to do it manually it would be to MUCH. I want to have a local variable like the following:

SET DIR = /PATH/TO/LIBRARIES/
SET CLASSPATH=%DIR%lib1.jar;%DIR%lib2.jar;%DIR%lib3.jar;....;%DIR%libn.jar

The command I want to set after setting this variable is:

javac -target 1.X -classpath %CLASSPATH% %SOURCES%would the problem be delayed expansions?

If it is do the following:

- at the beginning of the batch file (before using the variable CLASSPATH) set the local variable EnableDelayedExpasion.
- Then, when referring to the variable use !var! instead of %var%.

SEARCH for more information.

Hope this helped;

Two-Eyes %OK. But you did not say how many. We need to know. There is a practical limit. Two practical limits.
1.) you can only have so much in one variable.
2.) In a huge process there has to be some kind of error recover.

If you have a massive job that has not already been tested, you avoid putting it in a loop. Professional programmers have the habit of writing 40 lines of commands for a batch file rather that put it in a FOR loop. They use the FOR loop for things they know will work well. But students and amateurs don't. They enjoy the challenge of using a shortcut even when it makes the job harder, longer, and pointless.

My recommendation, based on experience and observation, is use the FOR loop to create a long list of compiler commands that will compile each file one at a time. later. Maybe something like this:

Quote

javac -target 1.X -classpath D:\old\java2.jar
javac -target 1.X -classpath D:\new\java2.jar
javac -target 1.X -classpath D:\old\donut.jar
javac -target 1.X -classpath C:\fire\water.jar
...
You could call it MyBigJob.bat and if it does not work right, edit it with Notepad using global replace command.
The objective is not to see how concise you can make the job,
but how you can do the job right.

Is this of any help?
But if somebody else has a good answer, that's fine with me.
2684.

Solve : move file from server to server?

Answer»

I need a batch file that will copy a file from serverA location to SERVERB location

I think I need the NET use command. Map a temporary path to both servers copy the file then REMOVE the mappings? Am I on the right track?

file name is datafile.csv

file is on serverA
I want to set a scheduled TASK to run a batch every MORNING that copies serverA c:\data\monthly\datafile.csv to serverB c:\department\monthly\today\datafile.csv

Thank you for your help. It is much appreciated.
Tina

2685.

Solve : Boot time assistance?

Answer»

Hello everyone!
I have a good one this time that i need a bit of assistance with. I am looking to create a VBS or BAT file that will ask me for the computer name. Then once the computer name is entered it will return the boot time. Has anyone created this file yet? I WOULD modify the VBS i use to find out the logged in user i just dont have time as i am slammed with other projects here at work, and i am not too familiar with VBS. Below are some examples...

Return remote boot time via command prompt ... simply change "PCNAME" to the correct computer name.
Code: [Select]Systeminfo /S PCNAME| find "System Up Time"

This VBS will ask you for the PC name, then tell you who is logged in
Code: [Select]strComputer = InputBox("What is your computer name? ie WSCI320CXXX:")
Wscript.Echo "The name you entered was " & strComputer
'WScript.echo "The user name will appear in seconds!"
On Error Resume Next 'continue when an error occurs
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
Wscript.Echo "There was a problem locating the computer."
Wscript.quit
End If
On Error GoTo 0
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colComputer
Wscript.Echo "Logged-on user: " & objComputer.UserName
Next
As always, your help is greatly appreciated.

-HoFL
Actually theres a built-in Batch variable for the computer name

Code: [Select]Systeminfo /S %COMPUTERNAME% find "System Up Time"
Hope this helps
,Nick(macdad-)That does help a bit, but that would mean i would have to run it on the local PC. Unfortunately that wouldn't be an option in this case. We are finding our users are waiting over 1 and 2 months to restart their computer. This is causing issues with their daily operations. We want to be able to check how long it's been in between boots to confirm what they are telling us before running around the campus to restart a computer. Is there a way i can create a prompt in a BAT file that will allow me to input the computer name, then have it insert in a variable field of the code?Download the uptime utility from microsoft:

http://support.microsoft.com/kb/232243

You can pass this utiility a computer name.

()d:\>uptime /?

UPTIME, Version 1.01
(C) Copyright 1999, Microsoft Corporation

Uptime [server] [/s ] [/a] [/d:mm/dd/yyyy | /p:n] [/heartbeat] [/? | /help]
server Name or IP address of remote server to process.
/s Display key system events and statistics.
/a Display application failure events (ASSUMES /s).
/d: Only calculate for events after mm/dd/yyyy.
/p: Only calculate for events in the previous n days.
/heartbeat Turn on/off the system's heartbeat
/? Basic usage.
/help Additional usage information.
I appreciate your post. The line below will remotely GET the boot time for me just fine. I just want a way i only have to doubleclick the VBS or BAT and enter the name of the computer i want to know about. I was just trying to make it so i don't have to type or copy and paste the line each time i want to get a PCs boot time.

Code: [Select]Systeminfo /S PCNAME| find "System Up Time"I have done some more research and found what i was looking for... I hope you GUYS ENJOY this...just save it as a VBS file.

Code: [Select]Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

strComputer = InputBox ("Enter Machine Name")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objSWbemDateTime.Value = objOperatingSystem.LastBootUpTime
MsgBox "Last Boot Time For " & UCase(strComputer) & " Was: " & objSWbemDateTime.GetVarDate(False)
Next

2686.

Solve : start exe by vbs?

Answer»
Hi All,

Is it posiple to start the.exe file by VBS command?

what is the code? and how to disable it?
thanksQuote from: tabehsn on October 20, 2009, 07:02:05 AM
Hi All,

Is it possible to start the.exe file by VBS command?

what is the code? and how to disable it?
thanks

Which .exe file? An .exe file can be a program or a process?

You may run .exe file from a batch file when you KNOW the complete path to the .exe file. Or the .exe is INCLUDED in the search path.


C:\>path
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Co
mmon Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10
.0\DLLShared\;c:\bin

C:\>On my XP pro machine there are 2,123 .exe files.


C:\>dir /B /S *.exe | wc -l
2123

C:\>



C:\WINDOWS\system32>dir /B /P *.exe
accwiz.exe
actmovie.exe
ahui.exe
alg.exe
append.exe
arp.exe
asr_fmt.exe
asr_ldm.exe
asr_pfu.exe
at.exe
atmadm.exe
attrib.exe
auditusr.exe
autochk.exe
autoconv.exe
autofmt.exe
autolfn.exe
blastcln.exe
bootcfg.exe
bootok.exe
bootvrfy.exe
cacls.exe
calc.exe
charmap.exe
ChCfg.exe
chkdsk.exe
chkntfs.exe
cidaemon.exe
cipher.exe
cisvc.exe
ckcnv.exe
cleanmgr.exe
cliconfg.exe
clipbrd.exe
clipsrv.exe
cmd.exe
cmdl32.exe
cmmon32.exe
cmstp.exe
comp.exe
compact.exe
conime.exe
control.exe
convert.exe
Press any key to continue . . .
Quote
Is it posiple to start the.exe file by VBS command?

You can use the Run method of the shell object:

Code: [Select]Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "c:\windows\system32\programname.exe",,True

Note: The True parameter indicates to wait on return. In other words, wait until the program finishes executing before continuing with the NEXT instruction.

Quote
and how to disable it

Not sure you can. It's part of the VBSCRIPT instruction set.

Good luck.C:\>type cal.bat
@echo off
calc.exe

REM full path :C:\WINDOWS\system32\calc.exe
C:\>cal.bat


______________________

Disable calc.exe by renaming calc.exe or delete calc.exe


C:\>ren /?
Renames a file or files.

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your DESTINATION file.

C:\>cd C:\WINDOWS\system32

C:\WINDOWS\system32>ren calc.exe xxcalc.exe

Thank you bro billrich and sidewinder
2687.

Solve : Printing MS-DOS to a USB port?

Answer»
Hi group,

I have 2 tower PC,s windows 95 & XP and I can print with the command dir>prn (LPT1) but they are connected with a parallel LPT1 port. My DOS for Dummies book shows how to get a printer working on a serial port but only mentions USB as an aside comment.
How do I get to print straight from my laptop via USB WHILST using MS-DOS.
I print out directories. I know I can copy and paste into Wordpad but not a directory with more than 250 entries.
HELP !!!!!!!



Best wishes


Dave Edwardsbut you could CREATE a file with the directory and open and print with word pad.....

dir > dir.txt
Hi Gary,

Didi what you said with my largest directory 12,000 plus and it worked. I had to search for it however. I then changed it to dir>dir.rtf and it opened in wordpad but I had to search again for it. It goes to a long long named folder because thats the folder the command prompt opens in. It's Documents and Settings\Dave Edwards\Desktop\name of file. Is there a way of me getting it to say My Briefcase which I have on the desktop with not much in.
Many thanks for your help.




Best wishesDon't remember much about the briefcase but you can put it anywhere you want, just specify the path....

dir > c:\dir.rtf
dir > c:\desktop\dir.rtf (maybe that was c:\windows\desktop)Can anyone describe a solution for such problem more in details? My mother has an old dos application and she want to use it on her new notebook with Windows XP SP3. DOS program works but it prints nothing on the USB printer now. This doesnt always work with DOS programs, but might be worth a shot and its redirecting the LPT communications through USB via a network shared printer. You dont even need a network to make this happen, just need to create the network share and then create the LPT1 redirect to the USB printers \\computername\sharedprintername and it might work for you.

Here is the link SHOWING how to do this: http://support.microsoft.com/kb/103938sorry to be a pain, but I have read forums and not found answer, I have a similar problem. My work computers run Vista but my main accounts program is a very old dos based program written in pascal. I need the speed of the modern computers to run the rest of my one person business, but I need the dos program for twenty YEARS of records! I have to date , been able to install pci parallel cards to run the two printers used in the accounts program because I can't get the program to use usb printers. I can see a time when parallel cards will not be available (they are hard enough to find now), so how can I get the program to use usb ports, or is this not possible?This thread is VERY old. If you have a problem, please make your own thread. Ok, I still have a problem since I'll create new thread with the same question. Thank you.
2688.

Solve : Batch scripting - Extracting block of data from text lines?

Answer»

Win XP HE SP.3+ Cmd.exe BATCH scripting.

I want to be able to extract the first n items of data from .Csv files hopefully without having to specify each item, i.E. specify the ENTIRE block rather than individual items.

The following script shows what I use and what I'd like to use to extract the leading 30 entries in the text line, can the Echo or any other command do this?

Note: A small .csv file will be created in your Temporary folder to facilitate running the script, it will be deleted on completion of the script.. If you do not want this facility to be used PLEASE do not run the script.

Current script:
Code: [Select]@echo off
cls
setlocal enabledelayedexpansion

:: Create csv file..
for /l %%a in (1,1,80) do (
set column=!column!Col.%%a,
)
set column=!column:~0,-1!
echo !column!>%temp%\column.csv

:: Extract leading 30 columns..
for /f "tokens=1-30* delims=," %%A in (%temp%\column.csv) do (
set column01-30=%%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,%%I,%%J,%%K,%%L,%%M,%%N,^
%%O,%%P,%%Q,%%R,%%S,%%T,%%U,%%V,%%W,%%X,%%Y,%%Z,%%[,%%\,%%],%%^^
)

echo %column01-30%
del %temp%\column.csv


Wannadoo script:
Code: [Select]@echo off
cls
setlocal enabledelayedexpansion

:: Create csv file..
for /l %%a in (1,1,80) do (
set column=!column!Col.%%a,
)
set column=!column:~0,-1!
echo !column!>%temp%\column.csv


:: Extract leading 30 columns..
for /f "tokens=1-30* delims=," %%A in (%temp%\column.csv) do (
set column01-30=%%A thru' %%^^
)


echo %column01-30%
del %temp%\column.csv

2689.

Solve : incorrect ms-dos versioni?

Answer»

You can try.
I get the microsoft wnidows 98 STARTUP menu. the command prompt only i receie the c:\> when I put the format c : . I RECEIVE bad command or file name. I do not have bootable disk.I LOOK in boot disk .com not sure what boot disk for window98 to DOWNLOAD. ALSO I do not have a floppy drive I would have to download on cd. The lap top has both.

2690.

Solve : Search subfolders for filename!?

Answer»

Hey GUYS!

- I hope someone is able to answer this.


I'm trying to create a batch program which can sort my music library. So far I've come up with this code:

Code: [Select]:A
set /P ARTIST1=Artist 1:
if exist *%ARTIST1%*.mp3 (
md C:\Users\%username%\Desktop\TEST!\"%ARTIST1%"
xcopy "C:\Users\%username%\music\*%ARTIST1%*.mp3" "C:\Users\%username%\music\%ARTIST1%"
DEL *"%ARTIST%"*.mp3
If %antal%==1 goto A

I've placed this file in my music folder - and the problem is that this file only searches the music folder - but not all of my subfolders.

How can i make the batchfile search BOTH the music folder and all subfolders for the artist name? Search current directory and subdirectories with dir /s *.mp3

C:\>dir /?

/S Displays FILES in specified directory and all subdirectories.



%homepath%\My Documents>dir /s *.mp3

Directory of %homepath%\My Documents\My Music

04/05/2009 04:49 PM 311,257 reveille.mp3
06/24/2008 12:34 PM 168,064 TAPS.mp3
2 File(s) 479,321 bytes

Directory of %homepath%\My Documents\My Music\iT
unes\iTunes Music

04/05/2009 04:49 PM 311,257 reveille.mp3
10/19/2009 04:14 PM 172,129 TAPS.mp3
2 File(s) 483,386 bytes

Total Files Listed:
4 File(s) 962,707 bytes
0 Dir(s) 304,299,802,624 bytes free

%homepath%\My Documents>

2691.

Solve : Backup a couple of directories using a batch file?

Answer»

Hello guys!

First of all - sorry if this has been asked before (I did search but probably just couldn't figure out the right terms to use) and also sorry if what I'm about to ask is stupid-simple to create, but unfortunately my level of experience in DOS isn't that big - I only know a few basic commands, and some basic knowledge from Unix shell.

OK. So I backup daily a couple of directories by zipping them onto my Flash Drive, without deleting the old files, but instead adding a following (+1) number to the name of the zip archive.

So I was wondering, since after a few hundred of these operations it gets REALLY irritating, is there a way to automate that task with a batch FILE, that I would only have to click on and it will do the REST for me (well, that's actually a RHETORICAL question - I'm pretty sure a simple operation as this is perfectly possible, I'm just too dumb to know how).

Thank you all guys!You just need to use XCOPY and since your copying it onto your Flash drive, I suggest just storing the batch file on the drive.

Code: [Select]@echo off
if not EXIST BackupBat.inf (echo. 1 > BackupBat.inf)
for /f %%a in (BackupBat.inf) do (
rd Backup%%a
set /a count=%%a+1
md Backup%count%
)
del BackupBat.inf
echo. %count% > BackupBat.inf
xcopy "C:\SourceDir\*.*" "Backup%count%" /E
echo.Backup Done
pause
NOTE:This will create a seperate file to keep track of the Backup Count, if this file is Deleted then it'll rewrite the First backup folder made.

Hope this helps
,Nick(macdad-)Thanks Nick!

It works, but it's not quite what I had in mind.

I have these directories:

E:\SomeDir
E:\SomeOtherDir

And I want to do the following with them:

ZIP E:\SomeDir to X:\backup\SomeDir112.zip
ZIP E:\SomeOtherDir to X:\backup\SomeOtherDir112.zip

Then the next time I do it it'll be X:\backup\SomeDir113.zip & X:\backup\SomeOtherDir113.zip and so on.Oh the ZIP command

Atleast you found the slip-up OK. Sorry for reopening this and bothering you again, but I've been trying to find out how to install a ZIP compressor for DOS and I just can't find anything.There are some compressors/decompressors that work from the command-line. Quote from: Helpmeh on October 18, 2009, 06:07:13 AM

There are some compressors/decompressors that work from the command-line.
Can you tell me how to find out if I have any and how to execute them?Google for 7-zip
Quote from: Salmon Trout on October 18, 2009, 09:43:58 AM
Google for 7-zip


Thanks a lot mate! That worked truly great!!! Problem with backup is solved now!
2692.

Solve : HELP(ADV): Batch file - rename file to directory name+++?

Answer»

I want to specify a folder in the batch file (ie. C:\Users\intellilogic\Documents\TopFolder) and have it take all the files and subdirectories in it and rename the files, appending there parent directories to the name and movie them to the root folder specified. I want to do this unlimitedly deep, but only renamed the files to its parent and then moving them all the way to the root. Ideally, I would like to avoid duplicate file names, so if duplicate files come about, appending a number to them would work well.

After doing all the renaming and moving, a confirmation of: “Check to make sure all the files successfully have been moved to the root before selecting yes. Would you like to delete all of the child folders now? (Y/N)” Then if I select yes, deleting all of the child folders that are ACTUALLY empty of files, ignoring blank directories, if they aren’t empty, don’t delete them. Assuming it ran correctly, they will be empty and all subdirectories will be cleared, leaving the root folder with just the renamed files.

Example:

[TopFolder]
[Folder1]
- File1.bla
- File2.bla
- File3.bla
[Folder2]
- File1.bla
- File2.bla
- File3.bla
[Folder3]
- File1.bla
- File2.bla
- File3.bla
[SubFolder1]
- File1.bla
- File2.bla
- File3.bla

Transformed into all files under the root folder

TopFolder
Folder1-File1.bla
Folder1-File2.bla
Folder1-File3.bla
Folder2-File1.bla
Folder2-File2.bla
Folder2-File3.bla
Folder3-File1.bla
Folder3-File2.bla
Folder3-File3.bla
SubFolder1-File1.bla
SubFolder1-File2.bla
SubFolder1-File3.bla

For stuff like this:


Thanks in advanced =]Good Luckfirst i would like to say that bill is making an effort at a joke, we don't charge at all!.

now i will continue with the creation of the script Hehe - I wouldn't think there would be a charge, I am currently broke anyhow, haha.

Thanks peace man =]Quote from: BatchFileBasics on September 30, 2009, 08:56:21 PM

first i would like to say that bill is making an effort at a joke, we don't charge at all!.

now i will continue with the creation of the script

teach him how to fish, not fish for him.Peace.Once I have the file, i will look at the code and learn it that way, it's like watching Jesus fish... =-0Why not break the job into smaller taks?
Do you have plenty of disk space?
First GENERAL rule is not to put stuff into the root.
Why do you want us to bend this rule?
How about a directory called
D:\BOGUSROOT

Quote from: billrich on October 01, 2009, 07:52:41 AM
How did Jesus feed the mulitude? Jesus fed the people fish. Jesus did not teach them to fish.
can you ask Jesus, whoever he is, to GIVE you a fish now? tell him to drop the fish from the SKY.. if you can do that, i will treat you to a cup of coffee. Bye@bill, stop babbling nonsense. Quote from: Geek-9pm on October 01, 2009, 12:12:00 PM
Why not break the job into smaller taks?
Do you have plenty of disk space?
First general rule is not to put stuff into the root.
Why do you want us to bend this rule?
How about a directory called
D:\BOGUSROOT



Sorry - I meant the root from which you start from, IE the top folder.OK you can use this as a starting PLACE.


Code: [Select]@ECHO OFF
CLS

REM THIS WILL SCAN THE CURRENT FOLDER AND RETURN SUB-FOLDERS TO A TEXT FILE
CD %CD%
DIR /b /s /ad>"%TEMP%\DIRTEST.TXT"

REM USE DIRTEST.TXT IN A FOR LOOP
FOR /f "delims==" %%A in (C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp\DIRTEST.TXT) DO SET A=%%A& CALL :DIR %%A


CLS
IF EXIST "%TEMP%\DIRTEST.TXT" DEL "%TEMP%\DIRTEST.TXT"
IF EXIST "%TEMP%\DIRFILE.TXT" DEL "%TEMP%\DIRFILE.TXT"
ECHO JOB COMPLETE.....
Pause
GOTO END

:DIR

REM THIS WILL SCAN THE CURRENT FOLDER AND RETURN FILES TO A TEXT FILE

CD\
CD "%A%"

DIR /b /a-d>"%TEMP%\DIRFILE.TXT"

REM USE DIRTEST.TXT IN A FOR LOOP
FOR /f "delims==" %%A in (C:\DOCUME~1\%USERNAME%\LOCALS~1\Temp\DIRFILE.TXT) DO SET FILE=%%A& CALL :DIRFILE %%A

:DIRFILE
ECHO %FILE%
PAUSE

:END


Please let me know if this dose not work for you.This looks very helpful, I will play with it - I think I will start at the top w/
IF EXIST "%TEMP%\DIRTEST.TXT" DEL "%TEMP%\DIRTEST.TXT" JIC =]
Can I take a stab at this using a SCRIPTING approach ? Comments are inserted so you can see what the script is doing line by line.

Code: [Select]##############################################
# Script: tf.txt (Not sure what to call it)
##############################################
# Usage: script tf.txt root("C:\Users\intellilogic\Documents\TopFolder")
##############################################
# Script moves all files in the root folder (and its sub and sub-sub folders)
# to the root folder with the parent folder name prepended to file name.
#
# For example, if root is "C:\Users\intellilogic\Documents\TopFolder",
#
# the file C:\Users\intellilogic\Documents\TopFolder\Folder1\File1.bla
# will be moved to
# C:\Users\intellilogic\Documents\TopFolder\Folder1-File1.bla.
#
# File C:\Users\intellilogic\Documents\TopFolder\Folder3\SubFolder1\File1.bla
# will be moved to
# C:\Users\intellilogic\Documents\TopFolder\SubFolder1-File1.bla.
##############################################

# Input argument.
var str root # This value is passed to the script.
# If not assigned, current folder will be used.

# Go to root folder.
cd $root

# Collect a list of all flat files.
var str list ; lf -rng "*" "." ($ftype=="f") > $list

# Loop thru files.
while ($list <> "")
do

# Get the next file.
var str file ; lex "1" $list > $file

# $file has the full path. Get just the file name. It is after the last /.
# Preserver value in $file. We will need it in move command later.
var str name ; stex -p "^/^l[" $file > $name

# Get the parent folder of the file. It is between the last and
# secondlast /.
var str parent

# Get the portion of $file upto the last /.
stex -p "]^/^l" $file > $parent

# $parent now has full path of parent folder.
# Get just the folder name. That's after the last /.
stex "^/^l[" $parent > $parent

# The new file name is now $parent-$name.
# We want to move the file to $root/$parent-$name.
system -s "move /Y" ("\""+$file+"\"") ("\""+$root+"/"+$parent+"-"+$name+"\"")

done



Script is in biterscripting ( http://www.biterscripting.com ) . But you should translate it to any scripting language of your choice or batch commands. I have added comments for that. (The script just looks bigger because of all the comments and beautification.)


2693.

Solve : ms-dos shorthand command help needed?

Answer»

Can someone point me to MS-DOS documentation that explains what is happening on LINE 5? Kind of hard to search for ":~" and find anything helpful.

for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set MDATE=%%c%%a%%b
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set MM=%%a
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set DD=%%b
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set YY=%%c
IF %MM:~0,1%==0 SET MM=%MM:~1%
IF %DD:~0,1%==0 SET DD=%DD:~1%
set cdate=%MM%-%DD%-%YY%you can find info on this is you type set /? in a cmd window.


%PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11TH (offset 10) character of the expanded
result. If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.

%PATH:~-10%

would extract the last 10 characters of the PATH variable.

%PATH:~0,-2%

would extract all but the last 2 characters of the PATH variable.



so in your case the line in question is saying if the first character of the variable %MM% is equal to 0 then set %MM% to the second character only.

This is useful if you are doing math because batch interprets a leading zero to be a octal number. Quote from: fossowat on October 16, 2009, 01:32:02 PM

Can someone point me to MS-DOS documentation

(1) This is not "MS-DOS". It is WINDOWS NT family command script. Specifically Windows 2000 and later.

(2) set /?

(part)

CODE: [Select]...specify substrings for an expansion.

%PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result.
2694.

Solve : Logging batch completion question?

Answer»

First off let me thank all of the guys posting answers on this forum. I have found many answers to my never ending questions.

I have one that I can't track down.

I have a batch file that copies a file to a backup directory adding the date and time to the file then runs a macro from within Access to update a database file. Finally it ftp's the updated MDB file to a webserver. Once this is done I write a text string to a log file stating that on this date at this time the mdb file was updated and the backup file is now originalfileName_datetime.mdb. Currently the NEW log file entry is written to the end of the file thus putting it at the bottom of the list. The purpose of this log file is that if needed I want to open the file and see the latest backup file but I don't want to have to scroll all the way to the end. I know it's LAZY but hey - isn't that why they invented these silly things in the first PLACE? Thanks again guys.

BTW - I've INCLUDED the line that writes the log entry to my log file. I created the variable nDate and nTime as I wanted to use the same date and time used in the renaming of the database file in the log entry but I've already stripped out the "/" and ":".

>> dblog.txt echo -- %nDate% - %nTime% sellsheet table updated and posted to kcboxman.com. Current backup file is kcboxman_%fDate%%fTime%.mdb.Use a FOR loop.

Echo YOUR INFO HERE >logtemp.txt
For /f "delims=" %%a in ('type logfile.log') do echo %%a >>logtemp.txt
type logtemp.txt > logfile.log
del logtemp.txt


Try that. Excellent! That worked perfectly and gave me just what I needed. Now I can preserve the update activity but if something happens I don't have to scroll to the bottom of a huge file to get the file name. I really appreciate it.

JimNo problem. You won't be able to use your current log file, as it will get messed up date-wise somewhere in the middle.

2695.

Solve : Newbie BAT file problem?

Answer»

Hi everyone,
I could use some pointers with an issue I have..

I am trying to do the following (I believe my logic is correct)...

1.) Create a BAT file to run during Windows Startup

2.) Within the BAT... Search a directory for a file (The file name is not the same every time - for example, Background1-002, Background1-628)

3.) If the file contains text 'ABC', reboot a Windows service. If not, do nothing.

I have look AROUND on this excellent site and found some GREAT resources to do the things I would like to do. I do have a few questions...

How do I search a file directory to find a specific file name that constantly changes (Step 2)? Can I use some sort of wildcard search since the beginning of the filename will constantly be the same? Sorry, my boss dumped this on me and I only have limited programming experience.

THANK you everyone for your help in advance!


HelloC:\>type findstring.bat
Code: [Select]@echo off

cd \

findstr /s "ABC" Background1*


findstr /s /m "ABC" Background1* > foundfile.txt


for /f "delims==" %%a in (foundfile.txt) do (

echo %%a
REM NET START "Error Reporting Service"


)
pauseREM the pause is necessary when run at startup time.


C:\>findstring.bat
GROUND\Background1-002:ABC
ground\Background1-003:ABC
ground\Background1-010:ABC
ground\Background1-002
ground\Background1-003
ground\Background1-010
Press any key to continue . . .

Output at Startup Time:

HelloThanks Bill. Could you help explain some of the code for me...

I have a basic idea, but I am new to this...

Code: [Select]@echo off

findstr /s "ABC" Background1*

findstr /s /m "ABC" Background1* > foundfile.txt


for /f "delims==" %%a in (foundfile.txt) do (

echo %%a
REM NET START "Error Reporting Service"

)
So, I am going to do a FindString in the Background.log file looking for ABC. If ABC appears, send it to the foundfile.txt. Then there is a loop that will start the services for each instance that comes back with ABC?

My boss actually MADE life a little easier for me. I can rename or move all of the older log files, so that the script will just search the folder for 1 .log file... would this code still provide the same results?

Thanks again for your help with this."So, I am going to do a FindString in the Background.log file looking for ABC. If ABC appears, send it to the foundfile.txt. Then there is a loop that will start the services for each instance that comes back with ABC?"

Yes, that is how it works. I did not test the start service line. I was not sure which service you planned to start. A REM ( remark ) at the beginning of the line will not allow the code to execute. As it is written the start service will execute each time ABC is found. ( might not harm ... a message will appear that it is already running )

The script will run the same if there is one or several "ABC" strings.

Good LuckHow do I specify the folder to do the Findstr command in? The files are only located in 1 folder, so it would make life a little easier to just have the batch file look in 1 location.. cd to the folder where the file is stored and remove the /s option from the findstr command. cd means change directory. A directory is the same as folder in windows.

For example:

C:\>cd ground

C:\ground>cd
C:\ground

C:\ground>findstr "ABC" background1*
Background1-002:ABC
Background1-003:ABC
Background1-010:ABC

C:\ground>


C:\>help cd
Hi Bill. Thank you for all your help. This will help me get started on solving the issue at hand.
The following findstr from the root directory will find the file( Background1*) on any machine.


C:\>cd \

C:\>findstr /s /m "ABC" Background1* > foundfile.txt

C:\>

I have no idea where the Background1* files are stored on your machine.

Quote from: seekupdmb5 on October 14, 2009, 07:32:58 AM


I am trying to do the following (I believe my logic is correct)...

1.) Create a BAT file to run during Windows Startup


To have a program run at startup time, the program must be placed in the startup folder:

C:\>cd %homepath%\Start Menu\Programs\startup

copy c:\findstring.bat .

( The "." above says copy to current directory. )

http://www.microsoft.com/windowsxp/using/setup/hwandprograms/autorun.mspx


To configure a program to start automatically

1.
Right-click Start, and then click Explore. Windows Explorer opens and displays your Start menu.



2.
In the left pane, click Programs. Browse to find the program you want to automatically open. In the right pane, right-click the program, and then click Copy.



3.
In the left pane, click Programs, right-click Startup, and then click Paste.



4.
Repeat steps 2 and 3 to add more programs to your Startup group.


The programs you add to the Startup group will start automatically the next time you log on to your computer.


Top of page
I tested the start service with the net command. It worked as expected. The first loop said we were able to start the service. The next two loops said the service was already working.


C:\>type findstring.bat
Code: [Select]@echo off

cd \

findstr /s "ABC" Background1*


findstr /s /m "ABC" Background1* > foundfile.txt


for /f "delims==" %%a in (foundfile.txt) do (

echo %%a
NET START "Error Reporting Service"


)
pause
REM the pause is necessary when run at startup time.


OUTPUT:

C:\>findstring.bat
ground\Background1-002:ABC
ground\Background1-003:ABC
ground\Background1-010:ABC
ground\Background1-002
The Error Reporting Service service is starting.
The Error Reporting Service service was started successfully.

ground\Background1-003
The requested service has already been started.

More help is available by typing NET HELPMSG 2182.

ground\Background1-010
The requested service has already been started.

More help is available by typing NET HELPMSG 2182.

Press any key to continue . . .
2696.

Solve : how to run a basic goto program?

Answer»

hello,im blocc. my ? is way BACK in the 80's i use to run this program on computers in school. 10 rem 20 print "blocc" 30 goto 20 and then hit run or enter. it WOULD scroll across the screen and depending on how u PUT the name or anything there how it would cross the screen. as well as change and color. i would love to run this on windowsxp but do not KNOW how as far as the cmd i think is not the same. what do i need to run this? if someone could HELP me out thanks.

2697.

Solve : MS-DOS Installation?

Answer»

hey, im Tony, im having sum trouble with the installation of DOS... i have it on my home computer, but im trying to install it @ school... it sayz i need a DISC, but i got the one @ home without one.... how can i install it without a disc? plz help
-Tony A.K.A. DruizziHi Tony, WELCOME to the CH forums.

Quote

but im trying to install it @ school

Forum rules prevent us advising on this as you might breach your school's security rules by installing on their system. Please consult your tutor/school IT specialist.

Good luck.I am a school computer programmer, my boss says if its blocked dont mess with it.... i just want to have it for the use of it on my, single computer..... please help, it would make my job soooooooooo much easier...You need the 4 floppy DOS DISKS to install it...
You can't simply MOVE it to another machine and make it work.All school PCs have a command prompt where the student is allowed to use commands that are similar to but better than the 1981 DOS machine.Bootdisk.comQuote from: billrich on October 14, 2009, 02:03:51 PM
All school PCs have a command prompt where the student is allowed to use commands that are similar to but better than the 1981 DOS machine.

No. Some schools block command prompt.I like the assumption that ALL school PC's are the same....
Wish i would have gotten that winning bid...i'd be out to pasture.If the school blocks CMD in the first place then don't install anything, you'll GET busted.
2698.

Solve : for loop runs twice?

Answer»

I have an issue where a for loop from a previous post is running twice. I am trying to get the file properties from the current directory and all sub directories. The only issue is that I am getting double results in my out put file. The issue is some where in the below code.

Code: [Select]ECHO Working with %CD%^\%FILE%

set fname=%FILE%

dir %fname% > dir.txt

for /f "skip=4 tokens=5" %%v in (dir.txt) do (
SET PS=%%~dpnxv
SET FS=%%~zv
SET FMDT=%%~tv
GOTO NEXT
)

:NEXT
echo Path Specification: %PS%>>"%userprofile%\Desktop\FileProps.csv"
echo File Size: %FS%>>"%userprofile%\Desktop\FileProps.csv"
echo File Modified Date/Time: %FMDT%>>"%userprofile%\Desktop\FileProps.csv"
echo =================================================================>>"%userprofile%\Desktop\FileProps.csv"
echo =================================================================>>"%userprofile%\Desktop\FileProps.csv"

Pause

del dir.txt


The Fileprops.csv looks like the following:

Path Specification: C:\WINDOWS\system32\XPSViewer\fileProps.bat
File Size: 2026
File Modified Date/Time: 10/14/2009 08:10 AM
=================================================================
=================================================================
Path Specification: C:\WINDOWS\system32\XPSViewer\fileProps.bat
File Size: 2026
File Modified Date/Time: 10/14/2009 08:10 AM
=================================================================
=================================================================



Thanks,
WayneI notice you are using the append redirection symbol >> to write to the csv so each time you run the batch the csv will get bigger. Also take out the GOTO NEXT. You do not need that, nor the :next label.
Quote from: Salmon Trout on October 14, 2009, 10:21:10 AM

I notice you are using the append redirection symbol >> to write to the csv so each time you run the batch the csv will get bigger. Also take out the GOTO NEXT. You do not need that, nor the :next label.


the >> is so the file will be appended to. with out that the file would be recreated each time. That would be fine except this will be ran on all sub directories.

the goto was to try and force it to leave the loop without going through it twice. That is the issue I am trying to FIX now. The loop SEEMS to be picking on on the next LINE of the dir.txt. I have also tried to make it create the csv in the for loop and I still have the loop executing twice. Any ideas on how to fix it?

Thanks,
WayneIf there are 2 lines in the dir.txt then the loop will execute 2 TIMES. Investigate why the dir.txt has 2 lines. Also your "tokens=" block is redundant.
yes well is there a way to to only have it run on the 5th line and not the 6th and 7th? Code: [Select]
setlocal enabledelayedexpansion
set line=1
for /f "delims==" %%v in (dir.txt) do (
if !line! EQU 5 (
SET PS=%%~dpnxv
SET FS=%%~zv
SET FMDT=%%~tv
)
set /a line+=1
)

2699.

Solve : Make Silent Installation?

Answer»
How to make silent INSTALLATION in batch ...

like i have setup.exe i want to INSTALL it silent so how i make batch programme that
install setup.exe SILENTLY...? ? ?I suggest you contact the system administrator at your school for HELP with thisA quote from Peter Grifin, "NO!". I suggest you read the rules Deadly D. Any GUESSES on what the 'D' stands for?
2700.

Solve : Help with Batch file creation?

Answer»

Code: [Select]if "%filedate%" == "%cdate%" goto run
if not "%filedate%" == "%cdate%" goto skip
Remove spaces in IF tests. They should not be there. You are comparing "%filedate%"[space] with [space]"%cdate%" which will never be true.
It must be me but my program is STILL not running as I would like it to run.
If the filedate is equal to the cdate then it should goto skip unfortunately whether the dates in either files are equal or not it still goes to run. Below is the corrected code what is wrong with it??


Setlocal enabledelayedexpansion
For /f "delims=" %%a in ('date /t') do set cdate=%%a
Set /p filedate=<%LOCDIR%\date.txt
ECHO %cdate%>%LOCDIR%\file.txt


if "%filedate%"=="%cdate%" goto skip
if not "%filedate%"=="%cdate%" goto run

:run
echo %PGRM% is updating to the LATEST version.
echo Please don't close window, the database will open once it has been updated.
copy %SRVDIR%\%PGRM% %LOCDIR%\%PGRM%
DEL %LOCDIR%\date.txt
echo %cdate% >> %LOCDIR%\date.txt
START /MAX %MSACC% %LOCDIR%\%PGRM%
goto end

:skip
echo Starting %PGRM%
START /MAX %MSACC% %LOCDIR%\%PGRM%
goto end
:endQuote from: LilG on October 14, 2009, 07:51:04 AM


Code: [Select]Setlocal enabledelayedexpansion
For /f "delims=" %%a in ('date /t') do set cdate=%%a
Set /p filedate=<%LOCDIR%\date.txt
Echo %cdate%>%LOCDIR%\file.txt


if "%filedate%"=="%cdate%" goto skip
if not "%filedate%"=="%cdate%" goto run <--------remove this line; it doesn't do anything.

:run
echo %PGRM% is updating to the latest version.
echo Please don't close window, the database will open once it has been updated.
copy %SRVDIR%\%PGRM% %LOCDIR%\%PGRM%
del %LOCDIR%\date.txt
echo %cdate% >> %LOCDIR%\date.txt
START /MAX %MSACC% %LOCDIR%\%PGRM%
goto end

:skip
echo Starting %PGRM%
START /MAX %MSACC% %LOCDIR%\%PGRM%
goto end
:end