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.

3401.

Solve : check to see if variable entered is .txt file?

Answer»

NewUser,

I changed the name of a personal.doc file to personal.txt

NOTEPAD would not open the personal.txt file.

Error message:

<<"The format must be ascii (text) before notepad can open personal.txt.

Changing the name of a file does not change the format.">>

Help?

p.s. When the Original Poster CHECKS for the .txt extension of a file, the .txt extension does not prove the file is a text file. So be careful.And that has what EXACTLY to do with the question, Bill? (I thought you were banned?)

Quote from: newuserlh on November 28, 2009, 08:15:12 AM

Like when the date variable has been CHECKED and is valid, I'd like to pass it back into the batch program.

Batch will check all dates and anything that needs to be done.

Vbs is not needed.

See post # 4Strongly suggest ignoring "Joanlong" who is a troll.


use a for loop
3402.

Solve : Please teach me more about 2>&1 for stderr Error Redirection?

Answer»

When I first saw "2>&1" on this site I thought it was an error, but quickly learnt about this new (to me) facility.

Now I actually want to use it, it fails to work as I expected/hoped for two commands on a line.

DIR *.DOC | FIND "/2009" >> RESULT.TXT
The above APPENDS to a file RESULT.TXT the details of files that match *.DOC,
or alternatively it puts on the console any stderr messages from DIR, such as "File Not Found".

I require that stderr should NOT appear on the console, and really want it to appear in RESULT.TXT.

DIR *.DOC >> RESULT.TXT 2>&1
This works exactly as I learnt/expected from last year.
It works like a charm on stderr - they appear in RESULT.TXT,
BUT RESULT.TXT also gets all the files from last year.

DIR *.TXT | FIND "/2009" >> RESULT.TXT 2>&1
If all is well then desired files (dated this year) are listed in RESULT.TXT.
If FIND is able to create stderr, that also may appear in RESULT.TXT
BUT UNFORTUNATELY any stderr from DIR now goes to console.

DIR *.TXT 2>&1 | FIND "/2009" >> RESULT.TXT
I "took a shot" and it worked, the console remained clean,
UNFORTUNATELY stderr from DIR was blocked by FIND from getting to RESULT.TXT

DIR *.TXT 2>> RESULT.TXT | FIND "/2009" >> RESULT.TXT
I "took a shot", but was rewarded on the console with
"The process cannot ACCESS the file because it is being used by another process."

IF EXIST ERROR.TXT DEL ERROR.TXT
DIR *.TXT 2> ERROR.TXT | FIND "/2009" >> RESULT.TXT
IF EXIST ERROR.TXT TYPE ERROR.TXT >> RESULT.TXT
That should achieve the end result, but I hate all the extra COMPLEXITY of two additional command lines, each with multiple commands, and it introduces more possibilities for stderr APPEARING on the screen (e.g. if ERROR.TXT is write protected, or if pernicous "PERMISSIONS" prevent successful access by an non-admin user.)

Advice upon improving the above code would be helpful for now, but I would really appreciate advice that is not specific to only "DIR | FIND ", but can be applied to any two (or more) "piped" commands

Regards
Alan
use findstr for 2 or more search conditions.

Code: [Select]D:\batch>date
The current date is: 27/05/2009
Enter the new date: (dd-mm-yy)

D:\batch>(dir not 2>&1 & dir *.ini 2>&1)|findstr/b "[a-z] [0-9]*/[0-9]*/2009"
File Not Found
17/05/2009 19:50 61 NOTES.INI
adjust findstr search condition to match your date formatThank you Reno

I was aware of Findstr a few years ago, and at the time I found no benefit in the extra complexity.

I now see the benefit, and your solution fully meets my immediate needs.

In the past I have done many strange things with various piped commands other than DIR and FIND. I am sure I will continue to do so ! !
For the future, I would appreciate any further advice on the use of 2>&1 or related mechanisms.

Again, thank you Reno

Regards
Alan
Feedback :-

I have found a solution to the error
"The process cannot access the file because it is being used by another process."

The first line of code below produces the error;
The error is cured by adding brackets as in the second line
Code: [Select]DIR *.TXT 2>> RESULT.TXT | FIND "/2009" >> RESULT.TXT
DIR *.TXT 2>> RESULT.TXT |( FIND "/2009" >> RESULT.TXT )

Regards
Alan

3403.

Solve : MS-DOS RmDir Command?

Answer»

Hello:

I have Windows XP SP3 operating system.

After a RMDIR command executes in my MS-DOS batch program, the rest of the MS-DOS commands after the RMDIR command do not execute. I don't know why.

Here is the directory structure that I have:

Folder 1\Folder 2\Folder 3
Folder 4
Folder 5
Folder 6
Folder 7
Folder 8
Folder 9
Folder 10
Folder 11

This is the RMDIR command that I coded in my MS-DOS batch program.

RMDIR /Q /S "C:\Folder 1\Folder 2\Folder 3"

When the RMDIR command executes, it deletes C:\Folder 1\Folder 2\Folder 3 and all the sub directories and files below it, which is what I want it to do, but then the rest of the commands after the RMDIR command in the batch file do not execute.

Does anyone know the reason for this?

Thanks for all your help!

Edward
Quote from: mellowco on May 26, 2009, 11:37:05 PM

Hello:

I have Windows XP SP3 operating system.

After a RMDIR command executes in my MS-DOS batch program, the rest of the MS-DOS commands after the RMDIR command do not execute. I don't know why.

Here is the directory structure that I have:

Folder 1\Folder 2\Folder 3
Folder 4
Folder 5
Folder 6
Folder 7
Folder 8
Folder 9
Folder 10
Folder 11

This is the RMDIR command that I coded in my MS-DOS batch program.

RMDIR /Q /S "C:\Folder 1\Folder 2\Folder 3"

When the RMDIR command executes, it deletes C:\Folder 1\Folder 2\Folder 3 and all the sub directories and files below it, which is what I want it to do, but then the rest of the commands after the RMDIR command in the batch file do not execute.

Does anyone know the reason for this?

Thanks for all your help!

Edward

What is the FULL code in your batch SCRIPT?Dear Helpmeh:

Thank you very much for your help.

After I received your reply, "What is the FULL code in the batch script", I did some more work on the problem, and I found out what was wrong.

The batch file that has the RMDIR command executes from one of the subdirectories that is being removed by the RMDIR command. When I execute my batch program from a different directory, the RMDIR command deletes properly the directory and the sub directories that I want, and then the rest of the MS-DOS commands after the RMDIR command execute as well.

Thanks again for all your help. It was very much APPRECIATED.

With very best wishes,

EdwardQuote from: mellowco on May 27, 2009, 08:43:00 AM
Dear Helpmeh:

Thank you very much for your help.

After I received your reply, "What is the FULL code in the batch script", I did some more work on the problem, and I found out what was wrong.

The batch file that has the RMDIR command executes from one of the subdirectories that is being removed by the RMDIR command. When I execute my batch program from a different directory, the RMDIR command deletes properly the directory and the sub directories that I want, and then the rest of the MS-DOS commands after the RMDIR command execute as well.

Thanks again for all your help. It was very much appreciated.

With very best wishes,

Edward
There, if you just leave it for a little while, come back later with fresh thoughts, you're bound to solve it! Feel FREE to stick around to help out other members, or get more help when needed!
3404.

Solve : copy files that created today?

Answer»

Hi Gurus,

I want to create a batch file and put in WINXP shecdule ,

THAT COPIES THE FILES THOSE ARE CREATED ON THE DAY WHEN THE BATCHFILE IS EXECUTED TO ANOTHER LOCATION.

Are all the files in one folder or spread around the file system?They are in one folder.method 1: use xcopy /d

method 2:use for loop & dir
Code: [Select]@echo off
for /f "skip=1 TOKENS=1-3*" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
if %%a==%date:~-10% (
echo %%a %%d
copy "%%d" "c:\backup\
) else goto:eof
)
method 3: use vbscript
Code: [Select]set fso=createobject("scripting.filesystemobject")
for each f in fso.getfolder(".").files
if datediff("d",f.datecreated,date())=0 then
wsh.echo f.datecreated,f
f.copy "c:\backup\"
end if
nextat cmd prompt, type cscript//nologo backup.vbsThanks, I used method 2.
But It gaves the message " The specified file cannot be found" . I have ATTACHED the screen shot.
What I need is :
Copy the ONLY THE file that created today to another folder.

[attachment deleted by admin]Code: [Select]copy "%%d" "c:\backup\"
Have you created the destination folder?

yes, i have created the destination folder c:\backupmy mistake, i didn't take account for time format "hh:mm am/pm"

updated code that support both 12h and 24h format:
Code: [Select]@echo off & setlocal
time/t|find "M" && set t=1,4* || set t=1,3*

for /f "skip=1 tokens=%t%" %%a in ('dir/a-d/tc/o-d^|find ":"') do (
if %%a==%date:~-10% (
echo %%a %%c
copy "%%c" "c:\backup\"
) else goto:eof
)I tried it , but still it is same.
Date format is the problem ?


[attachment deleted by admin]Quote from: kalmazz on May 23, 2009, 06:30:36 AM

I tried it , but still it is same.
Date format is the problem ?
no, i have take account for both date format, ddd mm/dd/yyyy or mm/dd/yyyy.

double check the code, try to copy & paste all the new code again at post#8. if your time format is 12h, it should display current time on the first line when the batch is executed.

additional check (type at cmd prompt):
Code: [Select]time/t
time/t|find "M" && (echo 12h) || echo 24hand tell me what the resultThanks,
IT IS DONE If you miss a day, you'll also miss copying some files because you're limiting your copy to just the files created "Today".

If you're using this batch file as a means of backing up critical data files, you might just want to use a BROADER criteria for the files being copied.

I use XCOPY to keep all my data files on C: backed up to D:

I just incorporated the XCOPY lines into my end of day shutdown script (batch file).

When done properly, with the correct SWITCHES, xcopy copies only files that are either new or have been updated since the last backup.
My batch file looks something like this:

Quote
@Echo off
cls
Rem Backup My Documents and all sub-folders/files.
xcopy "C:\Documents and Settings\Alex\My Documents\*.*" "D:\My Documents\" /s /y /H /R /D

Rem Back up my WordPerfect files.
xcopy "C:\MyFiles\*.*" "D:\MyFiles\" /s /y /H /R /D

Rem Back up all the files for My Web Page.
xcopy "C:\My web page\*.*" "D:\My web page\" /s /y /H /R /D

Rem Back up my email folders.
xcopy "C:\Documents and Settings\Alex\Local Settings\Application Data\Identities\{CC1A6FC7-0D07-4169-865D-56EBDD76EB8B}\Microsoft\Outlook Express\*.dbx" "D:\MyEmailFiles-Backup\" /s /y /H /R /D

Rem When the backup is done...Shutdown!

%windir%\System32\shutdown.exe -s -t 00 -f

On an average day, I may be backing up only one or two files, so the batch file runs and finishes in just a few seconds. It assures that I never shut down my PC with unsaved data files.
In this case D: is my backup hard drive.

Batch files can get really complicated or you can "KEEP IT SIMPLE".
Just add lines to accommodate any folders in your PC that contain valuable data.
That would be different for each person.

Even though I make a Ghost backup of my entire C: drive, at least once a week, my shutdown batch file assures that I keep all my data files backed up between Ghost backups.

So, don't loose your stuff to a HD crash.
Backup, Backup, Backup!!!

The Shadow

thanks for the REMINDER- I myself have been meaning to perform some file management. my 500GB drive is running out of space Thanks for your information on backups.
I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
How do I do it in a batch file ?

Quote from: kalmazz on May 27, 2009, 07:59:55 AM
Thanks for your information on backups.
I have a system that copies the backup files daily with different names on a folder. Ex. C:\BACKUPS.
I need to keep only last 7 days backup files and delete the previous days' file on daily basis.
How do I do it in a batch file ?
since this question is being ask a lot from day to day, here is an example .hta script.

this is my first hta script, so the code is messy & dirty.
i couldn't get the progressbar image to work properly and showing file being copied interactively.
feel free to modify the code in notepad, it is basically a vbscript wrapped inside html code.
WARNING: use at your own risk!!! test first on testing folder

[attachment deleted by admin]
3405.

Solve : for loop help?

Answer»

I am working on the following for LOOP.

Code: [Select]FOR /f "usebackq tokens=1-10" %%I in ("test.text") do (
SET I=%%I& SET J=%%J& SET K=%%K& SET L=%%L& SET M=%%M& SET N=%%N& SET O=%%O& SET P=%%P& SET Q=%%Q& SET R=%%R& CALL :xml %%I
)

the problem is that the loop only STARTS processing on the line with 10 ENTRIES.

EXAMPLE of test.txt:
i j k l m
i j k l
i j k l m n o p q r
i j k

the loop will start on line 3 and process from there. Is there a way to force processing from the first line?

3406.

Solve : How to extract zip file using inbuilt Dos command of Windows XP?

Answer»

Hi,

I would like to have dos command to extract zip files.
Note: i cannot use third party software like winzip and winrar.

For OS above XP 'compressed (zipped) FOLDER' facility is available, where you right click folder and click 'send to' -> ''compressed (zipped) folder', a zip file will be CREATED within that folder.
Now select this zip file and right click, 'extract all' menu will be available.
If you select this, wizard will open to extract file.
I want this through Dos Prompt so that i can use it in my batch file.

Thanks
I'm not aware you can do this at the prompt without a third party program. You can however create a your own command and have it run from the prompt or a batch file.

Unzip
Code: [Select] strZipFile = "" 'name of zip file
outFolder = "" 'destination folder of unzipped files

Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions

Fill in the appropriate names for the zip file and the output folder (must be quoted). Save the script with a vbs extension. In your batch file you can run the script with this entry: cscript //nologo scriptname.vbs

Good luck.

Note: option 256 displays a progress dialog box but does not SHOW the file names. Thanks for the info! Hopefully you can help me with an issue on this...

In a folder I have the following 3 files:

test.zip
unz.bat
unz.vbs

When I run unz.bat in a command window, the following message displays:

unz.vbs(5, 1) (null): The system cannot find the file specified.

When a friend runs my same files on his XP machine, it runs fine. Is there a system file I am missing?

This is the contents of my files:

file: unz.bat
--------------------------------

cscript //nologo unz.vbs


file: unz.vbs
--------------------------------

strZipFile = "c:\DONZ\test.zip"
outFolder = "c:\DONZ\"

Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions

Thank you for any help!
Does the folder containing those files have a long file name or a name with spaces?

You may have to put the entire path name after cscript //nologo.

For example, if you have those files in C:\Unzipping Path, you'll have to use this:

cscript //nologo "C:\Unzipping Path\unz.vbs"I used the same script and get the following error:

Quote

Microsoft VBScript runtime error: Object REQUIRED: 'objShell.NameSpace(...)'

Here is my code:
Code: [Select]strZipFile = "c:\documents and settings\%username%\fr5\resource.zip"
outFolder = "c:\documents and settings\%username%\fr5\"

Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions
I've checked, retyped the code, copied the code, etc. What am I missing?Quote
I used the same script and get the following error:

The same script would have worked!

In this context, the username variable needs to be expanded:

Code: [Select]Set WshShell = CreateObject("Wscript.Shell")
user = WshShell.ExpandEnvironmentStrings("%UserName%")

strZipFile = "c:\documents and settings\" & user & "\fr5\resource.zip"
outFolder = "c:\documents and settings\" & user & "\fr5\"

Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions

Everything else being equal, this should work. Thanks, Sidewinder. Worked like a charm. Hey guys. I hope someone is still looking at this thread as I require some help and quite urgently. The unzip seems to be working fine but the files I receive is always named differently because they contain a date and they are password encrepted. How can I specify the password in the script and also tell it to extract all files inside a certain directory not just one? Thanks in advanceQuote
Hey guys. I hope someone is still looking at this thread as I require some help and quite urgently

This would be reason number one why you should start your own thread. Many people will see this thread with 7 replies and deduce that there is NOTHING more to add. Reason number two is that it is considered rude to hijack someone else's thread, no matter how old.

Quote
The unzip seems to be working fine but the files I receive is always named differently because they contain a date and they are password encrepted.

Use the same algorithm as the sender to determine the received file name. You might also determine what files are in the receive directory, and sequentially unzip each one.

Did you use some 3rd party program to compress your files? Windows compressed files don't have a password option and they cannot be encrypted.

Need more info. .ZIP folders have the option of having a password to prevent the extraction of the files...also prevents WinRAR from extracting as well.Hi All,

