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.

1751.

Solve : move each file to a separate folder?

Answer»

hi
i want to  search  my  current folder and move all  of  (.exe) files to  a separate folder (each  file into  a unique folder )
and so
1- if there is not that folder exist create it
2-  rename each  folder to  file  name that has been  moved
3-  then  rename each  (.exe) file to  setup.exe

can you help me with that?
can  you  write some scripts for a batch  file?
thankstry this:
Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%A in ('dir /B *.exe') do (
set fileName=%%~nA
md !fileName!
move %%A !fileName!\setup.exe
)
pauseDon't  move .exe ( programs ) that are essential for the OS  to operate.

The path to the program cannot be found wnen the OS needs it.

Your OS will crash.  (  such files are usually PROTECTED from such nonsense. )

If you must have a new location, copy and don't move.thanks dear devcom for your fast reply
for testing your scripts i  copied 10 exe file into  a folder and start your program
unfortunately  it can't detect all  of exe files because it made some(5 ) folder  and name them  badly (half name)
and folders are empty  because it can't move files  to  folders  why?
1-files are not read only  and their attribs are clear
2-  some of files have long  separated names  example= windows media player 12
so  there is space in  file names
i  have this error  message  for all  files
Quote

The process cannot access the file because it is being used by another process.
        0 file(s) moved.   
                                                   
i  even  restart my  system  but nothing has changed
 i can  identify  and  move all  of these files with  other batch  files
so  what's wrong? Quote from: mioo_sara on May 30, 2009, 05:27:05 AM
thanks dear devcom for your fast reply
for testing your scripts i  copied 10 exe file into  a folder and start your program
unfortunately  it can't detect all  of exe files because it made some(5 ) folder  and name them  badly (half name)
and folders are empty  because it can't move files  to  folders  why?
1-files are not read only  and their attribs are clear
2-  some of files have long  separated names  example= windows media player 12
so  there is space in  file names
i  have this error  message  for all  files                                                   
i  even  restart my  system  but nothing has changed
 i can  identify  and  move all  of these files with  other batch  files
so  what's wrong?
First off, files that are being used by another process or computer can't be modified or moved until whatever else is using them has stopped. Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%A in ('dir /b *.exe') do (
set fileName=%%~nA
md "!fileName!"
taskkill /F /IM "%%A"
echo move "%%A" "!fileName!\setup.exe"
)
pause
try now if this will work REMOVE echo from 8 line Quote
First off, files that are being used by another process or computer can't be modified or moved until whatever else is using them has stopped.

so  why  i can  move them  with  below SCRIPT?

Quote
echo off & setLocal EnableDelayedExpansion