I am getting the Error while I am trying to run the Script


Test.VBS(5, 1) Microsoft VBScript runtime error: Object required:
'objShell.NameSpace(...)'


ndate = date()
ndate = ndate-0
strlongdate = formatdatetime(ndate,vblongdate)
strshortdate = formatdatetime(ndate,vbshortdate)
'wsh.echo "The yesterday date is : " & cstr(ndate)
'wsh.echo "The long date : " & strlongdate
'wsh.echo "The short date : " & strshortdate
strshortdatearray = split(strshortdate,"/")
'wsh.echo cstr(strshortdatearray(0))
'wsh.echo cstr(strshortdatearray(1))
'wsh.echo cstr(strshortdatearray(2))


'**********Set these values accordingly to the date format of the machine (2008-01-01)***********

str_short_year = cstr(strshortdatearray(2))
str_short_month = cstr(strshortdatearray(1))
str_short_day = cstr(strshortdatearray(0))

if len(str_short_day ) = 1 then

str_short_day = "0" & str_short_day

end if

if len(str_short_month ) = 1 then

str_short_month = "0" & str_short_month
end if

Option Explicit
'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\"

Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN"

Sub Extract( ByVal myZipFile, ByVal myTargetDir )
Dim intOptions, objShell, objSource, objTarget
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace( myZipFile ).Items( )
Set objTarget = objShell.NameSpace( myTargetDir )
Set colItems = objFolder.Items
intOptions = 256
objTarget.CopyHere objSource, intOptions
Set objSource = Nothing
Set objTarget = Nothing
Set objShell = Nothing
End Sub

ndate = date()
ndate = ndate-0
strlongdate = formatdatetime(ndate,vblongdate)
strshortdate = formatdatetime(ndate,vbshortdate)
'wsh.echo "The yesterday date is : " & cstr(ndate)
'wsh.echo "The long date : " & strlongdate
'wsh.echo "The short date : " & strshortdate
strshortdatearray = split(strshortdate,"/")
'wsh.echo cstr(strshortdatearray(0))
'wsh.echo cstr(strshortdatearray(1))
'wsh.echo cstr(strshortdatearray(2))


'**********Set these values accordingly to the date format of the machine (2008-01-01)***********

str_short_year = cstr(strshortdatearray(2))
str_short_month = cstr(strshortdatearray(1))
str_short_day = cstr(strshortdatearray(0))

if len(str_short_day ) = 1 then

str_short_day = "0" & str_short_day

end if

if len(str_short_month ) = 1 then

str_short_month = "0" & str_short_month
end if

Option Explicit
'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\"

Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN"

Sub Extract( ByVal myZipFile, ByVal myTargetDir )
Dim intOptions, objShell, objSource, objTarget
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace( myZipFile ).Items( )
Set objTarget = objShell.NameSpace( myTargetDir )
Set colItems = objFolder.Items
intOptions = 256
objTarget.CopyHere objSource, intOptions
Set objSource = Nothing
Set objTarget = Nothing
Set objShell = Nothing
End Sub



ndate = date()
ndate = ndate-0
strlongdate = formatdatetime(ndate,vblongdate)
strshortdate = formatdatetime(ndate,vbshortdate)
'wsh.echo "The yesterday date is : " & cstr(ndate)
'wsh.echo "The long date : " & strlongdate
'wsh.echo "The short date : " & strshortdate
strshortdatearray = split(strshortdate,"/")
'wsh.echo cstr(strshortdatearray(0))
'wsh.echo cstr(strshortdatearray(1))
'wsh.echo cstr(strshortdatearray(2))


'**********Set these values accordingly to the date format of the machine (2008-01-01)***********

str_short_year = cstr(strshortdatearray(2))
str_short_month = cstr(strshortdatearray(1))
str_short_day = cstr(strshortdatearray(0))

if len(str_short_day ) = 1 then

str_short_day = "0" & str_short_day

end if

if len(str_short_month ) = 1 then

str_short_month = "0" & str_short_month
end if

Option Explicit
'Extract "E:\PrePaid_Data\TN\SFAF\08_BAN_TN_SFAF_" & str_short_year & str_short_day & str_short_month & ".zip", "E:\PrePaid_Data\TN\SFAF\"

Extract "E:\PrePaid_Data\TN\01_BAN_TN_ADJM_20090528.txt.zip", "E:\PrePaid_Data\TN"

Sub Extract( ByVal myZipFile, ByVal myTargetDir )
Dim intOptions, objShell, objSource, objTarget
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace( myZipFile ).Items( )
Set objTarget = objShell.NameSpace( myTargetDir )
Set colItems = objFolder.Items
intOptions = 256
objTarget.CopyHere objSource, intOptions
Set objSource = Nothing
Set objTarget = Nothing
Set objShell = Nothing
End Sub




Resolve Any ONE ASAP............................
3407.

Solve : 2 part question about date in a batch file?

Answer»

Part 1:

I am using the following to create a zip file with a specific name:

@echo off
for /f "tokens=2-4" %%i in ('echo %date%') do (
set today=%%i
)
for /f "tokens=1-3 delims=/" %%a in ('echo %today%') do (
set month=%%a
set day=%%b
set year=%%c
)

for /f "tokens=1-4 delims=.: " %%i in ("%time%") do (
set hour=%%i
set minute=%%j
)

if %hour% LSS 10 set hour=0%hour%


I use %year%%month%%day%_%hour%%minute%.ZIP as the file name parameter, which gives me 20091125_0905.ZIP, for example. I want to change this so the output is in the DDMMMYY_HHmm.ZIP format, so the output would be 25NOV09_0905.ZIP. How do I need to reformat above, or use in it's place? I am using this in a bacth file to back up some files.

Part 2:

I would like to output both the date and time in UTC, instead of local time.rem We did not show the different format for file name, yet?

C:\batch>cat showdate.bat

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=2-4" %%i in ('echo %date%') do (
set today=%%i
echo !today!
echo %%i
)
for /f "tokens=1-3 delims=/" %%a in ('echo !today!') do (
set month=%%a
set day=%%b
set year=%%c
echo month=!month!
echo day=!day!
echo year=!year!
)

for /f "tokens=1-4 delims=.: " %%i in ("%time%") do (
set hour=%%i
set minute=%%j

echo hour=!hour!
echo minute=!minute!

echo !year!!month!!day!_!hour!!minute!.ZIP
echo !day!!month!!year!_!hour!!minute!.ZIP
)

rem set hour=9

rem echo hour=!hour!

rem if !hour! LSS 10 set hour=0!hour!

rem echo hour=!hour!


rem I use %year%%month%%day%_%hour%%minute%.ZIP as the file name parameter,
rem which gives me 20091125_0905.ZIP, for example.
rem I want to change this so the output is in the DDMMMYY_HHmm.ZIP format,
rem so the output would be 25NOV09_0905.ZIP. How do I need to reformat above,
rem or use in it's place? I am using this in a bacth file to back up some files.



OUTPUT:

C:\batch>showdate.bat
11/25/2009
11/25/2009
month=11
day=25
year=2009
hour=15
minute=39
20091125_1539.ZIP
25112009_1539.ZIP

C:\batch>QUOTE from: JohnBergt

Part 2:

I would like to output both the date and time in UTC, instead of local time.

I doubt if this is achievable using only batch scripting, VBS might be better for this part, perhaps one of the VBS gurus will drop in.

Meantime here's another version of batching to create the filename in the format you requested using the 24-hour clock (aka Military Time). The underlined command lines should be removed when you are finished testing. Your date format is assumed to be 'day mm/dd/yyyy' and the time format as 'hh:mm:ss.ms AM (or PM)', When the hour is less than 10 it's assumed it is shown as one digit.

Code: [Select]Script removed.

Edit: See amended script below....As a suggestion you could try extracting it with the Set command
Code: [Select]@echo off
set nummonth=%Date:~4,2%
set day=%Date:~7,2%
set year=%Date:~12,2%
set hour=%Time:~2%
set min=%Time:~3,2%

if %hour% LSS 10 set hour=0%hour%

for /f "tokens=%nummonth%" %%a in ('echo JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC') do (
set wordmonth=%%a
)

Then for the ZIP paramater you can just put:
Code: [Select]%day%%wordmonth%%year%_%hour%%min%.ZIP
For part two, you would have to use a 3rd party program or perhaps Cscript.

I'll get back with the Cscript instructions.

Hope this helps
,Nick(macdad-)Thanks T.C. and macdad. T.C.'s method worked well. Macdad, your method left some extra spaces and inserted a : into the file name, so that was invalid. Thanks to everyone for answering.Quote from: JohnBergt on November 25, 2009, 05:08:29 PM
T.C.'s method worked well.

You SPOKE to soon John, there is a glaring error in my script.

In the command line Code: [Select]for /f "tokens=%date:~4,2%" %%1 in ("%alphamonth%") do (
set month=%%1
) if the month is 08 or 09 (Aug or Sept) tokens will FAIL probably due to 08 and 09 being invalid octal numbers. Amended script posted below, sorry about the error.

Code: [Select]@echo off
cls

setlocal enabledelayedexpansion

set date=fri 09.26.2009
:: --------------------

set alphamonth=JAN FEB MAR APL MAY JUN JUL AUG SEP OCT NOV DEC

if %date:~4,2% lss 10 (set monthnbr=%date:~5,1%
) else (
set monthnbr=%date:~4,2%
)

for /f "tokens=%monthnbr%" %%1 in ("%alphamonth%") do (
set month=%%1
)

set today=%date:~7,2%%month%%date:~-2%

set time=1:12:13.14 am
:: -------------------

for /f "tokens=1-4 delims=: " %%1 in ("%time%") do (
set hour=%%1
set min=%%2
if /i %%4 equ pm if %%1 lss 12 set /a Hour +=12
)

if %hour% lss 10 set hour=0%hour%

set time=%hour%%min%

echo.&echo.
echo Today=%today% Time=%time%
echo.&echo.
echo Filename=%today%_%time%.zip




Script edited to allow for correct display of times between 12.00 (noon) and 1.00 pm date manipulation has been discussed countless times. Don't use batch for date manipulations. try learning and using vbscript if you are a native guy, or get a real programming language, Perl/Python are the ones you need.Quote from: gh0std0g74 on November 26, 2009, 02:53:27 AM
date manipulation has been discussed countless times. Don't use batch for date manipulations. try learning and using vbscript if you are a native guy, or get a real programming language, Perl/Python are the ones you need.

I believe this vbscript should do the job.Quote from: gh0std0g74 on November 26, 2009, 02:53:27 AM
Don't use batch for date manipulations. try learning and using vbscript

Sorry, I cannot agree with that. While it is a good idea to learn VBScript etc., when a member asks for a solution to a problem using batch scripting he/she should be assisted to achieve that solution in the scripting language of his/her choice not told to go off and learn another language with which he/she may have no experience. Certainly batch scripting is very limited in some areas, and date manipulation is one of them, but if the request is for assistance in a batch script that assistance should be forthcoming where it is possible. Then, and only then, should the suggestion be made to expand into VBS etc...Quote from: T.C. on November 26, 2009, 12:04:51 PM
Batch Works.

Code: [Select]@echo off

setlocal enabledelayedexpansion


date /t > sdate.txt
set /p sdate=<sdate.txt
echo sdate=!sdate!



set alphamonth=JAN FEB MAR APL MAY JUN JUL AUG SEP OCT NOV DEC

set tokens=%sdate:~4,2%

echo tokens=!tokens!



for /f "tokens=%date:~4,2%" %%a in ("%alphamonth%") do (
set month=%%a
echo month=!month!
)

set today=%date:~7,2%%month%%date:~-2%


time /t > stime.txt
set /p stime=<stime.txt

echo stime=!stime!


for /f "tokens=1-4 delims=: " %%a in ("%stime%") do (
set hour=%%a
set min=%%b
set pmm=%%c
echo hour=!hour!
echo min=!min!
echo PM=!pmm!

if !pmm! equ PM set /a hour=!hour! + 12

echo hour = !hour!
)

if %hour% lss 10 set hour=0%hour%

set time=%hour%%min%

echo.&echo.
echo Today=%today% Time=%time%
echo.&echo.
echo Filename=%today%_%time%.zip


Output:


C:\>fdate.bat

sdate=Wed 11/25/2009
tokens=11
month=NOV
stime=11:40 PM
hour=11
min=40
PM=PM
hour = 23


Today=25NOV09 Time=2340


Filename=25NOV09_2340.zip

Output for 11/26/2009:


C:\test>joan.bat
sdate=Thu 11/26/2009
tokens=11
month=NOV
stime=04:15 PM
hour=04
min=15
PM=PM
hour = 16


Today=26NOV09 Time=1615


Filename=26NOV09_1615.zip
C:\test>
Quote from: T.C. on November 26, 2009, 12:04:51 PM
Sorry, I cannot agree with that.
you do not agree because i said "Don't use batch for date manipulation"? or you don't agree that i asked OP to learn and use something else that is better at doing this job?

Quote
While it is a good idea to learn VBScript etc., when a member asks for a solution to a problem using batch scripting he/she should be assisted to achieve that solution in the scripting language of his/her choice not told to go off and learn another language with which he/she may have no experience.
you must understand that this is a forum, and we are allowed to suggest BETTER and EASIER alternatives to SOLVE the problem. What really matters is OP's choice of solution, not yours or mine.
No experience in learning something he did not know?? If OP has experience in batch, he wouldn't have asked here already. so what's your point?

Quote
Certainly batch scripting is very limited in some areas, and date manipulation is one of them, but if the request is for assistance in a batch script that assistance should be forthcoming where it is possible. Then, and only then, should the suggestion be made to expand into VBS etc...
as far as i already know, you have provided a batch (that may not work in every machine due to individual date settings). I/macdad have provided suggestion using vbscript and all that's left is up to OP. A challenge for you, try producing a batch to convert local to UTC for OP then, if you really meant what you say.Quote from: GD
A challenge for you, try producing a batch to convert local to UTC for OP then, if you really meant what you say.

GD - You obviously did not read my first response to JohnBergt, did I not state Quote
Quote from: JohnBergt
Part 2:

I would like to output both the date and time in UTC, instead of local time.

I doubt if this is achievable using only batch scripting, VBS might be better for this part, perhaps one of the VBS gurus will drop in.

One of the VBS gurus did drop in but unfortunately didn't leave a solution.

Quote from: GD
as far as i already know, you have provided a batch (that may not work in every machine due to individual date settings).

Quite correct, it will not work for date settings other than the ones I stipulated in my first response:
Quote
Your date format is assumed to be 'day mm/dd/yyyy' and the time format as 'hh:mm:ss.ms AM (or PM)', When the hour is less than 10 it's assumed it is shown as one digit.

How can I make that clearer? I have no wish to become involved in a drawn out argument about the merits of Batch Scripting vs VBS, I also believe VBS is superior in many ways than Batch but still believe that if a solution to a problem is asked for in batch scripting and that solution can be arrived at then it should be given.

Kind regards to all.

T.C.

Quote from: T.C. on November 26, 2009, 08:24:33 PM
GD - You obviously did not read my first response to JohnBergt, did I not state
don't worry, i did read your post before posting my last response.
Quote
but still believe that if a solution to a problem is asked for in batch scripting and that solution can be arrived at then it should be given.
so is there a clean and understandable batch(cmd.exe) solution given yet to take into account, different regional date settings on different machines, and the ability to convert to UTC time easily?? Your reasoning that batch solution should be given is flawed. most of the time, the ones posting questions here either did not know there are better alternatives, or they just have the mentality that says batch does everything. What's wrong with posting better alternatives that do the job in half the time it takes to do it in batch? you are beginning to sound that the other "hated" person around here. I suggest you focus more on providing solution to the OP and stop meddling with trivial things like this.
Quote from: JohnBergt on November 25, 2009, 09:04:59 AM

I would like to output both the date and time in UTC, instead of local time.

http://www.timeanddate.com/worldclock/converted.html?month=11&day=29&year=2009&hour=0&min=0&sec=0&p1=0&p2=184

The World Clock – Time Zone Converter – results

At the specified time, local time in Oklahoma City was 6 hours behind UTC
LocationLocal timeTime zone
UTCSunday, November 29, 2009 at 00:00:00
Oklahoma City (U.S.A. - Oklahoma)Saturday, November 28, 2009 at 6:00:00 PMUTC-6 hours CST


It appears Batch is the best solution for the first part of your question. See Post # 9

UTC is a minor problemthen , Miss genius, can you show a complete batch solution to do both part 1 and 2?
3408.

Solve : How to compile a .bat file? or write a simple .exe to call it??

Answer»

Hi,

I'm trying to intercept calls to a .exe to trace them (legit as my company WROTE the .exe) as part of debugging, and I've suceeded in writing a short .bat file which does what I want after renaming the original command with -ORIG.

the-command.bat
Code: [Select]@echo off
echo .|time >> logfile.txt
echo %0 %* >> logfile.txt
the-command-ORIG.exe %*

The problem is that the customer's program is expecting to call the-command.exe not the-command.bat.

I tried renaming the .bat file, but then it won't execute.
I tried creating a shortcut with .exe extension to the .bat but that didn't work either.

Is there a compiler I could use to convert it from .bat to .exe?
or do I need to WRITE a one-line program to call the .bat and compile it?
or would it be a whole lot easier to write a C program to do the tracing instead?I've nearly SOLVED it with MinGW and the following code

Code: [Select]#include <unistd.h>
#include <stdio.h>

main(INT argc, char *argv[])

{
argv[0] = "C:\\path\\etc\\the-command.bat";
execv("C:\\path\\etc\\the-command.bat", argv);
RETURN 0;
}
I'll follow up on the final problems in the programming forum.

3409.

Solve : Hello - I would like some help.?

Answer»

It's with MS-Dos, duhh

Anyway my problem is, I want to create a "ONE command only" code.

A example of what I am doing:

Code: [Select]:G
color d
echo You have answered yes.

set /P user=Username:
set /p pass=Password:
set /p id=Activating ID:

if %id% == 9878498 GOTO X
cls
I want to make it so the %id% MUST be the exact code (9878498) else will it exit.
I do not KNOW how to make this, any help would be appreciated,

Regards - Dzenet.if not %Id%==Number exit

There you go. i recommend you to stop before you CONTINUE further. for the sake of security, don't ever do password authentication that way. unless this is just for fun. here are some approaches you can use, if not for fun
1) database approach. Set up a database, then have the user authenticate through it using 1 interface. practically, your application will be done not in batch, but with a proper language
2) use the active directory, if you have it.Hello,
Yes, it is a very poor idea to use batch file to gather password information.
The recommendation given above byghostdog74 is the right way to go. Inform your user that they have to login to a certain directory and they will be asked for a password. That should take care of most of the cases where you would need a password on a Windows desktop PC.

3410.

Solve : save files and transfer to usb key??

Answer»

Basically before i wipe the hardrive and INSTALL win 7 again i was wondering if this is possible in mdos?

WINDOWS won't start normally, so it's not possible to do it the easy way.

I TRIED to install win7 from my usb key, it went badly. I'll spare the details.
I'm not sure what other details are needed, i'll check back often.
If you had an ABORTED Win7 installl chances are there's not MUCH data left to be retrieved...

3411.

Solve : A batch file do a automatic copying and renaming job with conditions like this??

Answer»

Hello, I'm NEWBIE in command prompt console and want to ask something about my issue.

I want make a batch file do this task (basic):

- Copy all *.dat file in F:\MPEGAV\ (DVD drive in my PC) to My documents.
- If target folder is empty or there isn't any dupplicate file, then OK. But if it contains files share same name with newcoming files (copy those *.dat video files from many different VCDs but their names'd be probably same 'coz that's the way VCD named files to make them playable in VCD/DVD player), then rename them to filename-currenttime.dat.

*Note: I know basically about cmd command and try them sometime (of course still newbie way) and had search Google for putting currenttime parameter into files names. Code below (modified a example that I find in google):
Code: [Select]for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename "*.dat" "*-%%dh%%e'%%f''.dat"
This command just do rename job and add time following h, m, s

I try some way to write a batch file do this job but unsucessfully. Pls someone help me out and pls write code in details (for my question, don't just tell me generally and tell me find out myself , thanks)This looks fun. It should work. I haven't tested it though.

If exist F:\MPEGAV\*.dat (
for /f "tokens=1-3 delims=:" %%a in (%time%) do (
set a=%%a
set b=%%b
set C=%%c
)
For /f "tokens=1,2 delims=." %%d in ('dir /b F:\MPEGAV') do if not exist "%userprofile%\My Documents\%%d.dat" (copy F:\MPEGAV\%%d.dat "%userprofile%\My Documents") else (copy F:\MPEGAV\%%d.dat "%userprofile%\My Documents\%%d-%a%%b%%c%.dat)
)Thanks a lot, man. I haven't try at the moment but anyway thanks for answer.

BTW, I've got some question. If the DVD/VCD drive isn't F: (not get F: as drive character due different number of HDDs, etc...) can I write code above somehow it keeps copy from valid location if 1st DVD/VCD drive isn't F: (for user have got 2 DVD drives, just need to do job with their 1st DVD/VCD drive).

Is it possible in batch file? Any environment parameter or anything made that work?

* I'll try and report to get further help if anything going wrong in current code.

I just curious about karma and got that when try playing P/S I click thanks u already

C:\batch>type nah122109.bat

Code: [Select]@echo off
cd "%userprofile%\My Documents\"
dir *.dat
pause
rem del *.dat ( remove "rem" if the *.dat should be deleted )


setlocal enabledelayedexpansion
for /f "tokens=1-5 delims=:" %%d in ("%time%") do (
echo "*.dat" "*%%d%%e%%f.dat"
echo time = %time%
echo d = %%d
set a=%%d
echo a=!a!
echo e = %%e
set b=%%e
echo b=!b!
echo f = %%f
set c=%%f
echo c=!c!
)

For /f "delims=" %%i in ('dir /b E:\MPEGAV\*.dat') do copy E:\MPEGAV\%%i "%userp
rofile%\My Documents\%%i-%a%%b%%c%.dat
)

echo cd "%userprofile%\My Documents\"
cd "%userprofile%\My Documents\"
dir *.dat
Output:

C:\batch>nah122109.bat
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of "%userprofile%\My Documents\"

12/22/2009 07:17 PM 10 test.dat-193731.78.dat
12/22/2009 07:17 PM 10 test2.dat-193731.78.dat
2 File(s) 20 bytes
0 Dir(s) 305,515,515,904 bytes free
Press any key to continue . . .

time = 19:39:27.84
d = 19
a=19
e = 39
b=39
f = 27.84
c=27.84
1 file(s) copied.
1 file(s) copied.
cd "%userprofile%\My Documents\"
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of "%userprofile%\My Documents\"
12/22/2009 07:17 PM 10 test.dat-193927.84.dat
12/22/2009 07:17 PM 10 test2.dat-193927.84.dat
2 File(s) 20 bytes
0 Dir(s) 305,515,515,904 bytes free

Both solutions posted take a static snapshot of the time. If there is more than one duplicate name for a single DVD/VCD, the code will break when the copy is performed and the time has not changed. I suggest leaving the clock running, NEST the for statements and use the dir command as the primary for loop.

Code: [Select]@echo off
set source=F:\MPEGAV
set target=C:\Documents and Settings\%username%\My Documents

for /f %%x in ('dir /b %source%\*.dat') do (
for /f "tokens=1-4 delims=:." %%i in ("%time%") do (
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l"
) else (
copy %source%\%%x "%target%\%%x")
)
)

Quote

I try some way to write a batch file do this job but unsucessfully. Pls someone help me out and pls write code in details (for my question, don't just tell me generally and tell me find out myself

With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution.
C:\batch>type winder122109.bat

Code: [Select]@echo off
set source=E:\MPEGAV
set target=C:\Documents and Settings\%username%\My Documents

cd %target%
dir *.dat
rem del *.dat ( remove "rem" if you need to remove .dat files )

for /f %%x in ('dir /b %source%\*.dat') do (
for /f "tokens=1-4 delims=:." %%i in ("%time%") do (
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat"
) else (
copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat")
)
)

cd %target%
dir *.dat
Output:

C:\batch>winder122109.bat

Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of %target%
12/21/2009 11:18 AM 9 me.dat-17320759.dat
12/21/2009 11:18 AM 9 me2.dat-17320759.dat
2 File(s) 18 bytes
0 Dir(s) 305,583,677,440 bytes free
1 file(s) copied.
1 file(s) copied.
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of %target%
12/21/2009 11:18 AM 9 me.dat-17333304.dat
12/21/2009 11:18 AM 9 me2.dat-17333304.dat
2 File(s) 18 bytes
0 Dir(s) 305,583,677,440 bytes free
@BillRichardson:

I thought you were banned. In any case if you noticed an error, why did you not simply fix it? Apparently anybody can be a critic, but if you're going to re-post code at least be accurate.

I posted:
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l"
) else (
copy %source%\%%x "%target%\%%x")
which I admit was in error.

You posted:
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat"
) else (
copy %source%\%%x "%target%\%%x-%%i%%j%%k%%l.dat")
which is also in error.

The corrected code:
Code: [Select]@echo off
set source=F:\MPEGAV
set target=C:\Documents and Settings\%username%\My Documents

for /f %%x in ('dir /b %source%\*.dat') do (
for /f "tokens=1-4 delims=:." %%i in ("%time%") do (
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%nx-%%i%%j%%k%%l.%%xx"
) else (
copy %source%\%%x "%target%\%%x")
)
)

I always thought we were here to help out the OPs. Keep in mind BillRichardson these threads are not about you but about the Topic Starters. That's all I have to say...I refuse to get involved in a marathon thread with BillRichardson, et al.

Quote from: Sidewinder on December 21, 2009, 05:23:21 PM
@BillRichardson:
In any case if you noticed an error, why did you not simply fix it? Apparently anybody can be a critic, but if you're going to re-post code at least be accurate.

_____________________________________

I respect your code and judgement more than anyone on this board.

You code is much better than mine.

I learn by running your code. The output always helps me.

I thought the new file names should have a ".dat" at the end?

I might have run the code incorrectly or had my folders set up wrong?

I will erase or change the code as you suggest.

Tell me exactly what to change.

Is it wrong to show the output?

I will do whatever you suggest.

Thanks for your help several times in the past.

Quote
With an attitude like that, you'll never learn anything. Would have been better to post your unsuccessful attempt. It would have shown that you at least made an attempt for a solution.

Well, I don't know if you're helpful for anyone previously, but not me... You just come and sounds like /I'm god, u're lazy boy, keep learning!/

Because there's people like you I wrote my question with those sentences above. I don't have to be a expert in command prompt console and I don't need to be someone like that. I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice. You don't need to stay there and say that, it's too pointless thing after all~ 4rum just make for give people a chance to get help and it doesn't REQUIRE that much conditions (in rules, I don't see that I've to post all my attempt and etc....)

Feel free ban nick or lock acc if u want.

Don't worry, everybody is entitled to their opinion and you will not be banned for expressing yours.

It's been said here and elsewhere "Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime." Apparently you just want someone to hand you a fish.

I must have been very tired last night, but post #6 (the corrected code) has an error. The corrected code (v2) is posted below. Take it for what it's worth.

Code: [Select]@echo off
set source=F:\MPEGAV
set target=C:\Documents and Settings\%username%\My Documents

for /f %%x in ('dir /b %source%\*.txt') do (
for /f "tokens=1-4 delims=:." %%i in ("%time%") do (
if exist "%target%\%%x" (copy %source%\%%x "%target%\%%~nx-%%i%%j%%k%%l%%~xx"
) else (
copy %source%\%%x "%target%\%%x")
)
)



Quote
I'm here for get some help no matter how good/bad am I (in computer experience), people'd give a hand or not, it's their choice

I'll keep that in mind the next time you post. It will save me the aggravation of reading another one of your rants. Quote
I'll keep that in mind the next time you post.
OK, keep TALKING yourself about that.

Don't start with fish and blah blah things... I'm working as a graphic artist and I can live without cmd, alright? I'm not a kid for you talk to me like that. And I don't need any ggdamn fish, just need a accurate and correct answer for my question, if it hurt your ego, then it's not my mistake. Thanks for nonetheless.

You live as a IT supporter or programmer or whatever, me too. Then don't personally attach me about fish and etc...Quote from: nah on December 22, 2009, 07:48:15 AM
OK, keep talking yourself about that.

Don't start with fish and blah blah things... I'm working as a graphic artist and I can live without cmd, alright? I'm not a kid for you talk to me like that. And I don't need any ggdamn fish, just need a accurate and correct answer for my question, if it hurt your ego, then it's not my mistake. Thanks for nonetheless.

You live as a IT supporter or programmer or whatever, me too. Then don't personally attach me about fish and etc...
Nah, that wasn't an attack. He is just explaining that people who get taught how to do this understand it for a lifetime, no longer need help, and can even help others out (that's what happened to me), but people who only want the answer, they need help for the rest of their life. Quote from: nah on December 20, 2009, 06:56:40 AM
I want make a batch file do this task.

You were given at least 3 possible solutions.

Which solution worked for you?
3412.

Solve : Merging the contents of two files, into one file?

Answer»

Hi there,

I have no idea how to resolve my problem.
I guess a dos batch file can help me, but I've got no idea how to start.

I've got two files, with similar contents. Both files are csv- files (comma separated value) which can be read by excel, but also with notepad (as txt-files)
The headers in both files are the same.
Now I want to JOIN the contents of one file, into the other file (or create one master-file of the two files).

Does anyone have an idea how i can do this (or is this even possible)?

Greetings

Shape


Did you want to keep the header of one of them and DISCARD it from the other?
Let's suppose that both files are valid spreadsheet files. If so, there will be mathematical expressions that may have absolute reference to cells inside the spreadsheet. But once the two files are combined as a simple text file., the REFERENCES will not be correct.
Does that MAKE sense to you? If your intent is to just combine the two files together for the purpose of documentation that would be an acceptable thing. Otherwise, if you really want that to spreadsheets to work together as one, you would have to use the features inside of XL two combined to spreadsheets together. Possibly, you would have to create a book inside of XL and each spreadsheet would be a separate page inside of one book. Then you would have to do some additional work so that the output of one page could be referenced on the second page and perhaps a sum total of the entire project could be given on the third page. Or something like that.
By the way, is this some type of homework assignment?
What you need to know is that the operating system itself is rather ignorant of the needs of application programs, at least at the file level. Relationships between application programs are controlled by a higher order of structure that is outside the domain of batch files.
Was this of any help? Or did I just make things worse?@Salmon
If possible, with out the header...

Searching this forum, It seems that part of the problem has been resolved in another topic.

@echo off
echo. > G:\dos\master\master.csv
cd G:\dos
for /f %%a in ('dir /b *.txt') do type %%a >> G:\dos\master\Master.csv
pause

This works just fine (for which my thanks, it saves me a lot of work!)


Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM

Let's suppose that both files are valid spreadsheet files.
The files are not valid spreadsheet files. A csv-file is a text file that excel can read by conversing a dot comma as the END (or start) of a new column in excel (B-column)

Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM
Does that make sense to you?

The dos commands as shown above, already works.

Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM
If your intent is to just combine the two files together for the purpose of documentation that would be an acceptable thing. Otherwise, if you really want that to spreadsheets to work together as one, you would have to use the features inside of XL two combined to spreadsheets together.

It makes a csv files, which excel can convert. the Master.csv works well in excel


Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM
Possibly, you would have to create a book inside of XL and each spreadsheet would be a separate page inside of one book. Then you would have to do some additional work so that the output of one page could be referenced on the second page and perhaps a sum total of the entire project could be given on the third page.

The data is shown in one page, inside the file

Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM
By the way, is this some type of homework assignment?

A serious work related problem, which needs a quick fix!

Quote from: Geek-9pm on December 22, 2009, 12:10:07 PM
Was this of any help? Or did I just make things worse?

You decide

3413.

Solve : New mbr - seeking direction and capabilities of batch files?

Answer»

Hey ya’ll.

I have a some standard questions at the bottom about building a batch file.

EDIT: -> Using WinXP, and am also searching the archives.

Background:
The program being engaged through a batch file is an audio (in my case, Podcasts (mp3)) file splitter, called MP3 Splitter and Joiner Pro, which splits at predetermined intervals setup in a cue file. When the program is run manually, with the mouse, the program accepts (drag & drop, or opening through a dialogue) the cue file first, and if there’s no file associated with the cue file, it prompts for it by opening another dialogue box to choose it. If there is an associated mp3 file listed in the cue file already, only the cue file needs to be loaded, and the audio file will automatically be added in/loaded. Normally, there is no association. Then, the user has to click the Split button, and it can be split to a predetermined directory. The commercials are cut out of the audio files, SAVING about 18 minutes per 1 hour podcast, so that's why i do this manually, but it's getting old. My issues with setting up a snazzy batch file to do the WORK stated above are:

Issue 1 - Sometimes there are 2 files (representing a 2 hour Podcast)

Issue 2 - Unsure which of the following approaches is better:

* Load the cue file, then load the podcast (and in the case of a 2 hour program, do the same thing again for the last hour of the program), or

* Use some kind of utility to find the latest files in the same directory as the cue file and rename a fixed text string within the cue file to the name of one of the audio files in the directory so that only the cue file would need to be loaded into the splitter.

Issue 3 - Don’t know how to (using a utility?) search for the latest podcasts in the directory. The filenames are always the same except for the date (inherent in the filename & differs daily, but always in the same location in the file name).

Issue 4 - Unsure how to send a key stroke through the batch file to press the Split button on the app, and also to close the app. The vendor of the app said that the splitter is not setup to split files with any switches at the command line but that it can load cue files and audio files from the command line. I have the syntax in an email, untested.

I get the feeling this is going to be a big deal if I pursue it.

My questions:

1)Can a batch file do all that I’ve stated above?
2)Are there utilities that can simplify some of those steps
3)Is this even the right forum / WEBSITE to be ASKING this?
4)Are there any examples for me to refer to either here, or somewhere else on the net?

Looking FORWARD to your replies.

Thanks from Tokyo

3414.

Solve : I need help with this code of inject.exe?

Answer»

ur right BC_Programmer

it asks for the command line ,this shows ur smartness!!!!!!!!

i 've attached files with that Inject.exe to show an illustration

but it was a command line just for distracting (i think)yes salmon "I BET"

it seems that from the 1st day ur helping me, but these dayz ur so rude

i cant see that 1st day SALMON TROUTQuote from: great_compressor_pain on November 30, 2009, 05:57:17 AM

yes salmon "I BET"

it seems that from the 1st day ur helping me, but these dayz ur so rude

i cant see that 1st day SALMON TROUT

And you never will while you keep posting nonsense.
Quote from: great_compressor_pain on November 30, 2009, 05:52:14 AM
it packs any means any files in 1 single file

Hey WinZip and WinRAR do the same thing. Do you want the code for them too?
*censored* is your bloody question? WHAT do you want? "the codes" as I've just stated is so meaningless, redundant, ambiguous and all-around script-kiddie to say that it doesn't specify at all what you want.


s ofar as I've just stated there are several possiblilities:

1. Either you want the actual source code to this program, which none of us can provide since we didn't write it.

2. you want somebody to write a program that does the same thing, and give you the source to that

3. you simply want to know what command-line options the program has.


So which is it? stop SAYING "it packs files" and "it's by some dude" Start giving us some frikkin' details rather then making contrived observations about the PROGRAMS BEHAVIOUR that you erroneously believe somehow GIVES us some idea what you want.


Oh! And by the way, inject.exe is infected. thought you might like to know- since you probably RAN it and all.


Quote from: great_compressor_pain on November 30, 2009, 06:01:39 AM
and as i said i've got the right guy

No. You don't. I still have no clue what the heck you want.
Profanity reported.
heh, I was wondering how long it would take for him to get help with his keygens/file injectors and other sketchy stuff elsewhere.Pain is heading to drink a tall cool glass of Ban Cola.
Quote from: Salmon Trout on November 30, 2009, 06:07:55 AM
Pain is heading to drink a tall cool glass of Ban Cola.


Or he deleted his account - he's a "Guest" now. Another one bites the dust
3415.

Solve : How to run a batch file inside a zip archive from a batch file??

Answer»

Here is the path of the working folder.
C:\Documents and Settings\Administrator\Desktop\VBS FONT EXTRACT

The folder I want to delete is called fonts and it is at this path.
C:\Documents and Settings\Administrator\Desktop\VBS FONT EXTRACT\fonts


Just to clarify I used the code for deleting in a new vbs script I didnt put it with the main one yet its all alone in one vbs file. Is that wrong?I thought you were adding the snippet to your existing script. The WshShell NEEDS to be created in a new script:

Code: [Select]Set WshShell = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.GetFolder(WshShell.CurrentDirectory & "\VBS FONT EXTRACT\fonts")
fl.Delete(True)

That did it. I'm gonna take a break hope you dont mind if I ask a few more questions later. I will try to get this FIGURED out but I may still need some help maybe tommorrow. Thanks again man I appreciate it.

I had to make it like this though just to clarify inorder for it to WORK and delete the fonts folder.

Set WshShell = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fl = fso.GetFolder(WshShell.CurrentDirectory & "\fonts")
fl.Delete(True)Just wanted to say THANK you once again to sidewinder. Because of you I learned and I am now working with VBS scripts and it is great. People like sidewinder are a great contribution to any society weather it be alien or human. 100% excellent. I am smarter because of sidewinder.
Thank You very much.

3416.

Solve : Error message when files not found?

Answer»

Gudday all
My code has been loaded ONTO the server and is working except for two (2) teensy PROBLEMS that users have found. The problem occurs when no .spl files are present in the folder
Code: [Select]echo finding spl files
REM *** Extract all .SPL files ***
rem DIR D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.TXT
dir !file_path!*.spl /b > SPLfiles.txt
echo finished finding spl files
.....
del SPLfiles*.txt
(the echo messages are for me)
When no .spl files are found an error message occurs
Quote

File not found
and the temporary file SPLfiles.txt is not deleted as it should be.

Why is the message 'File not found' being generated? I do not want the code to fail if no .spl files are found.
Or more particularly can I stop it?
And why would the file not be deleted if indeed the non-deletion is due to the error message?Code: [Select]echo finding spl files
rem *** Extract all .SPL files ***
rem dir D:\Archives\E20_120_AU\ArchiveCreator\Errors\*.spl /b > SPLfiles.txt
if exist "!file_path!*.spl" (
dir !file_path!*.spl /b > SPLfiles.txt
echo finished finding spl files
) else (
echo No .spl files found
)
.....
del SPLfiles*.txtST
Thank you.
So much to learn.
3417.

Solve : Wacky Question with Batch files.?

Answer»

I used and edited batch files back in the day, but i can't remember if they can be used to wait on a program.

Reason why i ask, i have a keyremapper -autohotkey, that i use to rebind numpad keys to function keys. Of course this effectively eliminates the use of the keypad regularly.

so i want to run
autohotkey
game.exe

then have batch file wait on EXIT of game.exe
close autohotkey.exe

?? feedback would be GREAT!If you are used to batch files from the old MS-DOS & Win95/98/ME days, then you will find that the command language used in Windows NT family OSs (especially Windows 2000 onwards) VASTLY expanded and improved. So much so that it is MISLEADING to still call it "DOS".

Check out the START command, and its switches. You can open a command window and type start /? at the prompt to see a list of them. I think you will find the /WAIT switch most useful.

e.g.

start "" /WAIT "C:\Program Files\Game Folder\Game.exe"

As for starting and STOPPING Autohotkey, I am not familiar with this app, but I am sure you will find help in its own very good forum

http://www.autohotkey.com/forum

Just a thought... can't you run the game from the autohotkey script?

hey thanks for the reply!
yes i could, but i have no other use for autohotkey other than making this game manageable, although it is a very good idea, i'll look into it!I use another Windows automation tool, Autoit, and I often start apps from within scripts so that when the app finishes control is returned to the script, and when the script finishes and exits, it returns control to the batch script.

3418.

Solve : Scripting Help2?

Answer»

Im trying to create a game in batch. I am beginning to get worried since many of my scripts seem to not be working. Can cmd break?
Quote

@echo off
PAUSE
if exist Level.txt. goto cash
echo 1.0>Level.txt
:cash
if exist Cash.txt. goto eng
echo 500>Cash.txt
:eng
if exist Energy1.txt. goto eng2
echo 10>Energy1.txt
:eng2
if exist Energy2.txt. goto exp
echo 10>Energy2.txt
:exp
if exist exp1.txt. goto exp2
echo 0.0>exp1.txt
:exp2
if exist exp2.txt. goto start
echo 10>exp2.txt
:start
set /p Lev= <Level.txt
set /p Cash= <Cash.txt
set /p eng1= <Energy1.txt
set /p eng2= <Energy2.txt
set /p exp1= <exp1.txt
set /p exp2= <exp2.txt
cls
echo Level %Lev%
echo Experience %exp1% / %exp2%
echo MONEY %Cash%
echo Energy %eng1% / %eng2%
echo Zach Wars
echo ---------
pause
:Jobs
cls
echo Level %Lev%
echo Experience %exp1% / %exp2%
echo Money %Cash%
echo Energy %eng1% / %eng2%
echo Zach Wars
echo ---------
echo Jobs
echo.
echo MUGGING Job. 1 Exp. 200 Dollars. -1 Energy. Press 1 to Perform Job.
set /p Job=
if %Job%==1 goto mug
echo This is an incorrect Selection
pause
goto Jobs
:mug
if %eng1%>0 goto mug1
echo Not enough energy to perform Job
pause
goto Jobs
:mug1
echo %eng1%-1>Energy1.txt
echo %Cash%+200>Cash.txt
echo %exp1%+1>exp1.txt
echo Job Completed
pause
if %exp1%>%exp2% goto lvup
goto Jobs
:lvup
set Lev=%Lev%+1
set exp1=0
set exp2=%exp2%+1
set eng1=%eng2%
set eng2=%eng2%+1
echo Congrats! You have leveled up!
pause
goto Jobs
batch is not really used for creating games or programming in general. When adding or subtracting integers in batch, use SET /A. Example:

set /a varname+=1
set /a var2=%varname%^2/40
You can use brackets, as you normally would. Note:
+=addition
-=subtraction
*=multiplication
/=division
^=exponent
?=roots. I don't KNOW this one. Quote from: Helpmeh on December 23, 2009, 06:47:12 AM

?=roots. I don't know this one.

Don't know where you got that from. According to the SET help, viewed by typing SET /? at the prompt they are

Code: [Select] () - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
<< >> - logical shift
& - bitwise and
^ - bitwise exclusive or
| - bitwise or
= *= /= %= += -= - assignment
&= ^= |= <<= >>=
, - expression separator
Quote from: Salmon Trout on December 23, 2009, 07:47:59 AM
Don't know where you got that from. According to the SET help, viewed by typing SET /? at the prompt they are

I put the question mark because I didn't know.
3419.

Solve : Delete system restore points??

Answer»

Hi there,
Does anyone know how to delete system restore points. They take a lot of space and I'd like to make a batch file that delete all the system restore points and just create one new system restore point. I allready managed to find how to create a new one, but does anyone know how to delete system restores points with vbs/batch under windows xp and windows vista?

Thanks in forward!I've never seen a way to delete/create a restore point via DOS, however you can use a VBScript to do it (do it all the time when cleaning up malware).

Disable system restore, deletes all the restore points and then re-enable it, then create your restore point. All done from within VBScript.

http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/computermanagement/restore/
Quote

They take a lot of space
What is a lot of space?
Using that kind of thought, let's all remove the spare tire and jack from our automobiles. We hardly ever NEED them.When I installed Windows XP in October 2001, I disabled System Restore. Since then, I have never missed it. I prefer to run my own backup strategy. Every Saturday morning, and also before updating "mission critical" software or altering something major, I make a backup of my system partition. I keep about the last 4 or 5 backups. I formerly used Norton (Symantec) Ghost, but now I uses Paragon 9.5.
I must say, for an average user, disabling system restore is not a good idea.For the average user, it is probably isn't a good idea. Then again if you backup your data (like you supposed to), and are safe in your browsing habits then I don't see any real problems with cleaning that out.

Because the problem is that it keeps way too much back history. If your MACHINE is functioning perfectly, a good clean up keeps it running. Even removing System Restore points is a good way to do that.

Most people would never go back three months for a system restore because that would end up breaking things they have legitimately installed (like Windows Updates, etc.)

I wouldn't disable it permanently unless you're willing to deal with the PC when things go faulty without having a restore point to try.

So, in my opinion, disable it then enable it and create a good restore point to clean up the machine is fine for a functional PC.

if you want to reduce the space it consumes... change the option accordingly. System Restore has a user-set limitation for each drive.

Having fewer restore points doesn't speed up the PC. It frees up disk space, but if your desperate enough for extra space to start clearing restore points, maybe it would be better to more fully analyze disk usage in other locations, or buy a bigger hard drive.

Quote
or buy a bigger hard drive.

Yes, I wanted to say that. Hard disk drive prices are now lower than ever. If top performance of the drive is not an issue, you can GET a refurbished IDE drive guaranteed by the factory at a bargain price. This is a great choice for backing up your videos, your photos, your downloads and any other stuff that takes up space that you do not use it every day.
This link is from a major vendor. You can get a 250GB drive with a warranty for well undrer $100. That would hold as much data as 50 DVDs.

http://www.compusa.com/applications/category/category_tlc.asp?CatId=134&SRCCODE=COMPGOOHDD&cm_mmc_o=7BBTkwCjCmH4CjCmH4CjCmH4The System Restore feature has its good and its bad points. Good: it allows you to easily protect the integrity of the Windows OS without having to take the time to create a full-fledged backup. Bad: it does not protect user files such as documents, Internet Explorer favorites, the contents of your recycle bin, graphics files, etc. It doesn't protect against a hard disk failure.


and nor does it protect from re-infection of malware. It can hide there waiting for you to need a system restore. You thought you were clean, but do a system restore and the mess gets reinstalled just like before.

That is why after I clean a machine of malware, I always delete the restore points and create a new one (clean).

But also, if you have an exact date of malware infection, a system restore previous to that date can put you back into working order (not really clean, but working).

That is why I still use it, but I just like to keep it cleaned out from time to time.
3420.

Solve : backup certain files?

Answer»

Hi there

I have a compare script which compares a specific SET of files and folders between 2 servers i.e. server A and server B. The compare script will tell me the mismatches between the 2 servers in terms of files/folders. The difference is output to a TEXT FILE. Is it possible to read file names from the text files and backup these files only rather then backing up the entire server.

please adviceshow how your file looks like. the usual way in batch, is using the for loop coupled with a tool to read files, such as TYPE...

3421.

Solve : retrieve data from an application?

Answer»

I have no programming knowledge but was given a group of files created in 1997 that together make up a FULLY functioning very basic custom invoicing program. With this program you can view invoices and create NEW ones. It is only controlled by keyboard functions. These are the files COMPRISING this program:

index.dat
shipping.dat
invoice.dat
work.dat
customer.dat
items.dut
cccdb3.exe

While I know how to use the program to view existing customer invoices, what I need to do is retrieve the data stored in the application for EXPORTING into a different program such as microsoft access. How do I retrieve the data stored?What was the program?
DOS did not have real data base manager.
So the type DAT has meaning only to the program that created it.
Was it part of the PC-WRITE family of programs?
you data most probably are your *.dat files. check to see if they are readable.

3422.

Solve : Deleting files in External Drive?

Answer»

I had been using an external drive to back up music and such. However, due to user ineptitude I allowed it to make multiple copies of each file, some of which have a .dcm file extension attached to them. Dealing only with my music folders, I would like to REMOVE all files except those which end in .wma and .jpg. I have a notion of where to start:

E:\delete e:\backup files\music\*.dcm

All of the music is broken down into the respective album folders, but I am assuming right now that shouldn't matter (i.e. i don't have to specify each individual album folder)

After that I want to remove multiple copies of the same files, which appear as following:

songname.wma
songname_randomdate.wma
songname_anotherrandomdate.wma

I am (much) less sure of that, but right now, I can't seem to get out of the gate: when i try to switch directories, nothing happens. For example:

C:\ cd e:

lets me read e:\backup files

but then immediately changes back to c:\

C:\ chdir e: does the same thing.

If I type C:\DIR e: , I can see all the directories.

I am operating on Windows XP and my computer recognizes my external hard drive, which is a Memeo Passport.

Thanks for any help!Quote from: kovan on December 24, 2009, 04:40:06 PM

I am (much) less sure of that, but right now, I can't seem to get out of the gate: when i try to switch directories, nothing happens. For example:
C:\ cd e:
Just type e: ( leave the cd out)
Quote
I had been using an external drive to back up music and such. However, due to user ineptitude I allowed it to make multiple copies of each file, some of which have a .dcm file extension attached to them. Dealing only with my music folders, I would like to remove all files except those which end in .wma and .jpg. I have a notion of where to start:
E:\delete e:\backup files\music\*.dcm
I'm assuming you want to delete all file ending in .dcm with names such as e:\backup files\music\album1\allsongs.dcm,e:\backup files\music\album2\allsongs.dcm, etc....
Code: [Select]DEL "e:\backup files\music\*.dcm" /sWill remove all files under the music dir with the extension .dcm
Quote
After that I want to remove multiple copies of the same files, which appear as following:

songname.wma
songname_randomdate.wma
songname_anotherrandomdate.wma
What kind of random date format do you have? If all of the files you want to delete end in 09.wma for example and you have no files you want to save ending in 09.wma you COULD use

Code: [Select]del "e:\backup files\music\*09.wma" /s
That will delete all files ending in 09.wma in all sub directories of music
to change drives type the drive letter and a colon e.g. D: and then [ENTER]

to change to a folder on a different drive

use the cd command with the /d switch

Say you are in "C:\My Folder\EggPlant" and you want to be in "E:\Music Files\Led Zeppelin"

you could type either:

E: [ENTER]
cd "Music Files\Led Zeppelin" [ENTER]

or just one line

cd /d "E:\Music Files\Led Zeppelin" [ENTER]

And you will now be in the folder on the other drive.

If you now type C: and press ENTER, you will go back to the C: drive, to the same folder on that drive that you were in before. Thank you Salmon Trout and Crusin702 for the assistance, especially with such rookie questions.

@Crusin702: The random dates do not consistently end in any digit. For example:

.08 [emailprotected];42;59.wma

However, all of the files consistently have an @ symbol included in them. I don't believe any of the song titles include that symbol, so is it possible to delete all files that include "@"?

The code you provided for deleting files that .dcm does not seem to be working. It keeps telling me that it can't find the files (see the attachment)



Thanks again!

[Saving space, attachment deleted by admin]Quote from: kovan on December 25, 2009, 12:57:53 PM
is it possible to delete all files that include "@"?

del *@*Thanks Salmon Trout, that worked perfectly. I tried using that same trick to delete the .dcm files, but it still tells me that it can't find the files.In fact, none of the files ending in .dcm that contain an @ symbol were deleted either. Is it possible the software provided my memeo prevents these files from being located? Sounds as if what you actually saved is shortcuts to where the files used to be...I just did a quick search and it seems the .dcm files are created by the hd software for backup and restoration purposes. Have you tried to delete any of them using explorer? If you can delete them that way, maybe just run a search for .dcm and select all and delete them that way.
3423.

Solve : Please test this batch script.?

Answer»

The script uses Extended ASCII codes and I want to determine if the default codes differ across Windows systems especially Vista and Win 7 variants.

Code: [SELECT]@echo off
cls
setlocal enabledelayedexpansion

set tl=┌&set tr=┐&set bl=└&set br=┘&set up=│

for /l %%▓ in (1,1,8) do echo.

set var=Now is the time
call :display

echo.
set var=For all good men to
call :display

echo.
set var=Come to the aid of their party.
call :display

echo.
set var=......Press any key to continue......
call :display


pause>nul
cls
exit/b

:display
:: Get length of var..
set var1=%var: =%■

:start
call set chr=%%var1:~%pos%,1%%
if !chr!==■ goto finis
set /a pos+=1
goto start

:: Calc number of spaces to centralize text box across line..
:finis
set /a spaces=((80-%pos%)-2)/2
for /l %%Σ in (1,1,%spaces%) do set spaces1=!spaces1!∩

:: Display text box..

set /a pos+=2
for /l %%Σ in (1,1,%pos%) do set line=!line!─

echo %spaces1:∩= %%tl%%line%%tr%
echo %spaces1:∩= %%up% %var% %up%
echo %spaces1:∩= %%bl%%line%%br%

set spaces=&set spaces1=&set line=&set pos=
goto :eof


Expected output is:


Many thanks.
It just opens and closes really quick. I saw something about % was unexpected at this timeComputeruler - thank you. There seems to be a conflict between Ansi and Unicode chars when copying/pasting using Notepad. The script runs perfectly locally as I use Edit.com as preferred text editor. I'll try different coding as a workaround to allow copy/paste with Notepad.

Thanks again & all the best for the festive season.

.

Using Windows XP SP3 cmd.exe

(1) I copied it into UltraEdit32 and saved it as dt1.bat.



(2) I OPENED a command window in the folder & typed the name.



(3) I pressed ENTER



I am using Consolas as my console window font. (Not every console font has the same characters above ASCII 127.)

I pasted it into SciTE, the other editor I use a lot, and saved it as dt2.bat. Same results.

Then I fired up Notepad which I hardly ever use, pasted it in, and when I chose to save as dt3.bat I got a dialog saying that since the file contained Unicode characters, information would be lost if I chose to save it with ANSI encoding, & to cancel and pick a different encoding so I chose Unicode and when I ran the thus-saved batch I got an error

Code: [Select]'■@' is not recognized as an internal or external command,
operable program or batch file.


Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.







Salmon Trout - thank you for your sterling efforts. You will note that in line 5 of the script you posted the Extended Ascii codes have changed, probably during the pasting operation, therefore the result is not what I'm trying to achieve.

I have found that the Extended Ascii codes are changed when the script is pasted into Edit.com running in Cmd.exe so the output there is not what is wanted, but, when the script is pasted into Edit.com running in Command.com the codes are properly pasted and the output is aok.

Would you care to:
(a) Copy the script to your clipboard.
(b) Open Command.com
(c) Start Edit.com
(d) Paste the script into Edit.com
(e) Save the script as Something.bat (or .com)
(f) Run the file in Command.com and Cmd.exe
(g) Post your result

A big ask, your result will be appreciated.





Quote from: Dusty on December 25, 2009, 01:21:03 PM

(a) Copy the script to your clipboard.
(b) Open Command.com
(c) Start Edit.com
(d) Paste the script into Edit.com
(e) Save the script as Something.bat (or .com)
(f) Run the file in Command.com and Cmd.exe
(g) Post your result

command.com -> edit.com -> pasted -> saved as bat script

(1) run in command.com (command window font set to 7x12 raster font)



(2) same batch run in cmd.exe (7 x 12 raster font)






Quote from: Dusty on December 25, 2009, 01:21:03 PM
I have found that the Extended Ascii codes are changed when the script is pasted into Edit.com running in Cmd.exe so the output there is not what is wanted, but, when the script is pasted into Edit.com running in Command.com the codes are properly pasted and the output is aok.

cmd supports- or tries to support, unicode. command.com does not. Either way, you cannot run edit.com from within cmd; it spawns command.com to run it anyway, not sure exactly where the issue lies, but I assure you it has to do with unicode/ANSI support.

If you save as ANSI encoded in any text editor your batch will work (given that the fonts match)Salmon Trout - Thank you again, that's exactly what I was trying to replicate.

BC-P - sorry, I'm not sure what you mean. Quote
If you save as ANSI encoded in any text editor your batch will work (given that the fonts match)

It's been shown that attempting to save the script using Notepad brings up the warning shown below even when Ansi encoding is selected. Selecting Unicode MAKES the script unusable.



Quote from: Salmon Trout on December 25, 2009, 03:29:24 AM
Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.
Quote from: BC_Programmer on December 25, 2009, 06:36:30 PM
Quote from: Salmon Trout
Finally I saved it from Notepad as dt4.bat with ANSI encoding and it ran fine, just like the screen capture I posted above.


Yeah, sure, the script runs but does not produce the REQUIRED output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3. After saving the copy/post into Edit.com running in Command.com the script runs correctly and produces the required output as shown in Salmon Trout's reply #5.

Thank you for your interest, would you run the script in Vista and post your results please?

Quote from: Dusty on December 25, 2009, 10:01:12 PM
Yeah, sure, the script runs but does not produce the required output because the Extended Ascii chars have changed as shown in Salmon Trout's screen capture in reply #3.


none of the character codes were changed.

Quote
I am using Consolas as my console window font. (Not every console font has the same characters above ASCII 127.)

and then, in the later screenshots:

Quote
(command window font set to 7x12 raster font)


this is the key.

Anyway, I ran it on mine, and even though I was using Raster fonts, I still got the same characters as Salmon Trout:




I decided to investigate. the issue is rooted solely in code pages. When I visited character map and went to the code that corresponded to the character I saw, it was there, within the same set of fonts. under the same code. This was odd. BUT! I changed the "character" in character maps "advanced" section to "DOS-US" and the line drawing characters were there.

Since I'm on Vista x64 I cannot run edit and it isn't included with my OS. I was able to get agreeable results by "cheating" what I did, was I copied the batch file to the clipboard, used the command "copy con D:\test.bat" and used the cmd "paste" feature, followed by Control-Z and enter. I did end up with an extra @echo off line at the top, but it has no impact on the functionality.

I ran the batch resulting from this, and success!:



So it works, as long as the batch os created properly, in vista x64.

As it is now, there are a LOT of encoding conversions to get it on other machines, copy from browser, paste to editor, etc. So, I decided to simply plop it in a text file and attach it as is. this way, the file should be relatively untainted by any data manipulation performed by the OS during copy paste, and it will be easier for others using other operating systems to test... in fact... test on my win 7 laptop:



Note: these are both x64 systems; I'd imagine it will work fine on x86 versions of these Operating Systems, too.






[Saving SPACE, attachment deleted by admin]BC_P - thank you, the results you produced are greatly appreciated.

D..
3424.

Solve : Wanted a command line Software?

Answer»

Hi Guys

my files R in MP3

hence i request a command line (RM) To (MP3) and vice versa
converter

Not necessary RM format only just it shld b lower than Mp3
pls help Tried Google?
YEP ive tried every THING

but none of them proves useful

most of searches give me mp3 2 wav and all that stuffwma can be a lower bit RATE than mp3 for the same sound quality, allegedly.
Quote from: the_mad_joker on DECEMBER 27, 2009, 07:38:44 AM

yep ive tried every thing

but none of them proves useful

most of searches give me mp3 2 wav and all that stuff
really? have you tried to search for mencoder (or ffmpeg?")
3425.

Solve : How to zip file one by one thru command line?

Answer»

Hi

I am having trouble to managing my disk space.

Currently i am getting file in following format.

a_011209.txt
a_021209.txt
b_011209.txt
b_021209.txt

I want to create a batch file where it will prompt me to change the date from 011209( DDMMYY format) to 021209 and then compress these files one by one.

Thanks in advance for your help.

Manoj



C:\>compact /?
Displays or alters the compression of files on NTFS partitions.

COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]

/C Compresses the SPECIFIED files. Directories will be marked
so that files added afterward will be compressed.
/U Uncompresses the specified files. Directories will be marked
so that files added afterward will not be compressed.
/S Performs the specified operation on files in the given
directory and all subdirectories. Default "dir" is the
current directory.
/A Displays files with the hidden or system attributes. These
files are omitted by default.
/I Continues performing the specified operation even after errors
have occurred. By default, COMPACT stops when an error is
encountered.
/F Forces the compress operation on all specified files, even
those which are already compressed. Already-compressed files
are skipped by default.
/Q Reports only the most essential information.
filename Specifies a pattern, file, or directory.

Used without PARAMETERS, COMPACT displays the compression state of
the current directory and any files it contains. You MAY use multiple
FILENAMES and wildcards. You must put spaces between multiple
parameters.

C:\>C:\>type press.bat

Code: [Select]@echo off

sed s/011209/021209/ datfile.txt


sed s/011209/021209/ datfile.txt | compact /cC:\>press.bat
a_021209.txt
a_021209.txt
b_021209.txt
b_021209.txt

Setting the directory C:\ to compress new files [OK]

Compressing files in C:\

-------------------------
rem Uncompress
rem C:\>sed s/011209/021209/ datfile.txt | compact /uNote: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
Look here, Sed is near the bottom of the list.
http://unxutils.sourceforge.net/Quote from: Geek-9pm on December 28, 2009, 08:31:24 PM

Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
Look here, Sed is near the bottom of the list.
http://unxutils.sourceforge.net/

I believe my sed version is for 32-bit and the creation date is 2005.

The simple substitution(s) of one pattern in a file name for different pattern seems to work ok.

sed s/011209/021209/ datfile.txt

p.s. I have not used 64-bit

Quote from: Geek-9pm on December 28, 2009, 08:31:24 PM
Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
Look here, Sed is near the bottom of the list.
http://unxutils.sourceforge.net/

better to use GNU ones....see my sigQuote from: ghostdog74 on December 28, 2009, 09:50:24 PM
better to use GNU ones....see my sig
Thanks, my beady LITTLE eyes did not see that before.
Here is the link in big letters.
http://gnuwin32.sourceforge.net/packages.html
3426.

Solve : CDROM in Batch File?

Answer»

Hello,

I have looked for a forum search fuctino and I also went through many pages to see if I could FIND my answer. I am wondering how I within a batch file tell it to use whater drive letter the cdrom is, the batch file will be ran on a laptop so it will only have 1 batch file but I cannot figure out how to get it to use whatever drive letter it is other than just setting it to D:\ and making sure all the laptops cdrom drive is SET to D:\. Is their a way for a batch to use whatever drive letter the cdrom might be? Below is the set drive that is D:\ would like to get that changed to use whatever drive letter the cdrom might be. I have tried SET PATH=%CDROM% and changing the d:\ifly.exe to %CDROM%:\ifly.exe but it does not work. Also a little ways down it calls for the cdrom drive again. If it put it to D:\ it will work just fine.

Code: [Select]ECHO 1 - Run ifly Installation Program
ECHO 2 - Update Manuals
ECHO 3 - EXIT
ECHO.
SET /P M=TYPE 1, 2 or 3 then press ENTER:
IF %M%==1 GOTO START
IF %M%==2 GOTO MANUALS
IF %m%==3 GOTO EXIT
:START
d:\ifly.exe
GOTO MENU
:MANUALS
rmdir c:\manualsupport /s /q
mkdir c:\manualsupport
xcopy /E d:\manualsupport\*.* c:\manualsupport\
xcopy /E /Y c:\manualsupport\nircmd\*.* c:\windows\
xcopy /E /Y c:\manualsupport\Shortcut\*.* c:\windows\
start c:\manualsupport\filespresent.bat
exit
:EXIT
exitI have found a generic way of doing it

having

Path=D:\;E:\;F:\;G:\; etc..

removing

Code: [Select]ifly.exe
GOTO MENU
:MANUALS
rmdir c:\manualsupport /s /q
mkdir c:\manualsupport
xcopy /E manualsupport\*.* c:\manualsupport\

seems to work testing now to make sure it all works.
C:\test>type chtoE.bat
Code: [Select]cd C:\test
E:
dir a*.txt
C:

Output:

C:\test>chtoE.bat

C:\test>cd C:\test

C:\test>E:

E:\>dir a*.txt
Volume in drive E is My Book
Volume Serial Number is 0850-D7C5

Directory of E:\

11/10/2009 03:24 PM 36 abc.txt
11/13/2009 01:21 PM 198 abc2.txt
11/17/2009 05:36 PM 290 abc5.txt
12/21/2009 01:29 PM 144 arc.txt
12/24/2009 09:58 PM 269 awkinfile.txt
12/23/2009 10:56 PM 39 awlinfile.txt
6 File(s) 976 bytes
0 Dir(s) 139,043,950,592 bytes free

E:\>C:

C:\test>So I finally found my answer, all I had to do was remove the d:\ifly.exe so it is what is below and remove the d: to what it is below. all is WORKING now.

Code: [Select]ECHO 1 - Run ifly Installation Program
ECHO 2 - Update Manuals
ECHO 3 - Exit
ECHO.
SET /P M=Type 1, 2 or 3 then press ENTER:
IF %M%==1 GOTO START
IF %M%==2 GOTO MANUALS
IF %m%==3 GOTO EXIT
:START
ifly.exe
GOTO MENU
:MANUALS
rmdir c:\manualsupport /s /q
mkdir c:\manualsupport
xcopy /E \manualsupport\*.* c:\manualsupport\
xcopy /E /Y c:\manualsupport\nircmd\*.* c:\windows\
xcopy /E /Y c:\manualsupport\Shortcut\*.* c:\windows\
start c:\manualsupport\filespresent.bat
exit
:EXIT
exit

3427.

Solve : if and set?

Answer»

where can i find the FILES for the if and set command on my COMPUTER i NEED them for compatibility of my batch file.If and Set are internal commands and are available only in the CMD shell.

Quote

i need them for compatibility of my batch file.
What???

EXTERNAL commands and CMD internal commands are SHOWN here http://ss64.com/nt/