for /f "tokens=* delims= " %%a in ('dir/s/b/a-d *.exe') do (
move "%%a" "home"
)
wow !! it worked devcom  thanks my  man
although i  saw error message for all  files  but this time all  the folders have created and they  are all  renamed
and exe files are moved and renamed
wonderful
now dear devcom if its ok  with  you  can  you  help  me with  this 2 last request?
question 1=
there are some more files (.com and .txt) files in  this folder next to  the others (exe file)
now i  wnat them  to  be moved to one folder (each  one) so  how can  we change above script?
i  changed 
Quote
for /f "tokens=*" %%A in ('dir /b *.exe') do (
to
for /f "tokens=*" %%A in ('dir /b *.exe *.com *.txt') do (

so  is there any  problem with  that? so  what about this  line? echo move "%%A" "!fileName!\setup.exe"
this command rename all  file to  setup.exe so  what can  i do for .txt and .com  files?
txt  file should be rename to readme.txt
.com files should be rename to setup.com
question 2= some of files have "update" or "uninstall" word in  their names
these kind of files should be renamed to update or uninstall (ignore to  rename them  to setup)

thanks my  dear devcombut you want to do this the same way as .exe for .txt and c.om ? so you have file test1234.txt and you want to make test1234 folder and put the .txt file there as readme.txt ?sorry  dear devcom for answering late
yes i  want the exact of operation  that you  mentioned
thanks i am  waiting Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%A in ('dir /b *.exe *.txt *.com') do (
md "!fileName!" 2>nul

set fileName=%%~nA
::set fileName=!fileName:update=!
::set fileName=!fileName:uninstall=!
set fileExt=%%~xA

if "!fileExt!" equ ".txt" (set moveName=readme) ELSE (set moveName=setup)

call :FIND "%%A"

echo move "%%A" "!fileName!\!moveName!!fileExt!

)
pause
exit

:FIND
set find=%~1
echo.%find% |findstr /I "uninstall" >nul && set moveName=Uninstall
echo.%find% |findstr /I "update" >nul && set moveName=Update
exit /b
this should work

PS you can remove :: from 8,9 line to make folders without update or uninstall word ,i mean if you have file: 'test update.exe' it will create 'test' folder instead of 'test update' folder if you delate ::

PS.2 ofc you need to remove echo if this will workWhy does "Mioo_Sara" want to move  ".exe" files into separate unique folder?   What is the goal of such a strange movement of .exe files?

What is Mioo_sara  trying to accomplish? 



Quote from: mioo_sara on May 30, 2009, 03:45:59 AM
hi
i want to search my  current folder and move all  of  (.exe) files to  a separate folder (each  file into  a unique folder )
and so
1- if there is not that folder exist create it
2-  rename each  folder to  file  name that has been  moved
3-  then  rename each  (.exe) file to  setup.exe

can you help me with that?
can  you  write some scripts for a batch  file?
thanks
maybe he created 1000 apps and now he want to clean his computer ? Quote from: devcom on May 30, 2009, 03:51:10 PM
maybe he created 1000 apps and now he want to clean his computer ?

If clean the computer  of .exe files, then del is better than move.

The movement of .exe to a unique folder was not restricted to .exe files created by the user.

It is and was a nonsense and dangerous exercise to move .exe files to a unique folder.billrich is right, this is odd.
1752.

Solve : Evil batch?

Answer»

I have a batch that I made so when I exit my money that in case I FORGOT to back-up to a floppy, which save me a good many to put a copy of it on there.  When I run it however it comes up saving that there isnt enough room on the disk.  If I do it in the program there isnt any issues but its a pain to go back an put in all the REQUIRED info.Not enough room on the floppy?LOL Hypocrite.

Show us the code.Its wierd, copy C:\doncuments and settings\robert\my documents\my money.mnn  A:\ /y /s /v

I have created a shortcut on the desktop so it looks better and STUFF not sure if it matters, not near the machine but sure its something like that.That's the batch file?In general, I have found that, when the error issued is "Insufficient disk space" or something similar, it is a good idea to check the free space on the target drive.there is nothing wrong with the floppies, I tried another and the same thing happened.This might even be a semi-intelligent question:  in what file system are the floppies formatted?I asssume FAT but I could be wrong.That makes the most sense, but I can't think of anything else...would it say if its not?  I dont know.  Strange Quote from: BC_Programmer on May 26, 2009, 11:55:28 AM

In general, I have found that, when the error issued is "Insufficient disk space" or something similar, it is a good idea to check the free space on the target drive.

I never said there might be something wrong with the floppies.Maybe whatever you're trying to copy is too BIG for the floppy?woah, slow down there Carbon- He's supposed to FIGURE that out himself!  I didn't want this topic to carry on for another 5 pages.
1753.

Solve : Delete files - older than 7 days?

Answer»

I have a folder where every day backup files are copied from a system.
I need to create a batchfile and put in the windows schedule that deletes the file older than seven DAYS.
How do I do it ?
I found this online. I hope it helps...

Code: [Select]:: --------DELOLD.BAT----------
echo off
SET OLDERTHAN=%1
IF NOT DEFINED OLDERTHAN GOTO SYNTAX

for /f "tokens=2" %%i in ('date /t') do set thedate=%%i

set mm=%thedate:~0,2%
set dd=%thedate:~3,2%
set yyyy=%thedate:~6,4%

set /A dd=%dd% - %OLDERTHAN%
set /A mm=%mm% + 0

if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
if %mm%==12 goto SET31

goto ERROR

:SET31
set /A dd=31 + %dd%
goto DONE

:SET30
set /A dd=30 + %dd%
goto DONE

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

:SET28
set /A dd=28 + %dd%
goto DONE

:SET29
set /A dd=29 + %dd%

:DONE
if /i %dd% LSS 10 set dd=0%dd%
if /I %mm% LSS 10 set mm=0%mm%
for %%i in (*.*) do (
set FileName=%%i
call :PROCESSFILE %%~ti
)

set mm=
set yyyy=
set dd=
set thedate=
goto EXIT

:SYNTAX
ECHO.
ECHO USAGE:
ECHO DELOLD X
ECHO   Where X is the number of days previous to Today.
ECHO.
ECHO EX: "DELOLD 5" Deletes files older than 5 days.
GOTO EXIT

:PROCESSFILE
set temp=%1
set fyyyy=20%temp:~6%
set fmm=%temp:~0,2%
set fdd=%temp:~3,2%
if /I %fyyyy% GTR 2069 set fyyyy=19%temp:~6%


:: +*************************************+
:: | This is where the files are deleted |
:: | Change the ECHO command to DEL to   |
:: | delete. ECHO is used for test.      |
:: +*************************************+
if /I %yyyy%/%mm%/%dd% GEQ %fyyyy%/%fmm%/%fdd% (
ECHO %FileName%
)

set temp=
set fyyyy=
set fmm=
set fdd=

:EXIT

:: ----------END-DELOLD.BAT-------------
Thanks,

This file delete the latest file - today's file . Is because of the date format ?
My date format is mm-dd-yyyy.

This file should delete the files older than 7 days. So there should not be any parameter passing .
Please let me know where to edit the batch file to give a FIXED value of 7 ?you should at least understand what the batch script is doing before using. Here's a MUCH shorter vbscript. don't have to WORRY about date settings.
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If DateDiff("d",strFile.DateLastModified,Now) > 30 Then
strFileName = strFile.Name
WScript.Echo strFileName
objFS.DeleteFile(strFileName)
End If
Next

on command prompt
Code: [Select]c:\test> cscript /nologo myscript.vbs

want SOMETHING even shorter? you can download GNU find (see my sig under findutils)
Code: [Select]C:\test>find c:\test -type f -mtime +30 -delete

1754.

Solve : WINRAR - FILES?

Answer»

I am taking CERTAIN types of  files as backup into a particular folder every day using the FOLLOWING batch files.

echo off
cls
COPY d:\s3kg\data\*.dbf e:\backups /V
COPY d:\s3kg\data\*.idx e:\backups /V
PAUSE

How do I make these files zipped using winRAR in windowsxp inside the  batch file?




CHECK out the winrar command line usage:

go to command prompt and type:
CODE: [Select]cd %programfiles%\winrar
rar.exe
youll get a large list of winrar command LINES

1755.

Solve : I am really need a help please?

Answer»

I am really need a help please

i need to make TWO batch files between my NETWORK
i need batch files make this jobs

if one of the network open the batch and logged on with "user+pass"

display his name on other users on the network who have the batch file

for example i have the batch and my friend as WELL have it

if he ran the batch and logged on
i need message tell me for example "Michael Online"

Thanks Quote from: Hallucination on May 30, 2009, 12:59:03 PM

I am really need a help please

i need to make two batch files between my network
i need batch files make this jobs

if one of the network open the batch and logged on with "user+pass"

display his name on other users on the network who have the batch file

for example i have the batch and my friend as well have it

if he ran the batch and logged on
i need message tell me for example "Michael Online"

Thanks
Ok...I don't think you can make a user log in, as I'm fairly sure that batch files get executed after they log in...but, you COULD do this.

echo off
set log=Shared folder path\log.txt
for /f "tokens=1-2 delims=: " %%A in ("%time%") do set tme=%%A^:%%B
echo %username% has logged in at %tme%. >> "%log%"
exit

And one to check to see if he logged in,

echo off
:loop
cls
type "Shared folder path\log.txt"
ping localhost -n 2 > nul
goto loop

If you put the first one in the startup script, you will always know when someone logs in.
1756.

Solve : write batch programming with html if possible ???

Answer»

       hi want to use batch programming in HTML home page like we use javascript.

        if possible


please be more clear. If you want to do web programming, get a web programming language, PHP, Python, Perl, RUBY ETC I agree with gh0std0g74 .... and the only integration with HTML and Batch would be links to batches for execution or download, and that is DANGEROUS for visitors if your batches are malicious. In IE you also would see a security warning. I ran into this problem when before learning Visual C++ wanted a nice INTERFACE for my console app programs. Security Blat was annoying so I just learned how to make GUI apps instead the right way vs a mix of compiled C++ and HTML GUI interface.
1757.

Solve : Using a .vbs file to launch a batch file?

Answer»

I WOULD like to launch an application using a batch file. I have no problem doing this:
Using a shortcut with "batchfile.bat otherfilename"

This works FINE. But, I would like to make the batch file invisible. Searching the internet, I found a .vbs script:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

This script is called by a shortcut:
%windir%\system32\wscript.exe invisible.vbs batchfile.bat otherfilename

This should do the trick, but refuses my 'otherfilename' to be transferred to the batch file.

Can someone help with this?
ThanksFound the answer here:
http://stackoverflow.com/questions/298562/windows-xp-or-vista-how-can-i-run-a-batch-file-in-the-background-no-windows-dis

Uses a more complicated .vbs file where it DETERMINES the number of command line VARIABLES before calling the batch file.

1758.

Solve : batch file that read from a txt file line by line?

Answer»

Hi All

I have little or no experience using batch FILES

I need to know how to do the following:

i have the text file (list_of_files.txt) with the contents:

C:\myfolder\file1.txt
C:\myfolder\file2.txt
C:\myfolder\file3.txt
C:\myfolder\file4.txt

I need a batch file to read the contents of the text file and copy the files listed in the text file to a specified folder and append something to the end of the file name

EG copy C:\myfolder\file4.txt C:\myfolder2\file4.txt_OLD

The reason I am doing this is the contents of list_of_files.txt may change.

regards
G. Code: [Select]echo off

set folder=C:\myfolder2

for /f "tokens=*" %%A in (list_of_files.txt) do (
echo. copy %%A %folder%\%%~nA_OLD
)
pause
test it and then remove echo. from 6 line Hey

That's a good solution but not really right

the first bit is good

I've figure that out ALREADY since I posted

for /f "tokens=*" %A in (list_of_files.txt) do copy %A C:\myfolder2

I need to keep the names of the files correct

you script rename everything to 1_OLD as opposed to file1.txt_OLD

I THINK I'm gonn have to do a 2 parter

so something like:

Code: [Select]for /f "tokens=*" %A in (list_of_files.txt) do copy %A C:\myfolder2

cd C:\myfolder2

for /everyfile %b do move %b %b_OLDfigured it out

%~nxA
Good to see this forum is going well and strong.

Here is an alternate solution script in biterscripting ( http://www.biterscripting.com ) .

Code: [Select]var str list ; cat "list_of_files.txt" > $list
while ($list <> "")
do
    # Get the next file. Get just the file name after the last /.
    var str file, name ; lex "1" $list > $file ; stex -p "^/^l[" $file > $name
    # New name is $name+"_OLD". Copy the file with new name to folder C:\myfolder2.
    system copy ("\""+$file+"\"") ("\"C:\myfolder2\"+$name+"_OLD\"")
done

J

1759.

Solve : how put a file list into a variable (string)?

Answer»

Hi All:

I NEED read a list of files from a directory and put into a VARIABLE (string) for use.

I have by example 3 files: "arch1.pdf" "arch2.pdf" "arch3.pdf"

I want put this string "arch1.pdf arch2.pdf arch3.pdf" in a variable.

I try with this sentences but not work.

echo off
for /f %%a in ('dir /b *.pdf') do (
set txt=%%a
echo %txt%
)
pause

what about:
Code: [Select]echo off
for /f %%a in ('dir /b *.pdf') do (
set txt=%txt% %%a
echo %txt%
)
pauseI try but the RESULT of the SCRIPT posted by BC_Programmer is:

txt
txt
txt



can you post the code for the batch file? Code: [Select]echo off
setlocal enabledelayedexpansion

for /f %%a in ('dir /b *.pdf') do (
set txt=!txt! %%a
echo !txt!
)
pause
?Perfect ... the last script work fine...   

thanks for everything...

1760.

Solve : Download file trough batch?

Answer»

Hi there,
is there any way I can download a file from a webserver trough batch (under winxp/vista)
I made a batch file that creates the following VBSCRIPT (and launches it):
End Sub

The script works like a charm for files less then 50 kb, but I want to download a file that is 450 kb.

Can anyone please help me

P.S. Installing external command line tools isn't an option, cause I can't install anything elseYou appear to be hitting a maximum buffer size that is more like 64k instead of 50k. You will likely have to write the 64k buffer prior to reaching 64k and then grab the other 63 or 64 k and perform another write appended to the end of file of the first write until the entire file is transferred. Not sure if this can be done and keep the handshake of the download or if the delay in writing will error that possibility out.

- OR - find a way to use a buffer other than the default without the 64k limit. In a PERL script on google a person stated that they changed from 64k to 2GB Buffer by switching between Win32::Textfield to Win32::RichEdit. This wont help you directly with your code, but sounds like the same issue, but a different language. ** For 2GB obviously you need resources to support that.

Other possibility is a limitation in the dos-shell buffer of windows that I didnt dig up any info on.

Windows caches downloads prior to writing to the hard drive so maybe there is an API call... although if you are going into API territory its further away from a batch than you probably want to be since you wanted to do this in batch.

wait a minute- ever since VB MOVED from 16-bit to 32-bit and dumped HLSTR's in favour of BSTR's it has had a maximum string size of 2GB...

Also- Why not write out the entire responsebody? I'm not sure exactly what the loop is trying to do- but couldn't you simply do:


Code: [Select]objfile.write objHTTP.ResponseBody


and, if it's converting to or from UNICODE you could use the StrConv() function.


Also- what exactly happens with files that are larger then 50K... (or 64K)
Quote from: BC_Programmer on JUNE 02, 2009, 02:05:37 PM

wait a minute- ever since VB moved from 16-bit to 32-bit and dumped HLSTR's in favour of BSTR's it has had a maximum string size of 2GB...

Also- Why not write out the entire responsebody? I'm not sure exactly what the loop is trying to do- but couldn't you simply do:


Code: [Select]objfile.write objHTTP.ResponseBody


and, if it's converting to or from unicode you could use the StrConv() function.


Also- what exactly happens with files that are larger then 50K... (or 64K)



Thank you for your responses. After looking a long time i have found the following script which works perfectly, but I only have one problem. It promps with an useless textbox to say where the file is saved. This ins't really user-friendly because the user doesn't need to be BOTHERED which such information imo. Does anyone now how to avoid the message box?

Thanks in advance

script:
End Function
you can use wget too
Quote from: devcom on June 02, 2009, 02:58:10 PM
you can use wget too


except:

Quote
P.S. Installing external command line tools isn't an option, cause I can't install anything else
1761.

Solve : copying and renaming files?

Answer»

There are files of the form

a-hire.txt, a-hire-1.txt,......, a-hire9.txt, a-hire-rpt.txt

I would like to single copy command to copy them to files of the form
a-hire-0601.txt, a-hire-1-0601.txt,......, a-hire9-0601.txt, a-hire-rpt-0601.txt .

 I am just putting the month and day on the end of the file before the .txt.

copy a-hir*.txt a-hir*.0601.txt gives me a-hire.txt.0601.txt

Thanks for any help.

The following is for ONE case Only:

Code: [Select]echo off
:Today
for /f "Tokens=1-3 delims=/-" %%a in ('date /t') do (
set Month=%%a
set Day=%%b
set Year=%%c
)
set Month=%Month:~4,5%


ren a-hire.txt  a-hire-%Month%%Day%.txt
dir a-hire*.*
del a-hire*.*

REM echo Hello > a-hire.txtC:\>newname.bat

Output:

  Quote

Volume in drive C is OS
 

Directory of C:\

06/01/2009  07:34 PM                 8 a-hire-0601.txt
               1 File(s)              8 bytes
               0 Dir(s)  304,370,679,808 bytes free
C:\>
here's a vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
mth = Month(Now)
d = Day(Now)
If LEN(mth) <2 Then
mth="0"&mth
End If
If Len(d) < 2 Then
d = "0"&d
End If
i=mth&d
For Each strFile In objFolder.Files
strFileName = strFile.Name
If InStr(strFileName,"a-hire") > 0 Then
BaseName = objFS.GetBaseName(strFileName)
Extension = objFS.GetExtensionName(strFileName)
NewName = BaseName & "-" & i & "." & Extension
strFile.Name = NewName
End If

Next
1762.

Solve : Ouput cannot be redirected to a file or a program?

Answer»

Hi,

I have a command(I EXECUTE it at DOS prompt) WHOSE output has to be redirected to a buffer or a file,which I am not able to do.

The same command's output can be redirected to a file if an option like "-a" is passed.

why am I not able to redirect when the command alone is passed? Is ther any solution to this kind of problem ?


please help me in this.

Thanks in advance

Raghu A

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

Do all your OS updates, Increase your RAM, CLEAN your machine, close applications which use much RAM  not needed.   Increase the buffer size.   Use >  and not >>  when possible.  Increase FREE  space on the HDD ( clean your machine ):  CCleaner.exe

Do the OS  repair.

1763.

Solve : Pen Drive Is not accessing?

Answer»

Hello friends i am not able to open my PEN drive through mouse,it says"access denied"...
is it possible to open my pen d through dos prompt?
if yes then how can i open my POWER point slide using dos COMMAND?First SEE if you can access it.

Type 'START "" "E:\" where 'E' is the directory of the USB device.

When did it start?
Does it work on other computers?

1764.

Solve : Creating a current date directory then moving files to the directory?

Answer»

I have syntax to create a current date directory yet not sure how to move text  files within the newly created directory.

The code successfully makes the directory but the move statement fails it sees the parameter as "" for fldr

Code: [Select]echo on

REM Title: EXP_BFS_DATA batch command
REM Title: Transfer of nightly BFS data export to a dated folder


REM Navigate to server BFS_Backup folder
REM Create a backup folder with today's date.

p:
CD p:\BFS_Backup
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO MKDIR %%g-%%e-%%f

REM Move nighlty BFS data export text files to dated folder

MOVE p:\BFS_Backup\*.TXT c:\BFS_Backup\??? - Unsure what to put here
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO set d=%%g-%%e-%%f

md c:\BFS_Backup\%d%
MOVE p:\BFS_Backup\*.txt c:\BFS_Backup\%d%\
Awesome Reno!! 

If I want to take just one step further and do IF EXISTS and IF NOT EXISTS for the directory how can I adjust the script?

Would the IF NOT EXISTS then the md command otherwise MOVE?  I am trying to come to a place that the command doesn't error on creating a current date folder if the current date folder (for some reason) existed.



Code: [Select]echo on

REM Title: EXP_BFS_DATA batch command
REM Title: Transfer of nightly BFS data export to a dated folder


REM Navigate to server BFS_Backup folder
REM Create a backup folder with today's date.

p:
CD p:\BFS_Backup
FOR /F "tokens=1-5 delims=/ " %%d IN ("%date%") DO SET fldr=%%g-%%e-%%f
MD p:\BFS_Backup\%fldr%

REM Move nighlty BFS data export text files to dated folder

MOVE "p:\BFS_Backup\*.txt" "p:\BFS_Backup\%fldr%"easy

Code: [Select]if not exist p:\BFS_Backup\%fldr%\ MD p:\BFS_Backup\%fldr%

from the help file if /?
Code: [Select]The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )Reno...

Last thing...if I want to log all the activity (like echo) into a log file is there any syntax for that? 

> to clear file and echo sth to it
>> to add line into it

ex.
Code: [Select]echo TEXT >file.txtperhaps that is not what I want...

Output needed only for errors

So something like

IF ERROR = 1
 THEN error.txt
  ELSE END

to output errors use this:
Quote

del file.txt 2>error.txt
Sorry for sounding dumb but what does file.txt represent?

Delete file.txt produces error.txt?

Why the delete?

Quote from: JTS on June 03, 2009, 10:42:58 AM
Sorry for sounding dumb but what does file.txt represent?

Delete file.txt produces error.txt?

Why the delete?


Dev just used delete as an example...if you used mkdir Foldername 2>error.txt, it would echo any errors to error.txtThanks all for the help....appreciate it..

1765.

Solve : How To play Music?

Answer»

can ANYONE TELL me how can I PLAY mpg file using DOS command?
Start "" "C:\directory\of\file.mpg"

1766.

Solve : Mass Copy?

Answer»

It has been a long time SINCE I have used DOS,

I though there was a command that I could issue from the root of my c drive which would step through my sub directories on my hard drive and copy any files that ended with jpeg to an alternate directory

But I can not remember how to do this - Any help would be greatly appreciated 

Thanks - daniel youll be using something with xcopy
xcopy c:\*.jpeg (flashdrive letter):\*.jpg /s

it will copy all images with .jpeg to a flashdrive. heres a better explanation

Code: [Select]XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
                           [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
                           [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
                           [/EXCLUDE:file1[+file2][+file3]...]

  source       Specifies the file(s) to copy.
  destination  Specifies the location and/or name of new files.
  /A           Copies only files with the archive attribute set,
               doesn't change the attribute.
  /M           Copies only files with the archive attribute set,
               turns off the archive attribute.
  /D:m-d-y     Copies files changed on or after the specified date.
               If no date is given, copies only those files WHOSE
               source time is newer than the destination time.
  /EXCLUDE:file1[+file2][+file3]...
               Specifies a list of files containing strings.  Each string
               should be in a separate line in the files.  When any of the
               strings match any part of the absolute path of the file to be
               copied, that file will be excluded from being copied.  For
               example, specifying a string like \obj\ or .obj will exclude
               all files underneath the directory obj or all files with the
               .obj extension respectively.
  /P           Prompts you before creating each destination file.
  /S           Copies directories and subdirectories except empty ones.
  /E           Copies directories and subdirectories, including empty ones.
               Same as /S /E. May be used to modify /T.
  /V           Verifies each new file.
  /W           Prompts you to press a key before copying.
  /C           Continues copying even if errors occur.
  /I           If destination does not exist and copying more than one file,
               assumes that destination must be a directory.
  /Q           Does not display file names while copying.
  /F           Displays full source and destination file names while copying.
  /L           Displays files that would be copied.
  /G           Allows the copying of encrypted files to destination that does
               not support encryption.
  /H           Copies hidden and system files also.
  /R           Overwrites read-only files.
  /T           Creates directory STRUCTURE, but does not copy files. Does not
               include empty directories or subdirectories. /T /E includes
               empty directories and subdirectories.
  /U           Copies only files that already exist in destination.
  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  /N           Copies using the generated short names.
  /O           Copies file ownership and ACL information.
  /X           Copies file audit settings (implies /O).
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          CAUSES prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be OVERRIDDEN with /-Y on the command line.

1767.

Solve : Copy from current path??

Answer»

Hello everyone. I am trying to include some lines in a bat that will copy files from the current location to a specified path on a drive.

For example i am trying to copy a shortcut to the desktops of many computers on our network. In that PAST the old IT team used to copy and paste one at a time. I WOULD like to create a bat that will copy files from whatever path on the network without having to EDIT the bat every time the folder is moved.

This is what i have but it wont work when running off the network. I remember having this issue but can not find my documentation.
Code: [Select]echo off
copy /Y "\Mithcell1.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Gradebook.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Printer_Install.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Computer_Issues.lnk" "%ALLUSERPROFILE%\desktop"

pause
echo on
Thanks for the help!

HoFL Quote from: TheHoFL on June 02, 2009, 04:22:14 PM

Hello everyone. I am trying to include some lines in a bat that will copy files from the current location to a specified path on a drive.

For example i am trying to copy a shortcut to the desktops of many computers on our network. In that past the old IT team used to copy and paste one at a time. I would like to create a bat that will copy files from whatever path on the network without having to edit the bat every time the folder is moved.

This is what i have but it wont work when running off the network. I remember having this issue but can not find my documentation.
Code: [Select]echo off
copy /Y "\Mithcell1.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Gradebook.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Printer_Install.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "\Computer_Issues.lnk" "%ALLUSERPROFILE%\desktop"

pause
echo on
Thanks for the help!

HoFL
First off, you need to do a bit of registry modding for that script to work on a computer...LNK files are hidden, and you can only unhide them by deleting a certain registry. Batch can't see them unless you do it...

If you want to move files which are in the current directory, just use their names and EXTENSIONS.Oh...wow i feel like a newb again. I knew there was a registry bit, but i ran that on my PC a while back. Or are you referring to running the registry change on the server?

i chaged the path to just the filename and extension and tried running the bat and the following is what i get.

Quote
'\\server\infotech\test'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
Press any key to continue . . .
Quote from: TheHoFL on June 02, 2009, 04:32:35 PM
Oh...wow i feel like a newb again. I knew there was a registry bit, but i ran that on my PC a while back. Or are you referring to running the registry change on the server?
On any computer that the batch file will be run on, the registry changes must be made.Okay, got it working. Below is my code that adds the registry that will allow running a bat from a UNC path. It worked perfectly. After running a BAT with the "REG" line should allow you to run any BAT from a UNC path.

Code: [Select]Echo off

REG ADD "HKCU\Software\Microsoft\Command Processor" /V DisableUNCCheck /T REG_DWORD /F /D 1

SET THISDIR=%~dp0

copy /Y "%THISDIR%Mitchell1.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "%THISDIR%Gradebook.lnk" "%ALLUSERPROFILE%\desktop"
echo The new files have been copied.
pause
Echo on Quote from: TheHoFL on June 02, 2009, 05:05:46 PM
Okay, got it working. Below is my code that adds the registry that will allow running a bat from a UNC path. It worked perfectly. After running a BAT with the "REG" line should allow you to run any BAT from a UNC path.

Code: [Select]Echo off

REG ADD "HKCU\Software\Microsoft\Command Processor" /V DisableUNCCheck /T REG_DWORD /F /D 1

SET THISDIR=%~dp0

copy /Y "%THISDIR%Mitchell1.lnk" "%ALLUSERPROFILE%\desktop"
copy /Y "%THISDIR%Gradebook.lnk" "%ALLUSERPROFILE%\desktop"
echo The new files have been copied.
pause
Echo on
Ok... Two things.

1. Any computers that runit must have all instances of NeverShowEXT or they will get a file not found error...(Just so you know)
2. Why do you turn echo on at the end?Yeah i know. Only IT will be using this and we have our PCs setup CORRECTLY to use it. Thanks for the info though. Quote from: TheHoFL on June 02, 2009, 05:18:57 PM
Yeah i know. Only IT will be using this and we have our PCs setup correctly to use it. Thanks for the info though.
Ok and No problem! Quote
First off, you need to do a bit of registry modding for that script to work on a computer...LNK files are hidden, and you can only unhide them by deleting a certain registry. Batch can't see them unless you do it...

Not true... I can see LNK files in cmd with all my PCs.

NeverShowExt applies to EXPLORER, not cmd. Same with the other "show hidden files", show extensions for known filetypes, etc etc.

"LNK" files aren't "hidden" per se, but rather special shell files. usually around 400 to 600 bytes.

Really, they evolved as a windows version of the older "PIF" files from windows 3.0/3.1.

see here:

HKEY_CLASSES_ROOT\.lnk


aside from the keys here, refer also to:

HKEY_CLASSES_ROOT\lnkfile

which has the "NeverShowExt" option you mention. (which applies to explorer, and other applications which respect the option)

I have it present, and I can see LNK files with dir.

"editflags" sets the option so that the folder options dialog will not show LNK in the file associations list. (imagine the havoc if that association was accidentally deleted!)

Which brings up an interesting point- there isn't really an association to anything for a shortcut- but rather an association to a particular Shell object, Likely a Shell interface object. My guess would be that the shell instantiates the object and de-serializes it's state from the shortcut's contents, and then the shell uses it's IFolderItem Interface to perform file-like tasks (most likely, execution) that in general operate on the target rather then the shortcut.

However- anything to do with file associations is irrelevant when speaking of DIR or the command processor- it doesn't respect anything of the sort, and simply displays the files that are present.




1768.

Solve : how to open banned orkut?

Answer»

in my clg ORKUT is banned is there any proxysite by which i can open it?i tried some of them but they have'nt worked.Read the rules

QUOTE from: topic 58736 C.H. Rules

Filters on school computers and in the WORKPLACE are there for a reason.  If they don't WANT you to do certain things on their network, it is your obligation to respect that.  We do not assist in bypassing these filters.  If you feel that you have a good reason, you need to discuss it with the network's administrator.
1769.

Solve : How do I remove " from a varable??

Answer»

I have a variable:

SET X=%1

%1 contains "5.200901011259.Ken.job"

How can I remove any/all quotes from the varable?

Ken


Here is more information that might lead to an answer.

the program that calls this uses this line:
FOR /f %%A in ('dir/b %QUEUES%\%QUEUE%\?.*.*.job') do call %BATCHQ%\exe\RunJob.exe %%A

The quotes are coming from this %%A.try this after seting the x var
Code: [Select]set x=%x:"=%http://www.dostips.com/DtTipsStringManipulation.php


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

setlocal enabledelayedexpansion

Rem %1 contains 'text"info"moretext'
Rem How can I remove any/all quotes from the varable?

set x=%1
echo  x =  %x%
set x=%x:~1,-1%
echo x = %x%
pause

set x=%x:"info"=info%

echo.  x = %x%!
Output :
C:\> quote.bat 'text"info"moretext'
 x =  'text"info"moretext'
x = text"info"moretext
Press any key to continue . . .
  x = textinfomoretext
C:\>http://www.dostips.com/DtTipsStringManipulation.php


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

setlocal enabledelayedexpansion

Rem %1 contains "5.200901011259.Ken.job"
 

Rem How can I remove any/all quotes from the varable?

set x=%1
echo  x =  %x%
set x=%x:~1,-1%
echo x = %x%

[/quote]
Output :

C:\> quote.bat "5.200901011259.Ken.job"

 x =  "5.200901011259.Ken.job"
x = 5.200901011259.Ken.job
thanks guys, this one worked (in DOS and compiled in EXE)

set x=%1
set x=%x:~1,-1%
what if you have extra quotes in between , eg
Code: [Select]"5.20090"101"1259.Ken.job"
KENL,

Ghost  and Dev are correct.  Their code :

set x=%x:"=%
set x=%x:'=%

is better than:

set x=%x:~1,-1%

( the above code only REMOVES quotes at the BEGINNING  and end of the STRING.)

http://www.dostips.com/DtTipsStringManipulation.php


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

setlocal enabledelayedexpansion

Rem %1 contains 'text"info"moretext'
Rem How can I remove any/all quotes from the varable?

set x=%1
echo  x =  %x%
set x=%x:"=%
set x=%x:'=%
Rem set x=%x:~1,-1%
echo x = %x%
pause

Rem set x=%x:"info"=info%

echo.  x = %x%!C:\> quote.bat 'text"info"moretext'
 x =  'text"info"moretext'
x = textinfomoretext
Press any key to continue . . .
  x = textinfomoretext

C:\>

1770.

Solve : Command prompt stopped recognising commands!?

Answer»

I felt like making a ping to my router, when for no apparant reason it didnt recognise the command.
So then I tried a bunch of other basic commands (HELP, ?, go, ipconfig, etc. )
So far only CD and start commands worked...

Help please! Ive no idea whats going on  Are you doing this in strictly DOS 6.22 or older -or- Windows DOS Shell DOS 7.0+?

If Windows is running, then its Shell and should RECOGNIZE those commands, but if 6.22 or earlier many commands didnt exist yet for TCP/IP Networking on original 6.22 installation without ADDITIONAL 3rd party software that i know of.

Im running windows vista 64, dunno what version it is, i just open the command prompt :SWhat message do you get when trying to use these commands? Is it the same message if you try and run hello at the command prompt?check your PATH variable. maybe system32 (is it?? ) is not thereI checked the path variable and when I changed it to C:\windows\system32 the commands started working again, thank allot ^^

1771.

Solve : Can someone tell me how to stop a batch file??

Answer»

I ran this program:

echo off
setlocal
set srcDir=c:\sass
set destDir=c:\css
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
c:\ruby\bin\sass %srcDir%\%lastmod%.sass > %destDir%\%lastmod%.css


Which watches a directory for a file change and copies it to another directory. However, even after closing the command LINE it still seems to be running in the background.

I just rebooted my computer and its still running... (no command line window is open)

Can someone tlel me how to stop it?


These steps will find out what is running. Also try and take a screenshot of the command window if you can see it.

#1. Open the command prompt. Type in tasklist and press enter. If you see a list of all your processes, continue. If not, reply and say you can't, and we'll work on something else.
#2. Type in this:
tasklist > "%userprofile%\Desktop\tasks.txt"
#3. Open "tasks.txt" on your desktop and post the contents in your next reply.Haha, thanks. I tried that and I couldn't locate the command service.

However, upon further INSPECTION of my task list I realized this software I downloaded (before I tried writing batch files) to watch my folders was actually still running (and running on startup), which is why some action was being performed on these folders despite the fact my script wasn't running.

God I'm such a moron.    Don't call yourself a moron! You solved your problem! The only good way to learn is with experience (take baking SODA and vinegar...if someone told you that together they create gas, would you believe them? If you found it out for yourself you learn what HAPPENS).

1772.

Solve : random??

Answer»

hi is there a peice of code that will pick a variable from a list out at randomYes...by picking out from array but random will only follow algorithm UNLESS you seed it. Random will always pick say 3,4,7,5,2 in that order if executed again and again after closing it unless you add a seed to influence the algorithms output in which the output is less likely to be guessed in the order at which it will spit out the outcome.

I have never seeded a random in a batch to give an example but am guessing that it follows the same rules as C, C++, or Perl with Time used.if you can download gawk for windows (see my sig)
Code: [Select]
C:\test>echo 1 2 3 4 5 10 8 5|gawk "BEGIN{srand()}{R=int(1+rand()*NF); print $(R)}"
8

C:\test>echo 1 2 3 4 5 10 8 5|gawk "BEGIN{srand()}{R=int(1+rand()*NF); print $(R)}"
4

C:\test>echo 1 2 3 4 5 10 8 5|gawk "BEGIN{srand()}{R=int(1+rand()*NF); print $(R)}"
4

C:\test>echo 1 2 3 4 5 10 8 5|gawk "BEGIN{srand()}{R=int(1+rand()*NF); print $(R)}"
3

C:\test>echo 1 2 3 4 5 10 8 5|gawk "BEGIN{srand()}{R=int(1+rand()*NF); print $(R)}"
5

C:\test>


No code is needed

Run CMD.EXE and type SET /?
At the end of several pages is a SMALL section on dynamic environmental variables that are sort of secret - if you do not know them you cannot see them.

%RANDOM% is one of them
ECHO %RANDOM% will display a (semi)random number that changes every time.

If you want a truly random sequence you will need to seed it.

Regards
Alan
Example for choosing a random # from 0 to 10:

Code: [Select]set /a return=%RANDOM%%10 Quote from: macdad- on June 16, 2009, 04:27:48 PM

Example for choosing a random # from 0 to 10:

Code: [Select]set /a return=%RANDOM%%10
Really? I always have to use goto loop so I can get a number...but depending on the number, can take a fairly long time. Code: [Select]set /a return=%RANDOM%%10
that will only generate a rand number. imagine a list of numbers eg 10,20,30,40,50. you will need to get a random item out of this list, not by simply using the above code. Quote from: gh0std0g74 on June 16, 2009, 06:43:00 PM
Code: [Select]set /a return=%RANDOM%%10
that will only generate a rand number. imagine a list of numbers eg 10,20,30,40,50. you will need to get a random item out of this list, not by simply using the above code.
Well, most more advanced needs require more lines in a script.

echo off
:loop
set /a rnd=%random%%50
if %rnd% neq 50 if %rnd% neq 40 if %rnd% neq 30 if %rnd% neq 20 if %rnd% 10 goto loop
echo The random number is either 10, 20, 30, 40 or 50.
echo Your random number is %rnd%.
pause > nul Quote from: Helpmeh on June 17, 2009, 04:05:23 PM
Well, most more advanced needs require more lines in a script.

echo off
:loop
set /a rnd=%random%%50
if %rnd% neq 50 if %rnd% neq 40 if %rnd% neq 30 if %rnd% neq 20 if %rnd% 10 goto loop
echo The random number is either 10, 20, 30, 40 or 50.
echo Your random number is %rnd%.
pause > nul
not really. if %RANDOM% doesn't hit a number in the list forever, are you going to wait forever?? use the number of items on the list with %RANDOM% instead. Quote from: gh0std0g74 on June 17, 2009, 06:08:30 PM
not really. if %RANDOM% doesn't hit a number in the list forever, are you going to wait forever??  :-Xuse the number of items on the list with %RANDOM% instead.
I personally have never used the %random%%10 style, but the 10, 20, 30, 40, 50 numbers was just an example.

For your example getting a random choice of a certain list, this would work. It would also work as a much quicker version than my previous code.

echo off
set /a rnd=%random%%5
set /a rnd*=10
echo %rnd%
pause>nul Quote from: Helpmeh on June 17, 2009, 06:48:32 PM
I personally have never used the %random%%10 style, but the 10, 20, 30, 40, 50 numbers was just an example.

For your example getting a random choice of a certain list, this would work. It would also work as a much quicker version than my previous code.

echo off
set /a rnd=%random%%5
set /a rnd*=10
echo %rnd%
pause>nul
and if the list of numbers is 1,2,3,4,11,13,16 for example, your code will not work isn't it? what i am saying , 1,2,3,4,11,13,16 has 7 items.  generate a random number from 1 to 7, (not the max value of the item ie 16). If the random number is 5, then use a loop or something, go through the list to position 5 and get the number "11"Yeah, I was just taking advantage of the consecutive numbers.

echo off
set /a rnd=%random%%7
if %rnd%==5 set rnd=11
if %rnd%==6 set rnd=13
if %rnd%==7 set rnd=16
echo %rnd%
pause > nul

would do the trick for your example. Quote from: Helpmeh on June 17, 2009, 07:38:03 PM
would do the trick for your example.
not enough. try not to hard code those numbers. Quote from: gh0std0g74 on June 17, 2009, 07:54:59 PM
not enough. try not to hard code those numbers.
I'm SLIGHTLY confused now...you want them set as variables?

echo off
set var1=1
set var2=99
set var3=1234
set var4=12
set var5=6
set /a rnd=%random%%5
set varout=%var%%rnd%
echo %varout%
pause>nul

Hope that works!I can't believe anybody would use a loop to generate random numbers over and over...

ever.

Even the case, where there is one index that is unused (IE, 5) can be RESOLVED without the need to resort to a looping mechanism. For example:

Code: [Select]1,2,3,4,11,13,16
the easiest way, as ghostdog said, is essentially to index the values.

Code: [Select]Sub Test()
Dim arrayTest as Variant
Dim resultrnd as Long
ArrayTest = Array(1,2,3,4,11,13,16)
resultrnd = ArrayTest(Rnd*Ubound(arraytest)+Lbound(arraytest))
End Sub

if you had a disjoint array somehow, simply inspect the returned random number; add a number equal to the amount of "nil" space that it is above.

1773.

Solve : copy to multiple computers...but differently??

Answer»

I know how to copy files to multiple computers, but i am curious if i can have files copied to multiple computer in a better way...maybe have the BAT file pull the computer names from a list or something, so the BAT file is a bit more easily read for other co-worker that MAY not work with BATs that ofthen.

Currently i am using the popular method of having many lines. But i have many computers i need to copy and was curious. Thanks for the input!

Currently using
Code: [Select]copy /Y "\\Server\share\file" \\client1\documents and settings\profile\Desktop
copy /Y "\\Server\share\file" \\client2\documents and settings\profile\Desktop
copy /Y "\\Server\share\file" \\client3\documents and settings\profile\Desktop
copy /Y "\\Server\share\file" \\client4\documents and settings\profile\Desktop
copy /Y "\\Server\share\file" \\client5\documents and settings\profile\Desktop
ETC...
You could simplify by using NET VIEW and WRITE that to a file such as NetworkedComputers.list ( to build a list ) by running NET VIEW>>NetworkedComputers.list then input that list into an array and then have the command go through each and every networked system on the list..

Running this command will write the OUTPUT of NET VIEW to NetworkedComputers.list file  ( Notation on the domain could be an issue with this list when only wanting names so you might have to go into this file and remove notation.)

""Warning without modifying this list it will go to ALL Systems and SERVERS that are part of the domain including the system that the batch is triggered from with the next portion in which you are copying files""

If you want to exclude the servers from the run you can add IF statements to test for known server names or manually edit the .list file so that it doesnt hit those systems from a single system that would run this batch server side.

This list created by:

Code: [Select]NET VIEW>>NetworkedComputers.list   

Only needs to be run once to build your list.

Then your batch will interact with this list, and all you need to do is edit the list instead of the actual batch file to add or remove systems to get the files.

If you are unsure how to read in from list into array etc let us know. If I had more time I'd put an example together but lunch break is over with and time to get back to IT.

Here is a quick peek at a sampleof it run at my network: You will need to condition (strip junk out of it) so that all you have it the list of computer names. Merchandiser below being a notation on the domain. And you will want to strip/remove all \\ and Server Name and Remark and ----------- in order to have clean names that can be passed into the batch arguments and function PROPERLY.

Quote

Server Name            Remark

-------------------------------------------------------------------------------
\\ACCT1                                                                       
\\ADAST                                                                       
\\ADETNARAID                                                                   
\\ADHANDL360                                                                   
\\ADLEBRAID                                                                   
\\ADLYMERAID                                                                   
\\ADMINASST                                                                   
\\ASTREET2003                                                                 
\\ASTREETVLI8                                                                 
\\BBXP                                                                         
\\BONNIEXP                                                                     
\\CAERDYDD                                                                     
\\CATERXP1                                                                     
\\CATERXP5                                                                     
\\CATERXP6                                                                     
\\CATERXP7                                                                     
\\CATERXP8                                                                     
\\CHEFXP                                                                       
\\CHICMERC             Merchandiser   
1774.

Solve : xcopy no prompt?

Answer»

I'm doing a copy with the following command to perform a copy.

Code: [Select]xcopy /s /c /d /e /h /i /r /k /y /q

I'm encountering "Are you sure (Y/N)?" prompt. Any idea how to I remove the prompt?xcopy  /?

/Y           Suppresses prompting to confirm you WANT to overwrite an
               existing destination file. dos isnt case senitive, have you tried it with just /y?  That should tell it to replace the file no matter.

This sort of falls in the same catagory, I'm using XCOPY to copy directoryies and it keeps asking me for DIRECTORIES or files, can I make it auto-choose directories?HELPMEH - ensure the destination path ends with a backslash to indicate a directory.

e.g. xcopy ....c:\sourcepath d:\destinationpath\Helpme,


xcopy /?
.
.
.
  /S           Copies directories and subdirectories except empty ones.
.
.
.

Dusty
Thanks, that should help!

Billrich
I want to copy the empty directories./ INDICATES the last dir at the end of the desenation an sourceThanks squall, oh and btw, you spelled guardian wrong.figures, I was tring to think of something but it evaded me.

1775.

Solve : HELP!! Converting xml file to csv using batch file?

Answer»

Hi,

Can anyone help me to do this. Thanks.

Traxcopy *.xml *.csv

This will copy all XML files as CSV's and leave a copy of the XML still present.


Cant be that simple right? You probably need to delimit your data, change its structure from the normal xml data structure?Dave,

That will only do straight copy from *.xml to *.csv, in this case i am required to save it as xml list format.

Trax
Can you POST a sample or copy of the xml file so i can see its structure?say from this;

   
  -->
-
 
 
 
 
 
 
 
-
 
 
 
 
 
 
 
-
 
 
 
 
 
 
 
-


to;

id   value   value2   value3   value4   value5   value6
RET_TRIAL   1               
RET_TRIAL      1            
RET_TRIAL         1         
RET_TRIAL            1      
RET_TRIAL               0   
RET_TRIAL                  1
RET_TRIAL_HS   1               
RET_TRIAL_HS      3            
RET_TRIAL_HS         1         
RET_TRIAL_HS            1      
RET_TRIAL_HS               0   
RET_TRIAL_HS                  1
if you have gawk for windows (see my sig)
Code: [Select]/<\/Mapping>/{f=0}
/<Mapping id/{
gsub(/.*Mapping id=\"|\".*/,"")
title=$0
f=1
}
f && /value/{
gsub(/.*value=\"|\".*/,"")
val=$0
print title" "val
}


save the above as myscript.awk and on command LINE
Code: [Select]C:\test>gawk -f test.awk file.txt
RET_TRIAL 1
RET_TRIAL 1
RET_TRIAL 1
RET_TRIAL 1
RET_TRIAL 0
RET_TRIAL 1
RET_TRIAL_HS 1
RET_TRIAL_HS 3
RET_TRIAL_HS 1
RET_TRIAL_HS 1
RET_TRIAL_HS 0
RET_TRIAL_HS 1
RET_TRIAL_ENT 1
RET_TRIAL_ENT 1
RET_TRIAL_ENT 1
RET_TRIAL_ENT 1
RET_TRIAL_ENT 1
RET_TRIAL_ENT 0

i don't really understand your output sample. (you should PUT them in code tags), so this is as far as i can go.Please see files attached.
I simply open testfrom.xml with excel and save as testto.csv (need to change the ext to attach).
Thanks.

[attachment deleted by admin]and then the sample you gave is TOTALLY DIFFERENT from the attached csv. why don't you describe properly what you want to get. I (or we) am not going to guess for you.sorry for that. i actually have few files to convert and those are the 2.
not trying to make you to guess, the first sample just too big to attached.

1776.

Solve : put limitation for avoid accessing to some steps?

Answer»

hi
i have a batch  file with  some comments and steps it seems something like this

Quote

echo off
setLocal EnableDelayedExpansion

:step1
.....
some comments

:step2
.....
some comments

:setp3
.....
some comments

:step4
.....
some comments

:end

but  i need to put some limitation  in some of steps in following way
i  want if  some files has found (php,ini,txt ) just step  1and 3 should be accessible and then  go to  end but if (xml,dll,exe)files has found all  steps should be accessible
is there any idea?


sorry  guys : if it's  possible  read  my  next  post  in  this  topic  to  find  out  more  information
C:\>type  findfiles.bat
Code: [Select]echo off
setLocal EnableDelayedExpansion

echo.  >  txtphpini.txt

dir /s /b  *.txt *.php  *.ini  >>  txtphpini.txt



echo. >  xmldllxe.txt

dir /s /b  *.xml  *.dll *.exe  >>  xmldllxe.txtC:\> findfiles.bat Quote from: billrich on June 19, 2009, 02:55:58 PM
C:\>type  findfiles.bat
Code: [Select]echo off
setLocal EnableDelayedExpansion

echo.  >  txtphpini.txt

dir /s /b  *.txt *.php  *.ini  >>  txtphpini.txt



echo. >  xmldllxe.txt

dir /s /b  *.xml  *.dll *.exe  >>  xmldllxe.txtC:\> findfiles.bat
That might not exactly help the OP out, depending on their knowledge level...

But in conjunction with your SCRIPT,

echo off
for /f "delims=" %%A in ('type txtphpini.txt') do (
REM YOUR COMMANDS HERE
REM USE %%A AS A FILE NAME
REM DON'T REMOVE THE BRACKETS
REM THIS DOES NOT NEED TO BE REMOVED
)
for /f "delims=" %%B in ('type xmldllxe.txt') do (
REM YOUR COMMANDS HERE
REM USE %%B AS A FILE NAME
REM DON'T REMOVE THE BRACKETS!
REM THIS DOES NOT NEED TO BE REMOVED
)
Will work just fine. Insert the commands for the txt, php & ini files, then copy those commands to the xml, dll & exe section, then add the xml, dll & exe only commands too.Helpme,

With all due respect, Your code is much more difficult for mioo_sara
 to understand than my code.

By the way, my code created  the "xmldllxe.txt"  file and the txtphpini.txt file .  Mioo_sara,
the original poster, offered no file names.


Quote from: Helpmeh on June 19, 2009, 04:54:59 PM


echo off
for /f "delims=" %%A in ('type txtphpini.txt') do (
REM YOUR COMMANDS HERE
REM USE %%A AS A FILE NAME
REM DON'T REMOVE THE BRACKETS
REM THIS DOES NOT NEED TO BE REMOVED
)
for /f "delims=" %%B in ('type xmldllxe.txt') do (
REM YOUR COMMANDS HERE
REM USE %%B AS A FILE NAME
REM DON'T REMOVE THE BRACKETS!
REM THIS DOES NOT NEED TO BE REMOVED
)
Will work just fine. Insert the commands for the txt, php & ini files, then copy those commands to the xml, dll & exe section, then add the xml, dll & exe only commands too.
Quote from: billrich on June 19, 2009, 05:09:36 PM
Helpme,

With all due respect, Your code is much more difficult for mioo_sara
 to understand than my code.

By the way, my code created  the "xmldllxe.txt"  file.  Mioo_sara,
 original poster, offered no file names.


I'm not saying my code is better or easier than your code. I'm saying that in combonation with both of our codes, the OP can actually use the directory your code makes to do work.

For example, if txtphpini.txt contained this:
C:\Test\test.txt
C:\Blah\test.php
C:\NONE\test.ini

then this code could delete them.
for /f "delims=" %%A in ('type txtphpini.txt') do (
del %%A
)

This reminds me of what my scout leader used to say..."Apart, you can't do anything usefull with those talents, but together you can do anything!"Helpme,

Yes, two heads working on a problem usually find a solution quicker.

But,  I don't understand what Mioo_sara is after.  Mioo_sara  needs to find files with certain EXTENTIONS: exe, ini . . . .  Many of the files are important system files and surely Mioo_sara's goal is not to delete system files or to move system files from their original FOLDER?

We  really don't have enough information to define the problem.

My code did not create any new directories (folders ).  My code created two new files and placed the files in the root ( C:\ ) directory. Quote from: billrich on June 19, 2009, 05:37:25 PM
Helpme,

Yes, two heads working on a problem usually find a solution quicker.

But,  I don't understand what Mioo_sara is after.  Mioo_sara  needs to find files with certain extentions: exe, ini . . . .  Many of the files are important system files and surely Mioo_sara's goal is not to delete system files or to move system files from their original folder?

We  really don't have enough information to define the problem.
Billrich,

Here's what I can see the OP wants:
The OP has a set of commands, some of which should only be run on txt, php or ini files, and all of them run on xml, dll or exe files.

Here's what I can see you've done:
Created a batch script that CREATES a directory of all the txt, php and ini files in one text document, and xml, dll and exe files in another.

Here's what I can see I've done:
Used the two directory files in for loops so multiple commands can be performed on each file automatically.

Here's what I see we've done together:
Completed what the OP wants.i'm  back  again
thanks dear (billrich and Helpmeh) for your replies and your scripts

Quote
Here's what I can see the OP wants:
The OP has a set of commands, some of which should only be run on txt, php or ini files, and all of them run on xml, dll or exe files.

yes helpmeh you got me !  this is what exactly  i need but  i think you and billrich  just focus on  files and not commands and steps
in  my  real  program  there is  more  than  100 lines  of codes  and there  is  lots  of  for  example  %%A so  i  think  i  should  put  my  pressure  on  something  more  unique
attention=
1- in  real  program  there  is  more  than  15  step  that  contain different  commands
2- files  should  not  follow  all commands and  steps  (one  by  one ) so  ....
3-as you  can  see in  next example some commands are  in  separated steps and  they  are acondylose
3- in below example  for  (php,ini,txt ) files ,  they  should  go  through  lots  of  commands  not  just  1 and  2
example= for (php,ini,txt ) files 

these are the steps that (php,ini,txt )files should go through
Quote
:step1
(sort by  alphabet) command

:step2
(copy  to...files)command

:STEP7
(search  to  find duplicate  files)command

:step 11
email me file names (command)

:end

it is  more  similar  to  what  i want
====================================================
Mioo_sara,

Please post your one hundred lines of code.


C:\>sort txtphpini.txt  |  More

C:\1100\SETUP.INI
C:\a-hire.txt
C:\aaa.txt
C:\bat.txt
C:\batextra\bill72.txt
C:\batextra\caavsetupLog.txt
C:\batextra\caisslog.txt
C:\batextra\christmas.txt
C:\batextra\count.txt
C:\batextra\data06.txt
C:\batextra\date.txt
C:\batextra\db.txt
C:\batextra\disklog.txt
C:\batextra\file.txt
C:\batextra\for.txt
C:\batextra\hist.txt
C:\batextra\homewk.txt
C:\batextra\Instruct_for.txt
C:\batextra\list_of_program_files.txt
C:\batextra\listone.txt
C:\batextra\log.txt
C:\batextra\noperiod.txt
C:\batextra\outmenu.txt
C:\batextra\period.txt
C:\batextra\pipe.txt
C:\batextra\session.txt
C:\batextra\show.txt
C:\batextra\signal.txt
C:\batextra\str3.txt
C:\batextra\task.txt
C:\batextra\temp1.txt
C:\batextra\test07.txt
C:\batextra\testfilnam.txt
C:\batextra\tips.txt
C:\batextra\win.ini
C:\batextra\x.txt
C:\batextra\xmas.txt
C:\batextra\xxx.txt
thanks billrich
well  i created a program  with  adobe flash  for  my  weblog
inside there is lots  of codes(action  scripts codes) but  because flash  can  not  work with  outside world easily !! i have to  use third party  tools  . so  i  choosed batch  codes because  they  are  easy  to  understand  and  easy  to  work  with
now  i  have  more than 20 bat file (i  put all of  them inside of  my  program  and  with  pressing each  button  when  we need  they  create  in  temp  folder  and  get start) but  problem  is  here  that  i want  to  put  all  these  batch  codes  in  a single  bat file and  call  every  command  from  inside  of  it
i dont  know  if it's  possible  or  what?  well  if  i put  each  particular  code  in  a  separate  bat file they will  work  very  nice  but  is  there  any  possibility  to  start  a batch  file  and  call  commands  from  inside  of  batch  file  when  we  need  it?
Mioo_sara,

Where is the code?  Post the code.

You may put all the code in one batch file.

or

You may call each of the batch files from one central batch file.

Where is  the code?  Post the code.

ok  i  will put  all  codes  in  a  batch  file  and  send  it  to  you
1777.

Solve : Detect time in batch file?

Answer»

i need my batch file detect time....

like this:---> if the time 16:45 and above goto shutdown...........
                    if not goto first

can somebody help me.......??there are two METHODS you could use,
the AT method that would add a scheduled time and command:
Code: [Select]AT 16:45 "c:\path to batch\shutdown.bat"
shutdown.bat:
Code: [Select]shutdown -s -t 30

orrr.
you can check time and all using the FOR loop:
Code: [Select]echo off
for /f "tokens=1-3 delims=:." %%a in ("%time%") do set newtime=%%a%%b
if %newtime% GEQ 1642 goto shutdown
goto first
pause

:shutdown
shutdown -s -t 10
exit

:first
rem commands

the script will interpret %time% into a 4 digit number with no .'s

then if the %newtime% (1642) is greater than or equals to 1642 goto shutdown
or goto first
that is not what i want......
ok let me explain clearly
if using AT command it just run when time is correctly punctual...
but now i want to run the second batch file even after time 16:45 which mean 16:46, 16:47, 16:48, 16:49 and on
so then you wouldn't need to use the at command if you use the batchEasy...

echo off
:start
commands
for /f "tokens=2 delims=: " %%a in ("%time%") do if %%a%%b gtr 1645 (goto shut) else (goto start)
:shut
shutdown -s -t 01

That should work...as long as its in 24h format. Quote from: Helpmeh on June 13, 2009, 02:52:30 PM

Easy...

echo off
:start
commands
for /f "tokens=2 delims=: " %%a in ("%time%") do if %%a%%b gtr 1645 (goto shut) else (goto start)
:shut
shutdown -s -t 01

That should work...as long as its in 24h format.

helpmeh, theres one flaw in the script
Quote
for /f "tokens=2 delims=: " %%a in ("%time%") do if %%a%%b gtr 1645 (goto shut) else (goto start)

tokens should equal 1-2 because it will only turn out as:
(minutes)%%btotally missed that...writing on a dsi is hard.psp isn't a walk in the PARK either  Quote from: BatchFileBasics on June 14, 2009, 11:30:16 AM
psp isn't a walk in the park either 
Too true...although DSi Internet uses the touch screen for typing, loading the keyboard takes a lot of time, as does everything...it also has a 700 something by 800 something resolution...and it uses opera, which I have never used previously.yea.
i am using opera right now. very fast to start up cold and all.
its pretty fast too. doesn't burn your CPU down(well mine anyway). Quote from: BatchFileBasics on June 14, 2009, 12:09:55 PM
yea.
i am using opera right now. very fast to start up cold and all.
its pretty fast too. doesn't burn your cpu down(well mine anyway).
Other than opening the keyboard, it's fairly fast...yea,
and seeing from other posts, you really love telling people.

Quote
that should do it...I had to MAKE that on my dsi so I had to write everything, no copypasta.

Quote
btw, I can't test it as I am STILL on my DSi

Quote from: BatchFileBasics on June 14, 2009, 12:28:32 PM
yea,
and seeing from other posts, you really love telling people.


I'm excited is all...I got it for my confirmation (along with $250), so I've been GOING crazy!i know how you feel. when i first got my psp. myspace was so fun haha.

"hey whats up, i just got my psp and im writing right now!!!!"

"hey guys guess what, im writing on my psp"

hahaI see you guys are working hard on Fareast187's problem.
1778.

Solve : Custom Screen Saver Issues?

Answer»

Hello everyone!

My new issue is with a custom screen saver. Our Home Office has sent out a screen saver to use at our campuses. They included an EXE that will install a screen saver and set it as the default. What i did was run the EXE so it placed the "ITEP_SS.scr" in "C:\WINDOWS\System32\". Then i copied the "ITEP_SS.scr" so i COULD make a BAT file that will be used to install it. Every TIME i run my BAT file the screen saver NEVER stays as the new one. After applying the BAT file to copy and install as the default the screen saver setting is set to "None". Does anyone have any suggestions? Below is what my BAT file looks LIKE. I added the pause in there to see if there were issues copying or adding the entries, but there are none.

Code: [Select]mkdir "C:\Program Files\IT\ITEP_SS\ScreenSaver"
copy /Y "%~dp0\screensaver\ITEP_SS.scr" "C:\Program Files\IT\ITEP_SS\ScreenSaver"
copy /Y "%~dp0\screensaver\ITEP_SS.scr" "%SystemRoot%\system32"
pause
reg add "HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 0
reg add "HKCU\Control Panel\Desktop" /V ScrnSave.exe /T REG_SZ /F /D "%SystemRoot%\system32\ITEP_SS.scr"
reg add "HKCU\Control Panel\Desktop" /V ScreenSaveTimeOut /T REG_SZ /F /D 3000
reg add "HKCU\Control Panel\Desktop" /V ScreenSaveActive /T REG_SZ /F /D 1
pause

Any ideas are MUCH appreciated.I am so sorry for the double post, but i found a partial FIX for my issues...

When you change the following line:
Code: [Select]reg add "HKCU\Control Panel\Desktop" /V ScrnSave.exe /T REG_SZ /F /D "%SystemRoot%\system32\ITEP_SS.scr"
To

Code: [Select]reg add "HKCU\Control Panel\Desktop" /V ScrnSave.exe /T REG_SZ /F /D "ITEP_SS.scr"
It seems to work for changing the screen saver. THe only issue now, it that the "wait" option is set to 20 minutes and i can not get it to disable or change. Any ideas guy and/or gals?

1779.

Solve : logon.bat help - resources if in specific groups?

Answer»

Hello again!

I am working on a logon script and having a bit of trouble. I am looking to install printers and maps specific drive according the an OU the signing on user is in.

So this is an example.
If the user is in the OU called "ACCOUNTING" i want to have the printers called "aact1", "acct2" installed. also i would like to map the drive letter "z" to "\\server1\share1".

I know the commands to map a drive and printer i am just having issues with the if statement with the OU.

Printer CODE
Code: [Select]REM installs printer
RunDll32.EXE printui.dll,PrintUIEntry /in /n \\server\printername2

REM To set DEFAULT Printer
rem RunDll32.EXE printui.dll,PrintUIEntry /y /n \\server\printername2

mapped drives Code: [Select]REM MAP H: To Users
NET USE H: \\server\share


Thank you for your help!Is it blatting about credentials missing? What is your error message?

The NET USE without {user/password} MAKES me believe your having authentication issues possibly with your instructions.Well the commands i am using are working. I would just like to add some "if" commands so i can only apply the printers i want to use to a user in specific OU in AD. Same with the mapped drives. I am just very fuzzy when it comes to using the if statement in this setting.I'm not sure what OU is, or how to use it, but this could work (modify OU to what you want).

if /i "OU"=="accounting" (
your commands here
don't remove the brackets!
)Thank you for the section of section of code. I will see if that will work ith what i am trying to do.

Active Directory Organizational Units can be explained here -> http://technet.microsoft.com/en-us/library/cc758565(WS.10).aspx

1780.

Solve : In need of a batch file HELP!!!!?

Answer»

Im sorry...totally new to the forum.

What i am in need of is a batch file that looks at the date stamps of a particular file.

We are supposed to get new files from a vendor daily, and I want to use my monitoring program to run the batch file to determine if we have recieved a new file in the last 2 days.

Im totally not a programmer!! HA..

Thanks in advance.

MWelcome to the CH forums.

Quote

We are supposed to get new files from a vendor daily

Will all files be in the same folder?   Will all files have the same extension?   What is your date format?

Please read this.

Quote from: Dusty on June 17, 2009, 03:37:30 PM
Welcome to the CH forums.

Will all files be in the same folder?   Will all files have the same extension?   What is your date format?

Please read this.



Files will ALWAYS be in same folder.... always .txt extension and date format is month/day/year (4 digit year) Windows..

I apologize for not being more thorough.

Thanks.

MThis script is totally untested...  It hopefully will check for a filedate of yesterday and today so that if the date today is the 20th it will check a filedate of 19th and 20th.  If you want to check for 18th 19th and 20th CHANGE the echo otherdate = (Date(^)-1^) command line to echo otherdate = (Date(^)-2^)

Code: [Select]echo off
cls
setlocal

set newfile=%temp%newfile.vbs

(
echo otherdate = (Date(^)-1^)
echo   yy = datePart("yyyy", otherdate^)
echo   mm = datePart("m"   , otherdate^)
echo   dd = datePart("d"   , otherdate^)

echo wscript.echo yy^&" "^&mm^&" "^&dd
)>>%newfile%

FOR /F "tokens=1-3" %%A in ('cscript //nologo %newfile%') do (
        set year=%%A
        set month=%%B
        set day=%%C

)

del %newfile%

        if %month% lss 10 set month=0%month%
        if %day%   lss 10 set day=0%day%

set today=%year%%month%%day%%

for /f "delims=" %%1 in ('dir /b "path\filename.txt"') do (
    set filename=%%1
    set filedate=%%~t1
)


set filedate1=%filedate:~6,4%%filedate:~3,2%%filedate:~0,2%


if %filedate1% geq %today% echo %filename% date/time is %filedate% & exit /b
   echo %filename% date/time %filedate%is not within 2 days of today's date. & exit /b


Good luck.

Edit: changed script in response to Ghostdog74's post below. Quote from: Dusty on June 17, 2009, 05:17:45 PM
If you want to check for 18th 19th and 20th change the set /a command line to set /a today=%today%-2
i am sure you know you can't simply minus a date like this in batch? extra code is needed to check dates for eg if date is 01 Jun and 02 Jun, then 2 days before is 30, 31 may.... Quote from: mattf2171 on June 17, 2009, 03:41:47 PM
Files will ALWAYS be in same folder.... always .txt extension and date format is month/day/year (4 digit year) Windows..

I apologize for not being more thorough.

Thanks.

M
NOTE windows file names cannot have "/".
assuming you can download GNU coreutils  (SEE my sig) you can use GNU date
Code: [Select]echo off
for /f "tokens=*" %%a in ('date_gnu "+%%m/%%d/%%Y" -d yesterday') do ( set yest=%%a)
for /f "tokens=*" %%a in ('date_gnu "+%%m/%%d/%%Y" -d "2 days ago"') do ( set twodaysago=%%a)
echo %yest% %twodaysago%
output
Code: [Select]C:\test>test.bat
06/17/2009 06/16/2009

use the if/else  to compare your dates. Quote from: ghostdog74
i am sure you know you can't simply minus a date like this in batch?

OMG how could I have made such an enormous fup?  Thanks for your timely reminder.  Should have switched on brain when getting out of bed.

D.I am working on modifying the script to suit my situation.

Thanks to all who have responded. Its a great help.

I will post back with results.

M
1781.

Solve : Creating an Hex file using a Batch file?

Answer»

Hi all,

I need to create Hex files using a batch file.

I've got this part of the code working for when I need simple text to be exported to a Hex file:
Code: [Select]CMD /U /C echo this is a test>>hex.txt
But the problem is that I also need to be able to write stuff directly in the hex section of the file. Using CMD /U only converts text to unicode, so adding a blank spot between EVERY letter, but I also need to add NUMBERS and values directly in the hex section of the code.

For example, I would need to add the number 76 before the word "animal"

If I simply echo "76animal" it will export as:
.7.6.a.n.i.m.a.l
00 37 00 36 61 00 6e 00 69 00 6d 00 61 00 6c
But what I would need is actually:
.La.n.i.m.a.l
00 4c 61 00 6e 00 69 00 6d 00 61 00 6c

Does anyone know if that would be possible?Seems to me that what you've shown is the hex display of a binary file.  Binary files are usually displayed in hex notation to make them more human friendly so that instead of displaying 01001100 the display shows hex 4C which can be interpreted as the letter L.  To ALTER the binary file content you need a PROGRAM to write binary values,  afaik not available in the Command Interpreter.

You could look at using Debug or a suitable programming language.

Good luckOP, if you download GNU tools ( see my sig ), you can use od command
Code: [Select]C:\test>echo "sfsfdfsg" | od -x
0000000 7322 7366 6466 7366 2267 0d20 000a
0000015

1782.

Solve : renaming file extensions?

Answer»

i'm trying to RENAME a file extension with a batch file run from my USB which will CHANGE the file extension of a designated file in the computer. im aware of the ren command but so far only managed to MAKE it rename the file extensions in the same directory. *problem solved* i managed to work it out for myselfAll it takes is sticking to it.

1783.

Solve : Error message too many files open?

Answer»

Hi there,
I am using Windows XP with 2.2 ghz duo PROCESSOR and 3gb of ram.  I have msdos foxpro based accounting program for my company.  When I try to work on the program, while saving the file it gives a ERROR message of "too many FILES open".  Please any one explain why this error is displaying.    Hello, rameshgujjetty. Wow! MS-Dos FoxPro!
To get rid of this error You should EDIT the file 'C:\Windows\System32\Config.nt'
There have to be two strings, 'Files=xx' and 'Buffers=xx'. Replace xx with 250 for 'Files=' and with 150 for 'Buffers=', or in case there is no such string(s), add it to the bottom of the 'Config.nt' file.Heads will roll if your company auditors are given accounts processed by Foxpro on an unsupported Operating System.

I suggest you get a proper MSDOS system, either salvage an ancient machine, or adapt your computer for dual-booting.

Regards
Alan
thank you sir for your valuable ADVICE

1784.

Solve : How to send the data to an application invoked from ssh?

Answer»

Hi All,
         I am newbiee for writing batch files.I have WRITTEN a batch file to log into linux machine from my windows through putty and to invoke an application on the remote end. I have to send the data to the application from my windows machine. My batch file looks like this....

type image | putty.exe -t -l root -pw anil123 -m anil.txt 10.50.25.53

where as the image contains the data to be sent to application.
anil.txt contains the application to be invoked.

what i have observed was, i am able to loginto the linux machine and able to invoke the application but not able to send the data to the application.My control is GETTING STUCK in the application which i have invoked and with the pipe command i am not able to send the data to application.....

please HELP me.......thanks in advance

Anil.
    I have asked for this to be re-directed to the correct forum.your application anil123 takes an image file as an input correct?? you can just SCP over the image file, then invoke the application.Thanks for the quick reply......

In my batch file, Image is the file which contains the data to be sent to the application that is invoked on the linux machine.....

linux machine to be specific i am working on a embedded device on which uClinux o.s is
running. so i can't winscp the image on to board........


Anil.

1785.

Solve : How to invoke a application from telnet?

Answer»

Hi All,
         
         I am trying to write a BATCH file which will log into a LINUX machine(after authenticating user name and password) and to invoke a application.

i have tried myself and searched in net for help......i tried different methods including the following.....

telnet 10.50.25.53 < ANIL.txt

where anil.txt contains the application to be invoked....


please help me its very urgent.....

Anil.
I have asked for this THREAD to be moved to the RELEVANT thread please wait for the response.you can't really do it like that. windows telnet client doesn't have that ability. if you want to call an applicatoin remotely , use a programming language that allows you telnet functions, eg Perl's Net:Telnet , or Python's telnetlib. etc.

1786.

Solve : Runnig 2 batch file?

Answer»

Hello All,
There is an example of what I am try to ACHIEVE

I Created a test1.bat file. Inside that batch file added
-----------
echo off
cls
START C:\test2.bat
-----------

Now I created  test2.bat and added it to test1.bat
-----------
echo off
cls

echo.test 2 here..
pause
-----------

When I execute I see the test2.bat open due to the pause command. What I was try to achieve is the test2.bat should close on its own even though you have a pause command.
When you complete the action I see the command prompt still running. I need to close it once the execution is done.
Hope if any one could help me.

Thanks &AMP; Regards
Girish Katti
The pause command will wait for a key to be pressed to continue. I do not know the technical reasons, but it will cause the command window not to terminate or continue on until a key has been pressed.

If the window remains open even after the script has completed, try adding CMD /c between start and test.bat .Hi,
Adding CMD /C closes the window after the second batch file is executed. Is there any way we can close the batch file having a pause entry.
I to agree its virtually not possible to do but any work around.
If you want it to stay open, replace cmd /c with cmd /k.Hi,
What I exactly need was to close the batch file having a pause statement.
Presently we are calling the second batch file from the first batch file and while we execute the first the second still remains open due to the pause statement.
I need the second batch file to close when we execute the first one.

Thanks in advance.


Quote from: girishkatti123 on June 21, 2009, 10:22:26 PM

I need the second batch file to close when we execute the first one.
Thanks in advance.
That just won't work. Pause waits for a key to be pressed. If you want to wait for a specific time, try this. Replace xx with desired time in seconds.

PING localhost -n xx -w 1000 > nulThanks for all your inputs.
I will use the ping command and then send a enter keyword to the batch file.

1787.

Solve : Empty folders after WinRar Compression wildcard. PLEASE HELP!?

Answer»

Good Day

I am trying to LEARN VBs scripting for my work. I have a task to schedule a script which can compress FILES of the past month once every month.

example: MAY 1 - 30 files compress every Jun 15th.   

Sources: C:\Test\May1\files.txt
               C:\Test\May2\files.txt
               C:\Test\Jun1\files.txt
               C:\Test\Jun2\files.txt

In my vbs script I wrote:
 objShell.run "CMD /C cd \ & cd C:\Program Files\WinRAR\ & WinRAR a -r C:\ArchiveDestinationFolder\FileName.rar C:\Test\May*" 

The output results to a FileName.rar with folders May1 and May 2 BUT THEY ARE EMPTY! there are no files.txt inside them!

What seems to be the problem? Please help

1788.

Solve : installing ansi.sys driver in xp pro?

Answer»

howcan i install ansi.sys driver in xp PRO can you help me ?WELCOME to the CH forums.

For ANSI.SYS in the Command.com shell see here..

1789.

Solve : Reversing a string in batch?

Answer»

As the title suggests, I want to reverse a string/variable in batch. Eg. the input is HELLO and the output is olleh. I know it is possible in vbs, but if possible, the script needs to be put in batch.Code: [Select]echo off
setlocal enabledelayedexpansion

set LINE=sdas sfsa fwfwa21321
set num=0

:LOOP
call set tmpa=%%line:~%num%,1%%%
set /a num+=1
if not "%tmpa%" equ "" (
set rline=%tmpa%%rline%
goto LOOP
)
echo %rline%

pauseThanks so much!anything can be put inside  a put batch, including the cscript /wscript engine. Its better next to time state you want "pure cmd.exe commands without use of external TOOLS".
As always Devcom's  effort is over and above.  Does Devcom work for Microsoft?

C:\>type  hi.bat
echo off
Code: [Select]setlocal enabledelayedexpansion

set line=%1
echo  line = %line%
set num=0

:LOOP
call set tmpa=%%line:~%num%,1%%%
set /a num+=1
if not "%tmpa%" equ "" (
set rline=%tmpa%%rline%
goto LOOP
)
echo reverse = %rline%
Output:

C:\> hi.bat  Hello
 line = Hello
reverse = olleH
C:\>

_______________________________________ _

For a laugh I will show a newbie effort with batch:


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

REM  http://www.dostips.com/DtTipsStringManipulation.php

setlocal enabledelayedexpansion

set x=%1
echo x = %x%

set x=%x:~-2,-1%
echo  %x% > rev.txt
set x=%1
set x=%x:~-3,-2%
echo  %x% >> rev.txt
set x=%1
set x=%x:~-4,-3%
echo  %x% >> rev.txt
set x=%1
set x=%x:~-5,-4%
echo  %x% >> rev.txt
set x=%1
set x=%x:~-6,-5%
echo  %x% >> rev.txt
type rev.txt
C:\>hello.bat  "Hello"
x = "Hello"
 o
 L
 l
 e
 H

C:\> Quote from: billrich on June 20, 2009, 02:54:12 PM

As always Devcom's  effort is over and above.  Does Devcom work for Microsoft?

lol , im not here's a one liner, using gawk
Code: [Select]C:\test>echo hello| gawk "BEGIN{FS=\"\"}{for(i=NF;i>0;i--)printf $i}"
olleh
1790.

Solve : MS dos driver installation?

Answer»

I recently loaded an older dell dimension 2350 with freedos, it doesnt have any other os on the hd. I loaded it to play the OLD elder scrolls games, the only PROBLEM is that it doesnt detect a sound card at all, so i figured i NEED to get a driver for it. I got a generic soundblaster driver that i think should work well enough, but i dont know anything about dos really. I was wondering if SOMEONE could walk me through installing a sound driver in dos or at least point me in the right direction. Also, no i do not know what type of card it is, since i really dont know my way around dos. if it helps at all, i am using the gem gui that came with freedos.The sound card will most likely not work unless you can find a DOS driver specifically for your sound card.

An easier solution (with sound support for modern cards) is DOXBox. It runs in Windows, EMULATES a Sound Blaster for DOS programs, then shoots it through whatever sound card Windows is using.

1791.

Solve : help with deleteing files based on file name?

Answer»

hey all,

I have loads of files that need sorting.

In a nut shell an avi file is created each time someone walks past a camera at work. We need to keep a solid month but delete everything older.

I'm going to be adding this as a scheduled task and I'm after help as to how to go about it.

the files are NAMED like this; yyyymmddhhmmss (year month day hour minute second) 20090623163154.avi

What the best way to go about this??

Should i be trying to compare file names against the system date (month only) and then deleting everything else or is there a better way??

Any thoughts would be greatly appreciated This can be done a number of ways ( Date/time stamp checked - or - have the routine store the avi's into FOLDERS for each month and have a process that performs a clean up that is automated to delete the folder older than 2 MONTHS so that say on July 1, you dont lose June's data, but May will disappear).

The lesser complicated being a monthly routine that on the first day of the next month it Moves all avi's from the last Month Folder to 2ndMonth folder, then Move all local avi's to the last month folder, then on the last day of the month delete all avi's from the 2ndMonth folder so the next day on the 1st, the avi files from last month them move into 2nd month and the process repeats over and over again in a shuffle and deletion process.

Hi thanks for the reply.

I hadn't thought about using folders to organise it and then cleaing up the older folders. - Good idea


How can i LIST all the month numbers (cut form file name or from date modified) that are currently in the folder and then assign to a varaible??

Chees again

So are you saying you want to get all the months that each of the files were made in(or there file name) and set to variable? Quote from: blastman on June 23, 2009, 09:33:10 AM

Any thoughts would be greatly appreciated

download GNU findutils(SEE my sig),and use the find command , problem solved.
Code: [Select]c:\test> find_gnu.exe  c:\path -type -f -name "*.avi" -mtime +30 -delete
the one liner above delete avi files more than 30 days old. cheers for all the replies guys.

I'm going to cheat as I found a vbs script I'd written a few years ago and managed to change a few details to get what i wanted.

Thanks for all the comments.
1792.

Solve : Command prompt icon is in my start menu?

Answer»

Thank you for looking at my post.
In my start menu, I notice the DOS icon, in with others in the last programs recently used.
I dont remember having used it, so why is it there?

It must have been used for something, for it to be there right?
Will a history or something tell me what it was used for or when?you used it when you were talking with that person on the phone- the alleged MICROSOFT tech.


Remember? You said he wanted you to run cmd... etc.Im no Guru,

You May remove the Command Prompt from the list:
(Point to Command Prompt icon, right click and choose "remove from List")

Thanks BC_Programmer, I might have thought that except I didn't actually do any of the things he wanted me to...
I didn't even write them down. I was just being inquisitive and ARGUMENTATIVE with him to test his resolve.
Turns out he didn't have much, though I must admit I can be RATHER belligerent to people on the phone like that. They, after all were paying for the call. I wanted to keep him on for as long as I could.... but he cracked.

Thank you too billrich, it is annoying just having it there. Haa! That was EASY... gone. Thanks 

Just thinking now what does RUN:  CMD actually do then?opens a command prompt. I myself use it all the time.BC_Programmer.  AH I see. So I would have used that then, to look at a dos program.
I think thats is what might have been the case with that then. I was trying to load some games onto a computer at the time.
I might have tried to look at where the program was or run its .exe file and it might have come up.(maybe)?

1793.

Solve : MS DOS 6.2 Question?

Answer»

Do you know where i can get MS DOS?
I need it for windows 3.1 that i want to install. I did some searching and found something similar.  It's called freeDOS
Also, apparently MS DOS is free now, I'm still trying to find the LINK for you though.

It's amazing what I can find when someone peaks my curiosity I also found a link to DR-DOS, I wasn't sure if they would still be around or not.I just remembered, if you have Windows 95 or Windows 98 you should be able to extract MS DOS from there. Quote from: Quantos on June 25, 2009, 11:25:55 PM

I did some searching and found something similar.  It's called freeDOS
Also, apparently MS DOS is free now, I'm still trying to find the link for you though.

It's amazing what I can find when someone peaks my curiosity
I have FreeDos but the problem i belive is that Windows 3.1 must have MS Dos. It is actually legal to use if you own a newer Windows OS is what i heard.

Quote from: Quantos on June 26, 2009, 12:25:22 AM
I just remembered, if you have Windows 95 or Windows 98 you should be able to extract MS DOS from there.
Well i have 98SE, will that work? I think Windows 3.1 needs MS DOS 6.22 or older (as old as 3.0 works).MS-DOS/IBM-DOS 3.1 is the minimum required version for windows 3.1.

It works with PC-DOS 2000 as well as DOS 7.1, too. Quote from: BC_Programmer link=topic=86311.msg577261#msg577261
It works with PC-DOS 2000 as well as DOS 7.1, too.
[/quote
So is MS Dos 7.1 in 98SE?  Quantos was saying i could take the DOS from a 95/98 pc...
yes, that would be 7.1. I don't know how to "extract" it from windows, but I would imagine it's done by creating a SYSTEM disk on the windows PC and copying the relevant DOS files, such as fdisk,format, find, etc. as well as performing the SYS command on the other PC's hard drive. Quote from: Cityscape on June 25, 2009, 11:11:35 PM
Do you know where i can get MS DOS?
I need it for windows 3.1 that i want to install.

Perhaps you could purchase a legal copy from someone on eBay.

Here's an easier solution.  Install Windows 98SE.  Then install TweakUI, it can be found on the 98SE disk, or you can SEARCH Microsofts site for it.

This utility installs in your Control Panel. After installing it you go to the Control Panel and click on the TweakUI icon. Then click on the Boot TAB and change the boot settings any way you want.

Set it to boot without the GUI, reboot and install Windows 3.1.


You owe me

Quote
How to Boot to a Command Prompt by Default

This article describes how to configure Windows to boot to a command prompt automatically.

http://support.microsoft.com/kb/141721 Quote
This article describes how to configure Windows to boot to a command prompt automatically.

TweakUI is a lot easier, and provides more features.  Of course on the same note, he will have to get used to doing things in the command line.  You can't use DOS without that knowledge. Quote from: Quantos on June 26, 2009, 04:54:09 PM
TweakUI is a lot easier,

Really?    I've no idea... never used it.
This way though,  no software to install -   just edit a file, and you're done.   I can't imagine anything easier than that.   

Quote
and provides more features.  Of course on the same note, he will have to get used to doing things in the command line.  You can't use DOS without that knowledge.

Yep.
But    Edit     is very easy to use. 


Heck...  I wonder if he could just edit the file with Notepad? 

Quote
Heck...  I wonder if he could just edit the file with Notepad?

To be completely honest I don't remember if Notepad has the priveleges to edit msdos.sys.  I would recommend using the command line like the article says though.  If Notepad worked I'm sure the GUY writing the article would have suggested it.Win 98SE is DOS 6.2....not DOS 7.1.
1794.

Solve : Copy/Sync files from network location?

Answer»

Hi there, well I am not to sure if this is possible; I've had a look around and being only new to writing dos based commands (in a batch file) I am stuck with trying to do the following:

At the moment I have two COMPUTERS networked and I want to in a sense "backup/sync" a specific folder (this being the my pictures folder; I want it to have hard COPIES exactly the same on each computer). I've managed to get it to copy the pictures over (only new files from the source that don't exist on the target computer); I want to be able to delete pictures from the target computer that have been deleted from the source computer.

This is what I have at the moment:
-------------------
echo off

echo Grabing New Files From Mary-PC Pictures

NET USE z: \\Mary-PC\Pictures

XCOPY z: c:\Users\John\Pictures\ /D /S /Q

echo Complete

Pause

Exit
------------------

So yeah I want to now delete files from the target computer (John) that are no LONGER on the source computer (Mary-PC) but I am not sure on how to accomplish that.

Any help would be highly appreciated
you could TRY and run the dir /b command redirect that to a text file and run a loop on the text file to see if the file exists on the target computer.

Code: [Select]DIR /B > %temp%\DIRCHECK

SET FILELOC=%temp%\DIRCHECK

FOR /F "usebackq tokens=1-2" %%A in ("%FILELOC%") do (
SET A=%%A&& SET B=%%B && CALL FILECHECK %%A

:FILECHECK

1795.

Solve : Getting DOS 6.22 to recognize a cd drive.?

Answer»

Hi,

In the attached file I have the insructions needed to get DOS to use a cd drive. Please read the file.
My questions are:
1. which lines do i put the commands on?
2. it GOES before what and after waht?
3. do i double space etc.

I basicly need to know how to format the file properly.

Help?

[ATTACHMENT deleted by admin]Post a copy of your config.sys and your autoexec.bat.

What kind of CD drive is it?Then do a search for the OakRom CD drivers... Quote from: Quantos on June 27, 2009, 04:19:30 PM

Post a copy of your config.sys and your autoexec.bat.

What kind of CD drive is it?
Okay, i've attached them in TEXT format.
It's just a standard LG DVD-ROM drive.

Quote from: patio on June 27, 2009, 04:24:56 PM
Then do a search for the OakRom CD drivers...
I have the OAKCDROM.sys in my C:/Dos folder.

[attachment deleted by admin]These should work.  Just rename them back to config.sys and autoexec.bat.

[attachment deleted by admin]So where in the file do i add "DEVICEHIGH=C:\DOS\oakcdrom.sys /D:MSCD001"?
and where in the other file do i add "LH C:\DOS\MSCDEX.EXE /D:MSCD001"

Do they have to be in a certain place/order to work?
And do i have to remove/modify ANYTHING when i add these?Use the files that I posted.  They are already edited Thanks a lot!!! I've been TRYING to get this working for a month or 2. I writing this using IE 3 in Windows 3.11 now.

I guess i owe you one now Quantos. We absolutely Love success stories here.... Well, that makes me feel a lot better

Just for that I'm going to treat myself to a bowl of ice cream.I'm havin a Guinness myself...Guiness Ice Cream Float. Quote
Guiness Ice Cream Float.

I like the way that you think.

Mmmm, creamy....
1796.

Solve : help with move?

Answer» IM tryign to exectue a move command on windows XP but when i run it it says that the syntax is incorrent. can anybody tell em whats going wrong? this is what i have so far.

move c:\DOCUMENTS and Settings\[USERNAME]\folder c:\folderWhenever the path CONTAINS spaces, use quotes.
Move "C:\Documents and Settings\%username%\file.txt" C:\folder

That would work, and %username% is your username.
1797.

Solve : Append date to a file?

Answer»

I would like to use the copy /xcopy or RENAME command and take a file and rename it to INCLUDE the date - is that possible.
i.e. rename "file1" to "file1_mmddccyy"It most definately is possible, here's the syntax.

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

Note that you cannot specify a new drive or path for your destination file.what is the command to get the date on the file ? Quote

REN [drive:][path]filename1 filename2

Change directories to the directory where the file in question is stored.
Then type
rename filenamehere.whatevertheextensionis whatyouwantittobenamed.whatevertheexten sionis do you mean datestamp?

Code: [Select]for /f "tokens=2-4 delims=/- " %%a in ('date/t') do set date2=%%a%%b%%c
you can then use xcopy to rename it to %date2%.ext

the date will then be 06252009
if ONLY your date IS in a mm/dd/yyyyC:\>type  datename.bat
Code: [Select]echo off

for /f "tokens=2-4 delims=/- " %%a in ('date/t') do set date2=%%a%%b%%c

echo date2  = %date2%

copy  try.bat  try%date2%.bat

type  try%date2%.bat

Output:

C:\>datename.bat
date2  = 06252009
copy  try.bat  try06252009.bat
        1 file(s) copied.
type  try06252009.bat

ECHO OFF
ECHO 1 - Stars
ECHO 2 - Dollar Signs
ECHO 3 - Crosses
echo Enter Choice
.
.
,as previously said, the date/t command is dependent on regional settings of the computer. either extra batch code need to be written to take CARE of that, or just use tools that take care of that for you automatically. eg VBSCRIPT
Code: [Select]Set objFS = CREATEOBJECT("Scripting.FileSystemObject")
Set objArg = WScript.Arguments
strFile = objArg(0)
Set objFile = objFS.GetFile(strFile)
today = Now
yr = Year(today)
mth = Month(today)
dy = Day(today)
If Len(mth) <2 Then
mth="0"&mth
End If
If Len(dy) <2 Then
dy="0"&dy
End If
strDate = mth&dy&yr
newfilename = objFS.GetBaseName(strFile) & "-" & strDate & "." &objFS.GetExtensionName(strFile)
objFile.Name = newfilename

save the above as test.vbs and on command line
Code: [Select]C:\test>cscript /nologo test.vbs file1.txt
1798.

Solve : my new batch program "batch editor" download?

Answer»

batch editor

UPDATE

sorry I messed up with the file name part here it is again fixed;
And I added a new feature you can chose the color of the text and background of the batch file you are making.


WHY I MADE THE BATCH EDITOR

I made the batch editor first for me, so I could make batch FILES really easy
but  I decided that I would put It on the internet, after some kind people helped me out on a problem with the batch editor.


ABOUT THE BATCH EDITOR,

The batch editor is a PROGRAM that lets you use shortcut words to make batch files.
This is the first version, and I will be working on updates.

(If you have any comments, QUESTIONS or suggestions please feel free to post them.)

THE DOWNLOAD

The download size is 7.05KB


[attachment deleted by admin]There's a dedicated thread to this, but if someone discovers a problem in your file, this is a good place to post it.ok what name is the name of the thread
thankyou There is sticky thread for posting apps

[attachment deleted by admin]I moved it.
Thankyouhow do I delete this thread?You can't, that would be something that the forum moderators need to do.ok THANK you

1799.

Solve : Batch command needed to delete oldest file in multiple directories?

Answer»

I can't fight this battle anymore alone so I'm turning to this forum for help.

Objective:
To create a batch file that would - for each directory, DELETE the oldest file in the directory if the number of files is greater than 2.  I would also like to log the date and which directory/file is being deleted into a simple txt file.

This will be run as a scheduled JOB on an XP Pro workstation every day as part of an attempt to keep "data backup files" from FILLING up an external USB drive. 

I've got the snippets of code and can place them into "For" and "If" loops but I just can't seem to get them linked TOGETHER so the variable is passed to the next command.  I almost got it to work but it would choke on the "|" (pipe) command or I'm sure I had a single/double quote in the wrong spot.  After I was done it must have been 30 lines of code and created a dozen tmp files - scary!

Here are the snippets so you don't have to recreate them.

echo off
setlocal EnableDelayedExpansion

REM enumerates directories
dir /A:D /B

REM counts number of .tib files in a directory
dir folder1\*.tib /B | find /v /c "::"

REM sorts .tib files (newest to oldest) in a directory
dir folder1\*.tib /B /O:-D

Any help is appreciated,
Joni


BTW: This script will do what Acronis True Image said it would do as part of its feature-rich product - Yeah, still waiting Acronis!!See here (example 4) for a vbscript, if you can use it.It looks like example 4:  "Copy oldest modified file to Destination" comes closest to my needs but considering I'm worse at VB than I am at simple batch commands, I may be in the same boat in trying to tie in my other needs.  I'll work on this tonight and report back. 
Thanks for the reply!
Well, I can stumble through on what the code will do when run but I'm not sure how to compile it.  I don't have time to learn a NEW language now but thanks for the examples anyway - I'm sure I'll use them in the future.

1800.

Solve : help with copy.?

Answer»

I'm trying to run a file from my flash drive which allows me to copy a batch file from the flash drive into a specific directory on the main COMPUTER, and then run the copied file on the computer instead of running the file from my flash drive. any help with this would be much appreciated.ok here is a code that I think will work

Code: [Select]echo off
copy (flash drive, drive letter) (look in my computer)://"(full PATH of the batch file in the flash drive)/(batch file name)" to C://"Documents and Settings/Computer user name/The Directory you want"
call C://"Documents and Settings/computer user name/The Directory you want"
Unless you know what the drive letter of the flash drive will be not SURE it will work.  thanks alot, i have the problem sorted now and its all working well. Quote from: squall_01 on June 22, 2009, 03:18:21 PM

Unless you know what the drive letter of the flash drive will be not sure it will work. 

If it's in the drive (not in any directories) then use %cd% and if it's on more than one computer, use %username%.I always copy STUFF to the current directory by using ".". At least for those commands that whine if I don't give a target.
I use cd .. a lot, as well.unless you know what its going to be it wont help any