3428.

Solve : Delete redundant files from backup folder?

Answer»

Hi there, I've had a search through the forum and couldn't find anything specific to my query but if there is already a post related to it I'd be happy to be pointed in the right direction.

At work I have a folder on my C drive which I use to store Excel, PowerPoint & Word Documents, as well as lots of .jpg image files that I use. I have a batch file that I use so that I can copy the contents of this folder to a location on the company server where people can access it.

The batch command for this file is as follows (I have REMOVED the exact names and locations of the folder):

@echo off

xcopy "C:\Location" "G:\Location" /D /E /Y


This command allows me to automatically copy all additional files or edited files to the desired location by simply running the command as expected.

What I would like to do though is have files that are no longer in the source folder (ones on C drive) removed from the destination folder (ones on G drive). The reason for this is that the destination folder on the company server is gradually creeping up in size and I don’t see any need for it. All I need is for the 2 folders to be synced so that they contain the exact same INFO. I believe this would involve a delete command but I am unsure how to go about this.

Ideally I think Robocopy is what is used for this sort of thing but I have contacted my IT department and have not had any feedback yet so would like to see if I could try something out myself.

I'll just add that I am not very experienced in using command prompts so would appreciate if you could explain things in laymen’s terms

Many Thanks

TS

C:\test>comp /?
Compares the contents of two files or sets of files.

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[liNE]]

data1 Specifies location and name(s) of first file(s) to compare.
data2 Specifies location and name(s) of second files to compare.
/A Displays differences in ASCII characters.
To compare sets of files, use wildcards in data1 and data2 parameters.

C:\test>dir m*.bat
Volume in drive C has no label.
Volume Serial Number is 0652-E41D

Directory of C:\test

04/27/2010 12:03 PM .
04/27/2010 12:03 PM ..
04/24/2010 02:39 PM 199 matt.bat
04/25/2010 11:27 AM 260 matt2.bat
04/25/2010 11:34 AM 307 matt3.bat
04/25/2010 11:41 AM 224 matt4.bat

C:\test>copy matt2.bat matt5.bat
1 file(s) copied.

C:\test>comp matt2.bat matt5.bat
Comparing matt2.bat and matt5.bat...
Files compare OK

Compare more files (Y/N) ? n

C:\test>Here is some information that may help. But it is not abut batch files. It is about how to keep a local drive and a network drive in sync.
How to use offline files in Windows XPThanks for the info guys but I have already solved the issue.

I ended up using the following command:

robocopy "source" "destination" /mir /z

TSQuote

Robocopy.exe: ROBUST File Copy Utility
Overview
The Microsoft® Windows® Server 2003 Resource Kit Tools are a set of tools to help administrators streamline management tasks such as troubleshooting operating system issues, MANAGING Active Directory®, configuring networking and security features, and automating application deployment.
Windows Server 2003 Resource Kit ToolsQuote from: Geek-9pm on April 28, 2010, 11:12:25 AM
Windows Server 2003 Resource Kit Tools

it also comes with Vista and Windows 7 by default.
3429.

Solve : ERRORLEVEL = 0 within FOR loop?

Answer»

I have posted previously about my DR check batch file, but just one issue remains...

I have this code within the batch...

example.txt contains the following line for testing...
Quote

\autoexec.bat

The for loop contains; - I changed the FIND to wwwwwwww to force a failure.
Code: [Select]set TIB=example.txt
set SERVER=C:
for /f "eol=; tokens=* delims=" %%i in (%TIB%) do (
dir "%SERVER%%%i" | find "wwwwwwww" >nul
if %ERRORLEVEL%==0 (
echo Located - %SERVER%%%i >> %logfile%
) ELSE (
echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile%
)
)

For some reason ERRORLEVEL always RETURNS zero even if the file doesn't exist, I'm assuming that's because the FOR command didn't error even though the dir command did.
If I run the DIR command outside the FOR loop it returns errorlevel 1

Does ANYBODY know of a way around this?you can try

Code: [Select]set TIB=example.txt
set SERVER=C:
for /f "eol=; tokens=* delims=" %%i in (%TIB%) do (
dir "%SERVER%%%i" | find "wwwwwwww" >nul
if ERRORLEVEL 1 (
echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile%
) else (
echo Located - %SERVER%%%i >> %logfile%

)
)

Or:
setlocal enabledelayedexpansion
set TIB=example.txt
set SERVER=C:
for /f "eol=; tokens=* delims=" %%i in (%TIB%) do (
dir "%SERVER%%%i" | find "wwwwwwww" >nul
if %ERRORLEVEL%==0 (
echo Located - %SERVER%%%i >> %logfile%
) else (
echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile%
)
)
endlocaltry this

variables set and read inside parenthetical expressions need delayed expansion.

setlocal enabledelayedexpansion
set TIB=example.txt
set SERVER=C:
for /f "eol=; tokens=* delims=" %%i in (%TIB%) do (
dir "%SERVER%%%i" | find "wwwwwwww" >nul
if !ERRORLEVEL! EQU 0 (
echo Located - %SERVER%%%i >> %logfile%
) else (
echo ***ERROR*** - %SERVER%%%i, does not exist or incorrect file date >> %logfile%
)
)
Thanks, not quite correct but you gave me a good pointer...

I just needed to replace % with !...
Code: [Select]if !ERRORLEVEL!==0
setlocal command was already added but not included it in my post above

I've noticed another issue, but I'll create a new post Quote from: ShadyDave on April 29, 2010, 07:39:36 AM
not quite correct

Code: [Select]if !ERRORLEVEL!==0
Code: [Select]if !ERRORLEVEL! EQU 0
These two are equivalent; I don't understand why you call my VERSION "not quite correct".
It created an error USING the EQU for some reason :-(Quote from: ShadyDave on April 29, 2010, 04:12:13 PM
It created an error using the EQU for some reason :-(
What was the line?
If !ERRORLEVEL! EQU 0 echo There was no error...

should work properly.Quote from: Helpmeh on April 29, 2010, 06:11:31 PM
What was the line?
If !ERRORLEVEL! EQU 0 echo There was no error...

should work properly.

It works properly for me.
3430.

Solve : Only copy folders?

Answer»

Is there a way just to copy a folder and all its subfolders but not the FILES in it???TRY using XCOPY with the /T and /E SWITCHES. This will copy the directory structure (including empty directories and sub-directories) without copying the files.

Good luck. Thanks a lot - it works fine

3431.

Solve : Batch file to move certain files+in sub folders?

Answer»

Hey,

I am looking for a SOLUTION on how to create a batch file to move all files with the extension .avi PLUS if there are any .avi in sub folders to move them too.



Example in pseudo code

Move C\Videos\*.avi TO D\Other videos
Move C\Videos\different folder names\*.avi TO d\Other Videos

Thanks in advance

for /f "delims=" %%A in ('dir /s /b c:\videos\*.avi') do move "%%A" "d:\other videos"

3432.

Solve : Help create folders from a txt file including subdirs?

Answer»

Hi. I found a simple BATCH program that will create directorie/folders from a txt file (ie., LIST.txt). It looks like this:
Code: [Select]@echo off
for /f %%i in (folders.txt) do mkdir %%i

However, it only works if your list in the txt file has single level directories, like this:
Code: [Select]folder1
folder2
folder3
etc...
What does the code need to add subfolders like this:

EXAMPLE txt file:
Code: [Select]folder1/subfolder1
folder2/subfolder2
folder3/subfolder3
etc...
?

The bat file will not make the subfolder. Is there a way to do it?In folders.txt change all the / to \

then it will work. I just tested it.

Thanks. That was a typo. My txt file has '\'. The problem is when you add a space in the name: 'folder 1\subfolder1'. The program will only create:'folder'. It's probably a simple solution of which i don't know Quote from: adabo on May 02, 2010, 08:10:20 AM

Thanks. That was a typo. My txt file has '\'. The problem is when you add a space in the name: 'folder 1\subfolder1'. The program will only create:'folder'. It's probably a simple solution of which i don't know

1. The default token delimiter in FOR /F is a space, so FOR will stop at the first space in each line of folders.txt. You must make FOR take the WHOLE line by USING "delims=".

2. In mkdir or any other operation where a file, folder or path name has one or more spaces, use quote marks. You can use them anyway, they do no harm.

mkdir "A folder name with spaces"

Code: [Select]@echo off
for /f "delims=" %%i in (folders.txt) do mkdir "%%i"
3433.

Solve : DOS security password?

Answer»

oh my GOSH- I need help! I'm trying to HACK into my sons COMPUTER- he deleted or changed my administrator info/password somehow.

I bought password recovery software, but can't figure out how to use it- or even get it on the stupid disk.
I, God only knows how, got into DOS security and enabled a boot password, thinking it was for the "Administrator" in Windows. Not so. N
ow it won't boot into Windows at all until I put in the password and I don't know how to get back into DOS to disable the password until I can figure out this software! I didn't want him to know!
He has Windows Vista- and I am unable to access the administrator OR his account.
Obviously I am computer impaired- HELP!!!!!Why were you meddling with your son's computer? How do we even know you are telling the truth? His computer - your admin password - something does not add up here.
Listen- I am happy to give you my phone number if you need- I bought him the laptop last Christmas- I am the admin- he is the user- I wanted to make sure I could "keep an eye" on what he's up to- as a responsible parent. Somehow- he was able to remove/ or change my password.
My son is almost 17 years old. He has suddenly stopped working out- which, by the way, is his favorite past-time, has started lieing, grades are failing, has money I have no idea where has come from-comes homes with an appetite that's unreal. I have two little girls that are greatly influenced by all this.
I "saw" an instant message that said his friend was searching the basement for his parents prescription drugs. His other friend told me they snort percacet or whatever else they can get their hands on. I was trying to find out where they're suppose to meet tonight, at 4:30 and put the fear into ALL of them.
I realize you have no reason to believe me, but I am single- educated and extremely hard working and scared to death for my son.
Please help me. I didn't want him to know so I can see exactly what's going on for myself. Certainly he's not going to tell me he's secretly hooked on drugs.
Please help me.

A very affecting story. It might be true. It probably is. However, we don't advise how to crack passwords. For these reasons: 1. It generally isn't possible. 2. We have no way of verifying the genuineness of the reasons given. 3. This forum is on the world wide web and anyone anywhere can read it.

Thank you for your response! Please understand, I'm not asking for help cracking HIS password. I purchased software to get back into MY account- which is the admin.

I enabled a DOS password, thinking it was "linked" to the admin WIndows password- which is now required to boot windows- I KNOW that password. I need to disable it, and can't figure out how to get back into DOS without access to Windows.

Do you know what I mean?I don't know of any "DOS password", and I've been using MS-DOS and Windows since 1982.
I believe he is talking about a bios password.

If you can see the screen at boot it will tell you to how to access the bios (usually F2 or Del). once in the bios look for security and then select password then delete or disable.

This will require the password you entered last time. ok- maybe that makes better sense- I have no idea what I did or how I did it- when I boot the computer up, it automatically asks me for the admin password I created, I guess in bios-then Windows opens when
When I hit f2 or delete upon start up, it still simply asks me for the password- I can't seem to access the place I was in where I enabled the password in the first place.
It's the "bios" boot password, I want to disable- I know the password, I just can't get past it after that.If it is a laptop machine and whoever enabled a BIOS password your only choice is to take the laptop to an authorised service center in your area...

You will need to provide proof of ownership.The OP created a bios password thinking it it is the administrator password. I am afraid we can't help you as any information is available to anyone with a computer. Even though your case may be true, if we help you, people with more malicious intentions may use it for bad purposes. Quote from: patio on October 30, 2009, 03:46:15 PM

If it is a laptop machine and whoever enabled a BIOS password your only choice is to take the laptop to an authorised service center in your area...

You will need to provide proof of ownership.
wow. That is QUITE a bump.

Anyway, I sure hope the original parent learned how to be a parent and talk to his kids instead of slinking AROUND in the shadows and talking about then like they are enemies.
3434.

Solve : netstat -an Help?

Answer»

When I type this in the run box on my XP machine it opens momentarily with a small list that shows what I am doing. Then fills with something else but closes out before I have time to read it. SEEMS suspicious ? THANKS R CTry it with opening the window with start/run cmd...instead of the command prompt,Thank you so much, it worked GREAT, not sure why but thats is OK !Now I would like to know what I am looking at. Can anyone tell me where to GO to learn about this list. ?

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\R C Tingle>netstat -an

Active Connections

Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 24.156.109.182:139 0.0.0.0:0 LISTENING
TCP 24.156.109.182:1472 82.99.19.52:80 CLOSE_WAIT
TCP 24.156.109.182:3913 66.102.7.104:80 TIME_WAIT
TCP 24.156.109.182:3916 66.102.7.101:443 TIME_WAIT
TCP 24.156.109.182:3918 66.102.7.104:443 TIME_WAIT
TCP 24.156.109.182:3920 66.102.7.100:443 TIME_WAIT
TCP 24.156.109.182:3922 66.102.7.100:80 ESTABLISHED
TCP 24.156.109.182:3925 66.102.7.100:80 TIME_WAIT
TCP 24.156.109.182:3928 66.102.7.154:80 TIME_WAIT
TCP 24.156.109.182:3929 66.102.7.101:80 TIME_WAIT
TCP 24.156.109.182:3930 66.102.7.101:80 TIME_WAIT
TCP 24.156.109.182:3936 74.125.127.118:80 TIME_WAIT
TCP 24.156.109.182:3945 72.14.213.139:80 ESTABLISHED
TCP 24.156.109.182:3946 72.14.213.139:80 ESTABLISHED
TCP 24.156.109.182:3951 69.72.169.241:80 TIME_WAIT
TCP 24.156.109.182:3953 69.72.169.241:80 TIME_WAIT
TCP 24.156.109.182:3954 69.72.169.241:80 TIME_WAIT
TCP 127.0.0.1:3910 127.0.0.1:3911 ESTABLISHED
TCP 127.0.0.1:3911 127.0.0.1:3910 ESTABLISHED
TCP 127.0.0.1:3914 127.0.0.1:3915 ESTABLISHED
TCP 127.0.0.1:3915 127.0.0.1:3914 ESTABLISHED
TCP 127.0.0.1:5152 0.0.0.0:0 LISTENING
TCP 127.0.0.1:5152 127.0.0.1:3912 CLOSE_WAIT
UDP 0.0.0.0:445 *:*
UDP 0.0.0.0:500 *:*
UDP 0.0.0.0:4500 *:*
UDP 24.156.109.182:123 *:*
UDP 24.156.109.182:137 *:*
UDP 24.156.109.182:138 *:*
UDP 24.156.109.182:1900 *:*
UDP 127.0.0.1:123 *:*
UDP 127.0.0.1:1900 *:*

C:\Documents and Settings\R C Tingle>

3435.

Solve : Check Network path exists?

Answer»

Hi everyone,

Can someone advise on checking if a network path (Z:\abc) is already in existance ?

If the answer is no I want to create it...I was just going to use "goto commands for this part"

Cheers
NeilIf the network drive is mapped to drive Z, then this should work:

Code: [Select]if exist Z:\nul (do something) else (do something else)

If the network drive is not mapped to a drive letter, this notation should work:

Code: [Select]if exist \\servername\sharename\ (do something) else (do something else)

Good luck. Thanks sidewinder !!

NeilSidewinder...just a couple quick questions :-

1. What is the nul for :-
Z:\nul

2. I tried to use the same code to check for a exists file :-
if exist C:\cae_prog\pdms\v11.6\CadCentre\mong_evars.bat (goto :evarscopied) else (goto :copyevars)

But it CARRIED out both :-
:evarscopied
:copyevars

So what did I get wrong ?

Cheers
NeilQuote

1. What is the nul for :-
Z:\nul

It's legacy code to indicate a directory and not a file. Don't think it's necessary on the more modern OSes.

Quote
2. I tried to use the same code to check for a exists file :-
if exist C:\cae_prog\pdms\v11.6\CadCentre\mong_evars.bat (goto :evarscopied) else (goto :copyevars)

But it carried out both :-
:evarscopied
:copyevars

I think control was passed to :evarscopied and then FELL into :copyevars. Normally goto is used without the : marker and the call is used with the : marker when calling an internal subroutine.

Code: [Select]if exist C:\cae_prog\pdms\v11.6\CadCentre\mong_evars.bat (call :evarscopied) else (call :copyevars)
.
.
.
goto :eof

:evarscopied
.
.
.
goto :eof

:copyevars
.
.
.
goto :eof

Before call :label came on the scene, I used to use goto for internal subroutines by setting a variable to a label name immediately following the goto. I could then use a goto to the variable (which held the label name); this allowed control to be returned to the next sequential instruction after the goto. Primitive yes, but in those days we learned to make do

Good luck.

Quote from: Sidewinder on April 20, 2010, 06:18:30 AM
It's legacy code to indicate a directory and not a file. Don't think it's necessary on the more modern OSes.

http://blogs.msdn.com/oldnewthing/archive/2003/10/22/55388.aspxHi almost got this working...one glitch is left the server name...

If I was going to path my drive and folder in I would use :-
net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO

I've tried this...to check the existance of the drive :-
if exist \\Saosl10005.Alst.no\Tcm (goto :pathexists) else (goto :newpath)

But it's not working...

So what have I got wrong in my code..

Thanks
NeilCode: [Select]If I was going to path my drive and folder in I would use :-
net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO

What does "I would use" mean? Did you use net use or not?

If the drive is mapped successfully, there is no reason for the exist test. Do you really want to use goto and not call? By using the : marker it makes it difficult to see what your trying to do.

Based on your code, this might be simpler:

Code: [Select]@echo off
if exist Z:\nul goto :pathexists
net use Z: \\SAOSL10005.ALST.NO\TCM /PERSISTENT:NO 1>NUL 2>NUL
if errorlevel 1 goto :error
if errorlevel 0 goto :pathexists

:pathexists
echo pathexists
goto :eof

:error
echo error
goto :eof

Should you decide to use call instead of goto, the code may need to be tweaked.

I wanted to check the for the full path :-
Z: \\SAOSL10005.ALST.NO\TCM

Just INCASE there was already a Z:\, but different path :-
Z: \\SAOSL10006.ALST.NO\Files

Cheers
NeilThe path is either Z:\ or \\SAOSL10005.ALST.NO\TCM, the former being conventional notation, the latter using UNC notation.

You can't use both, but you should be able to parse the net use output which will co-relate the local mapped drive to the remote device name. That should give you enough information as to whether the Z: drive is mapped and if so mapped correctly.

Code: [Select]@echo off
for /f "tokens=2-3" %%i in ('net use ^| find /i "Z:"') do (
if not errorlevel 1 (
set local=%%i
set remote=%%j
goto Mapped
)
)

:UnMapped
.
.
.
goto :eof

:Mapped
echo Local drive: %local%
echo Remote Drive: %remote%
.
.
.
goto :eof

If drive Z: is not mapped, the logic will fall into the :UnMapped label. If drive Z: is mapped, the logic will leave the for LOOP and start executing at the :Mapped label. I'll let you fill in the blanks.

The if statement in the for loop is written *censored*-backward. Unlike REXX for example, the nop instruction does not exist in batch code. NOP (no operation) is a GREAT target for conditional statements as it improves readability.

Dare I say good luck? Quote from: Sidewinder on May 04, 2010, 07:09:51 PM
The if statement in the for loop is written *censored*-backward. Unlike REXX for example, the nop instruction does not exist in batch code. NOP (no operation) is a great target for conditional statements as it improves readability.

REXX is the only language aside assembly that has a NOP, as far as I know...
3436.

Solve : How to input the username and password on the script??

Answer»

Dear all,

I am writing a script as follow, I want to copy LOCAL(192.168.2.1) E:\ drive some FOLDERS and files to remote PC 192.168.1.1, but there is a problem, it require the username and password when access the folder of 192.168.1.1, I have the username and password, but how to input on the script? and how to encode the password?

@echo off
echo.
echo CREATING folders...
Set mm=%DATE:~4,2%
Set dd=%DATE:~7,2%
Set yyyy=%DATE:~10,4%
mkdir "\\192.168.1.1\new\%yyyy%%mm%%dd%"
echo.
xcopy "E:\CSCOpx\files\rme\dcma\shadow\*.*" "\\192.168.1.1\new\%yyyy%%mm%%dd%" /E


Thanks!

3437.

Solve : Batch File - Select the text within { and }?

Answer»

I'm looking to make a batch file for BitLocker and I need to COPY the GUID after running "manage-bde -protectors C: -get". The GUID is in the {} BRACKETS, so it would be somewhat easy to NARROW the TEXT SEARCH needed to that area. Another option would be to get the GUID directly and store it as a variable.

3438.

Solve : Missing something - option to tell it where to save?

Answer»

Hello.

This is my first attempt at writing a batch script, so go easy on me. lol

I tested this script a few hours ago, and overall, it took about 15-20 minutes to run (~25.5 gigs of data)

As you can see, it's just a simple backup script. But, one thing that's been irking me about it (even though I'm a novice) is that I haven't found any info online (or maybe I'm just using the wrong search terms) on how I can get the script to prompt the user for a backup location.

The location that's listed (F:\Backup_%mm%-%dd%-%YYYY%\) is a local drive on my personal system. However, not everyone will have several hard drives and/or partitions to put the backup on.

With that said, lets assume that the user who runs this script, has an external drive plugged into their system. How can I get the script to prompt them for a location that they can enter?

Also, is there something I can add that will show the user the location of the backup?

For example, when the script is done, it will print out a message that says:

"Backup complete! Your backed up data is located in: X:\Backup_date_of_backup"

Thanks in advance!

Here's my script thus far:

Code: [Select]@echo off
echo ***********************************
echo * Vinny's Data Backup Script v1.0 *
echo ***********************************
echo.
echo This script will back up your Itunes music, videos, personal photos,
echo and internet favorites into a folder labeled with todays date,
echo which you can then burn to DVD(s) or copy to an external harddrive.
echo.
pause
echo Creating folders...
Set mm=%DATE:~4,2%
Set dd=%DATE:~7,2%
Set yyyy=%DATE:~10,4%
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Itunes
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Pictures
mkdir F:\Backup_%mm%-%dd%-%yyyy%\Favorites
echo.
echo Done!
echo.
pause
echo Preparing to back up your Internet Bookmarks...
xcopy "%USERPROFILE%\Favorites\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Favorites\" /e
echo.
echo Preparing to backup your personal photos...
xcopy "%USERPROFILE%\My Documents\My Pictures\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Pictures\" /e
echo.
echo Preparing to backup your Itunes Library...
xcopy "%USERPROFILE%\My Documents\My Music\iTunes\*.*" "f:\Backup_%mm%-%dd%-%yyyy%\Itunes\" /e
pause
(P.S: Overall thoughts on this script?)after the first pause put

set /p dr=enter external drive letter:

and replace
F:\ with %dr%:\Quote from: mat123 on April 30, 2010, 09:43:57 PM

after the first pause put

set /p dr=enter external drive letter:

and replace
F:\ with %dr%:\

Thanks for your reply. However, when I added that, i get the following output:

"The filename, directory name, or volume label SYNTAX is INCORRECT"
after it tries creating the folders (mkdir).

The command is written out like this:

mkdir %dr%:\Backup_%mm%-%dd%-%yyyy%\Favoritesand what are you entering in the prompt given by set /p?Quote from: BC_Programmer on May 04, 2010, 08:02:48 PM
and what are you entering in the prompt given by set /p?

I've tried several different variations:

i
i:
i:\

and they all return the same error(s) because it's trying to create 3 folders on the drive that I specifyyou have to enter a single letter.

try echoing %dr%:\ after you enter it and see what it expands to.



Additionally, I found a pretty neat course online that deals with writing a backup utility, and it served me as a great REFRESHER of batch scripting since I haven't done it in over ten years.

It's put together pretty well but uses some old-school techniques. In any case, it was worth the few hours to me to go through it and adapt the program to my needs while (re)learning to write batch scripts.

http://www.allenware.com/icsw/icswidx.htm
3439.

Solve : Using batch script to parse directories from a string?

Answer»

I'm writing a script that needs need to call a parameter from an EXECUTABLE's initialization file. I know where the executable is in this instance, but I'd like to write a reusable subroutine as I see this as a potential helpful TOOL. What I am after specifically would be the following:

Program 1.exe has a parameter file located at:

c:\a\b\c d e\f\g.ini

Program 2.exe similarly has one located at:

c:\a\b\c d e\256\here_there\initialize.xml

I'd like to have the subroutine work as follows:

Code: [Select]:: extract.bat
@echo off

:GetTarget from user input

set FILEPATH="c:\a\b\c d e\f.txt"
if not (%1)==() set FILEPATH=%1

REM where FILEPATH is a path to a file, whether fully qualified
REM or relative doesn't matter, we'll parse the string and
REM make it fully qualified and even set environmental
REM VARIABLES as needed.

:CheckExist make sure the expanded %FILEPATH% exists
echo. Checking to see if %FILEPATH% exists...
echo.
if not exist %FILEPATH% (echo.%FILEPATH% does not exist or is not a valid file name.
goto :EOF
)
echo. %FILEPATH% exists.
echo.

:EXPAND FILEPATH to parse
if "FILEPATH"=="" goto :JUMPOUT
for /f "tokens=1* delims=\" %%a in ("%FILEPATH%") do (
echo. %%a
set FILEPATH=%%b
goto :EXPAND
)

:JUMPOUT

:EOFHere's where I get a little confused. I guess I need to echo the output to a temp file in %TMP% so I can use the find command, but there has to be an easier way to parse the result.

Finding the drive should be easy since we can search on a ':' and the letter prior is the drive.

Finding the file name should be easy as it will be the last output. However, I don't want to use a FIND command here because the file may or may not have an extension.

The rest of the path should be easy as we can just construct the directories as the variables in between.

set path=%dir1%%dir2%%dir3%...%dir*%

However, getting each of these above output lines into a variable is where I am a little fuzzy.

Also, I want to be able to check the path of the extract.bat file itself and test to see if the string provided in the input is a fully qualified path or a relative path to the current directory, and then regardless of the input construct a fully qualified path as a possible output to pass to another subroutine.

Any advice or hints or input on this script would be greatly appreciated.
Quote

:EXPAND FILEPATH to parse
if "FILEPATH"=="" goto :JUMPOUT
for /f "tokens=1* delims=\" %%a in ("%FILEPATH%") do (
echo. %%a
set FILEPATH=%%b
goto :EXPAND <-------------------- this won't work!
)

:JUMPOUT

Sounds like you should study the FOR DOCUMENTATION... type FOR /? at the prompt... Look for the variable modifiers.

to extract the path from a fully qualified path and filename is quite simple

Code: [Select]for /f "delims=" %%A in ("C:\folder1\folder2\folder3\filename.ext") do (
echo drive %~dA
echo path %~pA
echo name %~NA
echo extension %~xA
)

Code: [Select]drive C:
path \folder1\folder2\folder3\
name filename
extension .ext
Quote from: Salmon Trout on May 05, 2010, 12:37:21 PM
Sounds like you should study the FOR documentation... type FOR /? at the prompt... Look for the variable modifiers.

to extract the path from a fully qualified path and filename is quite simple

Code: [Select]for /f "delims=" %%A in ("C:\folder1\folder2\folder3\filename.ext") do (
echo drive %%~dA
echo path %%~pA
echo name %%~nA
echo extension %%~xA
)

Code: [Select]drive C:
path \folder1\folder2\folder3\
name filename
extension .ext
3440.

Solve : make long filename folders with makedir?

Answer»

Too many YEARS - too much forgotten. My batch file which use MD to create directories from a list of new folders have stopped working for some reason. It used to be that the command line

MD "This Folder Has A LONG Name"

made a folder with that name. Now, I get six folders named "This", "Folder", "Has", "A", "Long" and "Name". Been searching for the simple "Duh" answer for days. Does someone remember out there?

Spending Hours to save minutes. and haven't found a real reference yet. Running XP Pro SP3 on 4 year old AMD64 box w/2 gig RAM.

I know this must have an easy answer, and it would be much appreciated.
Code: [SELECT]S:\Test\longname>md "This folder has a very long name indeed"

S:\Test\longname>dir
Volume in drive S is USBHD
Volume Serial Number is 2C51-AA7F

Directory of S:\Test\longname

05/05/2010 06:43 PM <DIR> .
05/05/2010 06:43 PM <DIR> ..
05/05/2010 06:43 PM <DIR> This folder has a very long name indeed
0 File(s) 0 bytes
3 Dir(s) 197,617,135,616 bytes free

S:\Test\longname>

Post your batch file.
Thank's much for your post. In copying and testing my original batch file, it created unusual characters in the filename which were not in the batch text, so I noted it was saved in UTF-8. When changed it to ANSI, it was less weird, but still made a directory for each noncontiguous word after MD". When the command is typed in the dos window, all is fine, but when in the batch file, is not fine.

The non-working batch looks thus:
G:
CD..
CD G:\Audio\_Raw downloads
MD "1006 281 1202-1206"
CD "1006 281 1202-1206"
MD “1 filenr1 (Speaker1 name here)”
MD “2 filenr2 (Speaker2 name here)”
MD “3 filenr3 (Speaker3 name here)”
MD “4 filenr4 (Speaker4 name here)”
MD “5 filenr5 (Speaker5 name here)”
MD “6 filenr6 (Speaker6 name here)”
PAUSE
It is not the spaces that are causing your problem - you are using the wrong kind of QUOTES.

You are using these quotes

“ ”

You need to use ordinary double quotes like this

" "

see this code which works

Code: [Select]MD "1 filenr1 (Speaker1 name here)"
MD "2 filenr2 (Speaker2 name here)"
MD "3 filenr3 (Speaker3 name here)"
MD "4 filenr4 (Speaker4 name here)"
MD "5 filenr5 (Speaker5 name here)"
MD "6 filenr6 (Speaker6 name here)"
I am ecstatic! Thanks for the solution! As I expected, it was something dumb.

in Notepad, I changed the display font to "system" from Tahoma and it confirmed the
problem in quotes characters which then displayed as vertical bars. The original text is copied from an Excel Spreadsheet which looks at paste from a web page and using text handling equations, creates the batch text. An unconscious change of font created the whole thing.

It is done!

Mahalo from Honolulu.
I strongly suggest that when you are creating or editing code that you use a monospaced font such as Courier New, Lucida Cosole or Consolas. These fonts are much better for consoles and code editors.
It will be heeded. Again, many thanks for your commitment and ongoing contributions to many others.

3441.

Solve : getting file size with space in folder...?

Answer»

I'm trying to get the FILE size of a file using the following code;

Code: [Select]for/F %%i IN ("\\SERVER\snp_other_rsync\new folder\test.txt") DO echo %%~zi
But %%~zI equals Nul.

Is it not possible to check file size where there is a space in the path?Quote

Is it not possible to check file size where there is a space in the path?

Yes it is. You have to STUFF the entire file name into a single variable either by ELIMINATING the space as the default delimiter or DECLARING a single variable with the spaces included:

I chose the later:

Code: [Select]@echo off
for /f "TOKENS=*" %%i in ("\\server\snp_other_rsync\new folder\test.txt") do echo %%~zi

Good luck.
3442.

Solve : batch file to open an antivirus program, update, run, close, then open another?

Answer»

scenario:
I have 3 anti-virus programs on a LIVE cd (UBCD) I want to write a batch file to open one of the antivirus programs, update, run, and remove threats. Then I want the 2nd and 3rd antivirus programs to do the same.


My big question
"Is this possible?" I know I can start the programs ,but the commands to get the programs to update and run I have no idea. If anyone knows about an article or book I could read that would be great. The antivirus/ MALWARE removal programs would be. Spybot sd, Malware byte, and Avast.

I read that you could find the path to the executable then go into command prompt and cd to that directory and the help command would bring up the batch commands associated with the program but no luck 4 me. For instance if mbam.exe was located in c:/programfiles(x86)/malwarebytes/mbam.exe then I would cd to malwarebytes and type "mbam /?" to bring up the batch command associated with malwarebytes. Here is the article: http://technet.microsoft.com/en-us/library/cc750054.aspx
I couldn't bring up anything so if anyone else has any insight that would be great.Check out the command line arguments for Spybot, MBAM and Avast

The MBAM update is interactive and pops up a windows informing the user the update was done. It also pops up a windows if any nasties are found. Spybot is completely automated with the right set of parameters. I have no experience with Avast.

Good luck. THANK you for the help I got the script to update and run a SCAN using a batch file but like you said it prompts you to click OK when it is updated and OK when it starts the scan. Does anyone know if its possible to write a script to click OK automatically without having to physically click OKFor Spybot, the following parameters will do everything unattended:

Code: [Select]SpybotSD.exe /autoupdate /autoimmunize /autocheck /autofix /autoclose

For MBAM, the following parameters will do the scan unattended:

Code: [Select]mbam.exe /scan -quick -terminate

You can replace the -quick parameter with -full for a full scan. The scan will only popup a window if any nasties are found so you can clean them up.

In both cases you may need to add a fully qualified path to the executable.

Quote

Does anyone know if its possible to write a script to click OK automatically without having to physically click OK

For the MBAM update popup you'll need to switch to a Windows script language (VBScript, JScript and Powershell 2 are already installed on your machine; others can be downloaded and installed)

As mentioned I have no experience with Avast, so try playing around with the parameters until something accomplishes what you need. All three programs have help files which may explain more than the webs pages that were posted.

3443.

Solve : unable to eliminate a moving icon.?

Answer»

I AM NEW TO APPLE IMAC. THE LOADING ICON (DISC MOVING ROUND AND ROUND) NEVER STOPS AND DOES NOT LET ME CHOOSE A SUBJECT AS LONG AS IT IS MOVING. THE POINTER ALSO IS NOT ABLE TO BE USED TO POINT AT ANYTHING.
I THINK IT DOES THIS WHEN SAFARI IS CHOSEN FROM THE DOCK. this is the Microsoft Dos fourum not apple please POST in the correct SECTION

3444.

Solve : Limit extension search to 3 characters?

Answer»

Hello I have a reasonably simple problem using the FOR command.

When I execute the batch-file below all *.sas files from the source folder should be copied to the destination folder.

This works basicly but there are also file extensions longer as 3 characters.
For instance LARGE_FILE.sas7bdat
Those files I don't want to be copied.

Somehow the *sas works as if it where *.sas*

I cannot seem to FIX this little error.
It might be a HERITAGE from the old 8.3 filename length times but then there must be some way to exclude the large files with some %%~zF option?
Can anyone help me with that

EDIT: Found the solution by using the following:
for /R %bron% %%F in (*.sas) do ( copy %%~d%%~pF%%~nF.sas o: /Y )
This way only the path and filename are presented in the do-command wich will result in errors if the file LARGE_FILE.sas can not be found because the actual name is LARGE_FILE.sas7bdat but this is no problem to me.

I will LEAVE the post for others to learn from... still think this might be a BUG because the programmers did not anticipate for extensions beyond 3 characters.

============================

Code: [Select]echo off
cls
rem ** copies all *.sas files to folder **
setlocal enabledelayedexpansion
echo The given parameter: %1
echo stop now if the parameter is missing!
SET /P INPUT= continue? (y/n) :
if "%input%" =="y" goto YES
if "%input%" =="Y" goto YES
if "%input%" =="n" goto NO
if "%input%" =="N" goto NO
if "%input%" =="" goto END

:YES
echo.
set bron=X:\SERVER\FOLDER1\FOLDER2\SOURCE\%1\
subst o: /D
c:
cd "\LOCALFOLDER\SUBFOLDER\DESTINATION\"
md %1
cd %1
subst o: .
echo Copying, please wait......
for /R %bron% %%F in (*.sas) do ( copy %%F o: /Y )
del AUTOEXEC.SAS
del BATCH.SAS
echo Copy of %1 has finished.
endlocal
pause
goto END

:NO
echo No actions executed.
goto END

:END
echo End, press any key to continue.
pause >nul
exitWhy not use the following to confirm the input;

Code: [Select]if /I '%input%=='y goto YES
goto no
:yes
/I = ignore case in string

No need to add N check as next line sends all other inputs to :NO

Also...

Code: [Select]cd /d "c:\LOCALFOLDER\SUBFOLDER\DESTINATION\"
Using the /d parameter will also change drive letters as well as path

3445.

Solve : At + run as admin?

Answer»

Hi there,
I want to run a batch file each 16TH and 17th day of the month, and I need it to be run as administrator, but I don't want an UAC window that prompts on the 16th or 17th day of the month. I would also like that the batch file is ran as soon as the pc is started on the 16th or the 17th of the month (I allready tried some things with the command at, but it seems that you have to specify an hour, and the problem is I can't predict the hour on which the user will use his pc).
To explain as best as possible: have the possibility to run the batch file as administrator (the batch file that includes the 'at' command), but I would like that on the 16th or 18th of the month, I don't want to press a yes on an UAC dialogue in ORDER to run the batch file that the at command had previously configured

Thanks in forward for your help and sorry for my bad englishAs SEEN as I don't get a lot of response, i'll post what I allready succeeded in:

Now I have made a cronjob with:

SCHTASKS /Create /TN runprogram /TR c:\windows\... /sc daily /SD 24/05/2010

but the problem is: on the 24th I still get an UAC control window to run the batch file. How can I prevent that?Quote from: Blackberry on May 08, 2010, 04:37:35 AM

As seen as I don't get a lot of response, i'll post what I allready succeeded in:

Now I have made a cronjob with:

SCHTASKS /Create /TN runprogram /TR c:\windows\... /sc daily /sd 24/05/2010

but the problem is: on the 24th I still get an UAC control window to run the batch file. How can I prevent that?

http://www.windowsnetworking.com/kbase/WindowsTips/WindowsXP/AdminTips/Utilities/XPschtaskscommandlineutilityreplacesAT.exe.html

C:\test>SCHTASKS /Create /TN runprogram /TR c:\windows\... /sc daily /sd 06/05/2010
SUCCESS: The scheduled task "runprogram" has successfully been created.

sd format is month/day/year and not day/month/year might be the problem.

C:\test>SCHTASKS /End /TN runprogram
SUCCESS: The scheduled task "runprogram" has been terminated successfully.


http://social.technet.microsoft.com/Forums/en/winserverManagement/thread/454b0e9e-1ef1-4026-a8e3-91766f049f91
Blackberry: maybe you can force it to run as the admin directly by using the /u and /p switches? (/u machine/administrator /p )
3446.

Solve : son changed password in bios...?

Answer»

My son (15) wanted to change his password in command prompts (why I dont KNOW) and that somehow took him to the bios SCREEN where he changed it there...then after he couldnt log out he SHUT it down. The monitor will not come up it clicks LIKE it is turning off after about 30 seconds. We are using the MOTHERBOARD grafics card. Any suggestions about how I can get it to come up???It's always a kid...

On eBay you can order a book for $10 that shows how to reset passwords.
Take it out of his allowance.
http://www.google.com/search?hl=en&rlz=1T4GGLL_enUS304US305&q=reset+bios+password&aq=f&aqi=g10&aql=&oq=&gs_rfai=CH000235

3447.

Solve : Need batch file to delete dupes?

Answer»

The BATCH file will go through every sub-folder in a SPECIFIED folder, and delete the first version of any file that's the same length as another file in that folder.

I'd APPRECIATE your help in CREATING this batch file, or if you just want to create it and SELL it to me (for maybe $30?), that would be fine too.Are you still interested in this?

[emailprotected]

3448.

Solve : Batch file - conditional backup upon startup?

Answer»

Quote from: The Raddish

I do admit I do not fully understand the logic in the following command:

echo "!thisline!" | find "<setting id=""21"">" | find "</setting>"

You have to consider the whole line:

Code: [Select]echo "!thisline!" | find "<setting id=""21"">" | find "</setting>" && goto foundline
What's happening is this...

We send !thisline! through a pipe to an instance of the find command*. The search string is "". The quotes around "21" need to be doubled to make them literal so that find will treat them as part of the search string. If that search string is present, all of !thisline! is output by find. If it is not present, there will be no output. Any output (including the null output if the string was not found) is conducted by another pipe to a second instance of find. This time the search string is "". If that string is also present in !thisline!, then two things happen. First, !thisline! is output (to the console)** by the second instance of find. Secondly, find returns an errorlevel of zero. If either the first or second string are not found, the errorlevel will be nonzero. The && double ampersand operator*** means "if the previous operation gave a zero errorlevel, then perform the operation immediately following." Thus only if both strings are found in !thisline! will the goto command be executed.

* echo string1 | find string2 will echo string1 only if it contains string2. Find returns a zero errorlevel if the search string was found, and a nonzero errorlevel if it was not. If you only want the errorlevel and don't care to see the string, you can redirect the output to nul.

** to avoid screen clutter, I redirected the output of the second find to the null device with >nul but I see you have removed that.

*** command1 && command2 ... EXECUTE command1 and if it is successful (i.e. returns a errorlevel of zero) execute command2

simple example

dir cat.txt && echo There is a file called cat.txt in this folder

Or

echo %monthname% | find "December" && (
echo CHRISTMAS is coming!
echo The goose is getting fat
call Santa.bat
)

The converse is the || (double pipe) operator

operation1 || operation2 means execute command1 and if it "fails" (i.e. returns a nonzero errorlevel) execute command2.

I must have read dozens of descriptions of how and what pipe does. I loosely understood the concept, but was thoroughly confused when it came to using multiple pipes in a single line.

Your explanation in the above post was the most clear and and easy to understand description of how the pipe operator works that I have read to date. My hat's off to you, sir!

I have another question, but I'll post a new thread for it. It's related to this script but is a good question in it's own right.

Again, thank you for the time and effort you spend here educating others. Quote from: Salmon Trout on May 03, 2010, 12:28:27 PM
SPECIAL characters need escaping: the escape for most is ^. To echo a string with < or > or both, quote it. To escape one quote, use another.

note all quotes...

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in (test.xml) do (
REM note quotes in next line
set "thisline=%%A"
echo "!thisline!" | find "<setting id=""21"">" | find "</setting>">nul && goto foundline
)
:foundline
for /f "tokens=1-2 delims=^<^>" %%A in ("%thisline%") do set filepath=%%B
echo %filepath%

Using the above as a model, mine looks like this:

Code: [Select]@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion

set XMLFILE=C:\test\file.xml

for /f "delims=" %%A in (%XMLFILE%) do (
set "THISLINE=%%A"
echo "!THISLINE!" | find "<setting id=""21"">" | find "</setting>">nul && goto FOUNDLINE
)

:FOUNDLINE
for /f "tokens=1-3 delims=^<^>" %%A in ("!THISLINE!") do set RAW_PATH=%%C
echo. %RAW_PATH%

This works on my sample file, but I found that when deployed on another machine that has a larger XML file, I got the following error on four lines:
Code: [Select]'#178' is not recognized as an internal or external command, operable program or batch file.
'#178' is not recognized as an internal or external command, operable program or batch file.
'#178' is not recognized as an internal or external command, operable program or batch file.
'#178' is not recognized as an internal or external command, operable program or batch file.
In searching the XML setup file on the other machine, there were four lines with #178 in them. So I copied those lines into a test file, and sure enough, the error appears when the batch script is run on the test file.

It doesn't really affect anything other than displaying the error while parsing the XML file for the file path, but I'd like to understand why it triggers on these lines and if there is anything that can be done to correct it.

sample file.xml:
Code: [Select] <column data-type="9" description="" modifying-command="276" name="Solar_kW" process="" units="kW/m&#178;">
<column data-type="9" description="" modifying-command="276" name="Solar_kJ" process="" units="kJ/m&#178;">
<column data-type="7" description="Smp" modifying-command="0" name="Solar_kW" process="Smp" units="kW/m&#178;">
<column data-type="7" description="Smp" modifying-command="0" name="Solar_kJ" process="Smp" units="kJ/m&#178;">



<setting id="2">1</setting>
<setting id="3">1</setting>
<setting id="12">257149</setting>
<setting id="15">1</setting>
<setting id="16">2</setting>
<setting id="17">%a\raw_data.dat</setting>
<setting id="18">10</setting>
<setting id="20">3</setting>
<setting id="21">C:\Datalogger\raw_data.dat</setting>
<setting id="22">0</setting>
<setting id="23">30000</setting>
<setting id="1" />
<setting id="2">0</setting>
<setting id="3">2</setting>
<setting id="12">9</setting>
<setting id="15">1</setting>
<setting id="16">2</setting>
<setting id="17">%a\%s_%n.dat</setting>
<setting id="18">10</setting>
<setting id="20">3</setting>
<setting id="21">C:\Datalogger\final_storage_2.dat</setting>
<setting id="22">1</setting>
<setting id="23">30000</setting>
<setting id="28">3</setting>
<setting id="30">6619599</setting>
<setting id="31">3</setting>



<setting id="2">1</setting>
<setting id="14" />
<setting id="15">1</setting>
<setting id="16">1</setting>
<setting id="17">C:\Datalogger\ports_and_flags.dat</setting>
<setting id="18">10</setting>
<setting id="20">3</setting>
<setting id="21">C:\Datalogger\Sifter\ports_and_flags.dat</setting>
<setting id="22">1</setting>
It's the ampersand before the #178 which is causing the error message. The ampersand is a well known "poison character". The command interpreter (cmd.exe) regards it as the command chaining character.

echo hello & echo goodbye

hello
goodbye

echo hello & goodbye

hello
'goodbye' is not recognized as an internal or external command, operable program or batch file.

Processing any string with any & characters will cause errors unless special precautions are taken.

A workaround that I suggest is to replace the & with another harmless character e.g. an asterisk, before sending the line through SEND.


@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion

set XMLFILE=C:\test\file.xml

for /f "delims=" %%A in (%XMLFILE%) do (
set "THISLINE=%%A"
set THISLINE=!THISLINE:^&=*!
echo "!THISLINE!" | find "<setting id=""21"">" | find "</setting>">nul && goto FOUNDLINE
)

:FOUNDLINE
for /f "tokens=1-3 delims=^<^>" %%A in ("!THISLINE!") do set RAW_PATH=%%C
echo. %RAW_PATH%





Thanks once again, it works as expected!
3449.

Solve : Batch - Copy files with a same filename within a folder structure?

Answer»

Hey folks!

I searched through the WEB but I could not FIND anything helping me.
I'm trying to write a batch file in order to copy JUST the files within a folder structure to another folder.
All the files within the given folder structure do have the same name, but I don't want the batch script to overwrite the file that has been copied into the destination directory so far, instead it should in a way rename the files, so that in the end I do not have only one file called "filename.dat" but all of the files out of the source directory called "filename01.dat", "filename02.dat"... or something similar...

This is what I have got so far:

Code: [Select]@echo off

Set "sourceDir=%CD%

:: copy files
For /F "Delims=" %%! in ('Dir "%sourceDir%\" /b /s /a-d 2^>nul') do (
@xcopy "%%!" "%sourceDir%\%z%" /i /y /h /f /c

)
pause

I am able to get the single files within the folder structure, but I don't really know how to manage the overwriting PROBLEM. (The first file is copied and is then overwritten because of the next file which has the exact same filename)

Hope you can help me!

Greetings, hannes2424Quote from: hannes2424 on May 06, 2010, 06:24:39 AM


"All the files within the given folder structure do have the same name."Code: [Select])


There are never two files with same name in the same folder.Are you still interested in this?

I happen to be WORKING on a project which is related and might help you out.

Pleas give more details on what you are trying to achieve.

What type of files, etc...?

[emailprotected]If understand this correctly, you have duplicate file names across a directory tree but now you want them in a single directory where duplicate file names can be a real problem.

One solution would be to use XCOPY as a helper utility (use the /s switch to hunt down all the files in the tree, but also use the /l switch to not actually copy anything. Th end result will be a list of files that would have been copied which you can use in combination with an existence test and the plain old COPY utility. Along the way you can build a sequence number to add to the file name to prevent duplicates. A bit unconventional perhaps, but sound logic.

Code: [Select]@echo off
setlocal
set source=i:\myFiles
set target=c:\temp

for /f "tokens=*" %%i in ('xcopy /s /e /l %source%\* %target%') do (
if exist %target%\%%~ni%%~xi (call :sequence %%i) else (copy "%%i" "%target%\%%~ni%%~xi" 1>nul 2>nul)
)
goto :eof

:sequence
for /l %%x in (1,1,25) do (
if not exist "%target%\%~n1_%%x%~x1" (
copy "%%i" "%target%\%~n1_%%x%~x1" 1>nul 2>nul
goto :eof
)
)
goto :eof

Be sure to set the source and target variables to valid values for your machine. The current script is set for a possible 25 duplicates for any single file name. Change as necessary.

Good luck.
3450.

Solve : read file error in main routine?

Answer» HI Guys

I am having a problem with a machine that USES DOS 6.22. When I GO to run the progam on the machine I get an error "READ file in main routine" and then a C prompt. Any idea what this means.

Sounds like a disk error but ... what program is it? Run from hard drive or floppy or what? Insufficient information.