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.

7601.

Solve : How to run another program several times with different input??

Answer»

Hello,

if someone could help me it would be great! I use LINGO, which is a tool for solving LINEAR systems and performing optimization. I have developed some such "programs" in LINGO (LINGO has a "language" of its own). These "programs" take some parameters as inputs and give a number as output. What I WANT is to run this programs I MADE several times, e.g. 1000 times, with different inputs each time. In other words I want to perform a loop, something that LINGO does not give me the means to do.

So, I want to make a batch file that calls the specific file I made in LINGO and runs it several times with different inputs that I will provide in the batch file. Does anyone know how to do this? I am a beginner in writing batch files.If you give examples of LINGO COMMAND line syntax (what a command line with parameters looks like) you will probably get an answer. If you EXPECT us to do the research, maybe not.
I would appreciate if you share the solution of this problem with me as I experience the same problem.
Thanks in advanceEDIT: Geeze, it was a graveyard post.

Quote from: minnie on March 23, 2012, 06:42:46 AM

So, I want to make a batch file that calls the specific file I made in LINGO and runs it several times with different inputs that I will provide in the batch file.

How will you provide the input? Are the numbers in a plain text file, one per line?
This sort of thing could work.

Code: [Select]@echo off
for /f "delims=" %%a in (input.txt) do (
for /f "delims=" %%b in ( ' lingo.exe /switches %%a ' ) do (
>>file.log echo input was %%a and output is %%b
)
)
7602.

Solve : Power Plan import windows 7?

Answer»

Hi,

I am trying to have my batch file import a customized power plan I created. The MACHINES will be windows 7 x64, but would like it to work with x86 also. Here's my batch so far:


@Echo OFF
powercfg -import "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
pause


Now, the problem is 2 things:

1. UNC paths are not accepted
2. There's the actual power plan file to import (path seen in the batch file)

The question is, How do I reference the correct path within the batch file since I cannot use UNC paths? Thanks!
@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "PowerPlan.pow"
pauseQuote from: Squashman on May 22, 2012, 07:20:50 PM

@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "PowerPlan.pow"
pause

You know...., I wrote that up earlier but didn't end up even trying it because of this:
http://www.sevenforums.com/tutorials/75562-power-plans-export-import.html

This guide didn't have an option for just: powercfg -import "PowerPlan.pow"
For the record I almost tried that! I will try it and post back. Thanks!Z:\Standard Install\Win7 Configs\Files for Scripts>powercfg -import "WonderGroup Desktop PowerPlan.pow"
The file could not be found.

Yeah, it didn't work unfortunately. I even tried the file without quotes. I looked at the parameters with the help flag and it states that you MUST specify the actual path:
-IMPORT Imports all power settings from the specified file.

Usage: POWERCFG -IMPORT

Specify a fully-qualified path to a file generated by
using "PowerCfg -EXPORT parameter".

Any other ideas? Thanks for your help!Hmm, Powercfg must work differently on Windows 7. Windows XP says you need to use the /File switch to pull from an existing config file and it doesn't say anything about having to use the fullpath to the file name either. XP also uses slashes and not hyphens for the switches. I hate it when Microsoft keeps switching back and forth on that crap. They did that with FORFILES when Server 2003 came out.

Ever here of the %CD% variable!


C:\>pushd \\Server\volume\FTPTEMP

Z:\FTPTEMP>echo %CD%
Z:\FTPTEMPQuote from: Squashman on May 23, 2012, 08:25:10 AM
Hmm, Powercfg must work differently on Windows 7. Windows XP says you need to use the /File switch to pull from an existing config file and it doesn't say anything about having to use the fullpath to the file name either. XP also uses slashes and not hyphens for the switches. I hate it when Microsoft keeps switching back and forth on that crap. They did that with FORFILES when Server 2003 came out.

Ever here of the %CD% variable!


C:\>pushd \\Server\volume\FTPTEMP

Z:\FTPTEMP>echo %CD%
Z:\FTPTEMP

I'm not sure what you're getting at . How can I apply these commands to my batch?The %CD% variable is the full path to the CURRENT DIRECTORY you are in. You said you needed the full path to your Power Configuration file.Quote from: Squashman on May 23, 2012, 12:55:36 PM
The %CD% variable is the full path to the CURRENT DIRECTORY you are in. You said you needed the full path to your Power Configuration file.

Oh, I understand what you mean. I'm sorry, what I meant is I have the full path and it will never change... but the file path is located on a network drive so therefore I cannot include the path to the power plan file in the batch as indicated below:

@Echo OFF
powercfg -import "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
pause

~And the batch that we tried (below) didn't work because it needs the full path to the file whilst using the import command:

@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "WonderGroup Desktop PowerPlan.pow"
pause

I just need to import the "WonderGroup Desktop PowerPlan.pow" file using the powercfg -import command, but it doesn't work because it's a UNC path. I am not needing to Echo/Print/Show the path name in the batch file. I just need the batch file to import the file located on the UNC drive.

Got it? . I hope I clarified my question! HAHAH. You are not understanding what the Pushd command does and what the %CD% variable is.
The pushd command maps a drive letter to your unc path and then makes that drive letter and directory the current working directory!

Powercfg -import "%CD%\Wonder Group Desktop PowerPlan.Pow"

Do you see the light!Quote
The pushd command maps a drive letter to your unc path and then makes that drive letter and directory the current working directory!

Not quite. The pushd <directory> command puts the current directory on the stack and changes to the directory indicated. The companion command (popd) PULLS a directory entry from the stack using a last-in first-out (LIFO) method and makes that the current directory. Nothing is mapped. Pushd can be used to save the directory where the batch file originated, and popd can be used to restore it for the user. In between the batch file can change directories as needed without leaving the user lost in the directory structure.

I think it would be better to use the net use command to map the UNC to a regular drive:\path notation and go from there.

Code: [Select]net use Z: \\reagan\mis$
powercfg -import "Z:\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
net use Z: /d

I know what PUSHD and POPD does, but trying to explain it to him for this exercise was becoming futile. I am trying to explain it to him in layman's terms so he understands because obviously he is not understanding.

I do this all the time in my scripts where a command will not accept a UNC path.

The only issue with using the NET USE command is that you cannot guarantee that DRIVE Letter is not already in USE unless you sit there and use a FOR LOOP to check what drive letters are already in use. PUSHD and the %CD% variable is the perfect solution for this problem.Thank you all for the help. I am no expert with CMD but I am familiar with the %CD% AND pushd/popd commands .

1. [Powercfg -import "%CD%\Wonder Group Desktop PowerPlan.Pow"] doesn't work as it throws an error (I tried it after your initial post)
2. net use could work, but as squashman notated - someone might have the drive z: already mapped

So, I'm still stuck

FYI:

C:\Users\cfash>pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

Z:\Standard Install\Win7 Configs\Files for Scripts>powercfg -import "%CD%\WonderGroup Desktop PowerPlan.pow"
An UNEXPECTED error condition has occurred. Unable to perform operation. You m
ay not have permission to perform this operation.Well to make sure it really is not a Permissions issue, manually map a drive letter to that UNC path and then run the powercfg command. You should just be able to type all that at the cmd prompt without creating a batch file just to check if it is a permissions issue.

We can use the NET USE command, it will just add a lot of extra code to your script. You can tell NET USE to map to the next available drive letter and then we can rerun the NET USE command inside a FOR LOOP to find out what drive letter got mapped to that share.As suggested, you can use "NET USE" to obtain a drive letter:

Code: [Select]@Echo Off
for /f "tokens=1-2" %%a in ('net use * \\reagan\mis$ ^| find "is now connected to"') do set netDrive=%%b
powercfg -import "%netDrive%\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
net use %netDrive% /d
Pause
7603.

Solve : Zip a single file using winzip?

Answer»

For some reason i can not figure out how to jsut grab one file zip it. This command line grabs everything in the folder and zips it. am i missing something... I just want to grab the a single .jpg file and zip it?

The file is i want to zip is called 15.jpg
I also wanted to MOVE the zip file to another directory listed underneath...
C:\Documents and Settings\user1\My Pictures"

which i think the -m does but I'm not sure how to add it as well can someone help?

Code: [Select]
"C:\Program Files\WinZip\WINZIP32.EXE" -a "C:\Documents and Settings\user1\My Documents\New Folder\15.zip"

First of all .you can not use WinZip in DOS. It is a Windows program
PKZIP is free and runs in DOS.
http://pkzip.en.softonic.com/
Sorry, that is the wrong version...
Here is the DOS version.
http://www.pkware.com/software/pkzip/dosGeek, if daillest39 is able to run a program from C:\Program Files, then clearly they are talking about Windows command prompy and not "DOS".

WinZip supports command line options to add and extract from files.

When adding files the command format is:

[Path to]\winzip32.exe [-min] action [options] filename[.zip] files

where:

-min specifies that WinZip should run minimized. If -min is specified, it must be the first command line parameter.

action
-a for add, -f for freshen, -u for update, and -m for move. You must specify one (and only one) of these actions. The actions correspond to the actions described in the section titled "Add dialog box options" in the online manual.

options
-r corresponds to the Include subfolders checkbox in the Add dialog and CAUSES WinZip to add files from subfolders. Folder information is stored for files added from subfolders. If you add -p, WinZip will store folder information for all files added, not just for files from subfolders; the folder information will begin with the folder specified on the command line.

-ex, -en, -ef, -es, and -e0 determine the compression method: eXtra, Normal, Fast, Super fast, and no compression. The default is "Normal". -hs includes hidden and system files. Use -sPassword to specify a case-sensitive password. The password can be ENCLOSED in quotes, for example, -s"Secret Password".

filename.zip
Specifies the name of the Zip file involved. Be sure to use the FULL filename (including the folder).

files
Is a list of one or more files, or the @ character followed by the filename containing a list of files to add, one filename per line. Wildcards (e.g. *.bak) are allowed.

So,

In your SITUATION this would be the command line:

"C:\Program Files\WinZip\WINZIP32.EXE" -a "C:\Documents and Settings\user1\My Documents\New Folder\15.zip" "15.jpg"

If you want to then move the zip file to another folder, why don't you just specify that folder as the zip file destination?


@Salmon Trout

It worked perfect thank you Quote from: daillest319 on April 03, 2012, 01:20:53 PM

@Salmon Trout

It worked perfect thank you

All I did was type "winzip32.exe command line" into Google.
I have always just used the command line add on client.
http://www.winzip.com/downcl.htm
Most of our automated batch files use this where I work.
7604.

Solve : How to write a batch file to copy directories recursively and then create a shor?

Answer»

Hi there,
I need to create a batch file which can perform following actions.
1.Copied directories and sub directories from source folder OLDER than 10 days to destination
folders.
2. Delete copied directories from source folder and create short cuts for that in source folder.
I have written the following batch file. But I am not getting proper result which I want.

@echo off
@echo copying file to Archive folder
XCOPY c:\tempMovetoUDrive U:\Archive /e/d:03/20/2012
pause
@echo creating a SHORTCUT for copied files
set SHORTCUT_NAME=Shortcut to copied files
set SHORTCUT_PATH=C:\tempMovetoUDrive
set PROGRAM=U:\Archive
set WORK_DIRECTORY=C:\tempMovetoUDrive
set ICON_FILE=%SYSTEMROOT%\system32\SHELL32.dll
set ICON=4
set WINDOW_STYLE=1
echo SET oWS = WScript.CreateObject("WScript.Shell") > tempshortcut.vbs
echo sLinkFile = "%SHORTCUT_PATH%\%SHORTCUT_NAME%.lnk" >> tempshortcut.vbs
echo SET oLink = oWS.CreateShortcut(sLinkFile) >> tempshortcut.vbs
echo oLink.TargetPath = "%PROGRAM%" >> tempshortcut.vbs
echo oLink.IconLocation = "%ICON_FILE%, %ICON%" >> tempshortcut.vbs
echo oLink.WindowStyle = "%WINDOW_STYLE%" >> tempshortcut.vbs
echo oLink.WorkingDirectory = "%WORK_DIRECTORY%" >> tempshortcut.vbs
echo oLink.Save >> tempshortcut.vbs
WScript.exe tempshortcut.vbs
rem del tempshortcut.vbs

Any help would be appreciated.
Many thanks
Contrary to popular belief, XCOPY does not do file aging. If the /d switch is present, files dated on or after the /d switch date are copied. A solution might be ROBOCOPY where you can age the files and maintain the directory structures.

You can get ROBOCOPY here

The shortcut CODE looks OK, but I did not test it, just made sure the batch code transferred into the VBS code correctly.


7605.

Solve : Cmd to produce list of computers on domain that are turned on?

Answer»

Hi Guys

Does anyone know the command that creates a FILE of all the PC's that are turned on.

i know there is one as i've used it before but i CANT find it in my notes.

thank you

p.s forgot to say i am using psexecNot sure if this is what you are LOOKING for.
http://www.hostalive.net/hostalive.htmlthanks guys

i found the solution

NET VIEW>>NetworkedComputers.list

7606.

Solve : Batch file creation?

Answer»

Quote from: rossBNE on October 01, 2012, 08:45:25 PM

c:\\dir\fort.exe &LT;in.dat&GT; out.dat

So, the batch file has to make this type of call.

Then this would be your batch file. Can you explain further? Try creating a new thread with descriptive title, RATHER than using someone else's thread.

Code: [SELECT]@echo off
c:\dir\fort.exe <in.dat> out.dat
7607.

Solve : Copy %CD% to server %username%?

Answer»

So were doing a server move and staff rename and didn't want to COPY all our staffs old files over to the new one. We wanted them to do it so were not storing old stuff they never use anymore.

I would like to be able to copy the current location the .bat file will be in (on the old server \\server\staff_folders\userfolder) to \\server\staffhome\%USERNAME\


So figured something like below but just can't get it to work. I am prolly missing something simple..

Copy current directory to their new staff folder.

netuse x: \%cd%
copy x: \\file1\staffhome\%USERNAME%\

I'm not going to be using this for every staff member but it would help me speed up the process as I know a bunch of them that constantly use their space properly.

Any help would be greatly appreciated!!! In a batch, the directory where that batch file is located (physically stored) is %~p0, (that's a zero) so you could try using that instead of %cd% which is the current directory, which is not necessarily the same.

Full path and name would be %~dp0


Thanks I tried switching that out and it still doesn't work :/

That's good to know for FUTURE reference!! You will not get the server and share name from %cd% or %~dp0

net use x: \\server\staff_folders\userfolder

or

pushd "\\server\staff_folders\userfolder"
:: commands here
popd
OK after searching and searching here is what I've come up with that works..

Now the only problem I'm having is I'm trying to run this on XP and Win7. Since they changed Documents and Settings to Documents I need to figure out a way to have it check somehow. If anyone knows a way that would be great, I'm still searching and learning.


@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /h /i /r /k /y /EXCLUDE:excludebackupcopy.txt

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up your Desktop...
%backup% "%USERPROFILE%\Desktop" "\\file1\staffhome\%USERNAME%\Desktop\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\Documents" "\\file1\staffhome\%USERNAME%\My Documents\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseYou could parse the output of the VER command and do different THINGS according to the major version number (5 for Windows 2000 & XP, 6 for Vista, W7 & W8)

e.g. (just a pointer):


for /f "tokens=1-6 delims=. " %%A in ('ver') do (
if "%D"=="6" (
set pname=Documents
) else (
set pname=My Documents
)
)


2000
Microsoft Windows 2000 [Version 5.00.2195]

xp
Microsoft Windows XP [Version 5.1.2600]

windows Vista
Microsoft Windows [Version 6.0.6001]

Windows 7
Microsoft Windows [Version 6.1.7600]


Awesome sounds PERFECT!!!

I've tried it a few different ways but still can't figure out how to implement it into this. Here is where is makes logical sense to me lol Still kinda learning this stuff..


Code: [Select]@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /i /r /k /y /EXCLUDE:excludebackupcopy.txt

for /f "tokens=1-6 delims=. " %%A in ('ver') do (
if "%D"=="6" (
set pname=Documents
) else (
set pname=My Documents
)
)

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\My Documents" "\\file1\staffhome\%USERNAME%\My Documents\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseTry this:

Code: [Select]@echo off
:: variables
set drive=x:\Backup
set backup=xcopy /s /c /d /e /i /r /k /y /EXCLUDE:excludebackupcopy.txt

ver |find " 6.">nul && (set pname=Documents) || (set pname=My Documents)

echo ### Backing up current folder...
%backup% "%cd%" "\\file1\staffhome\%USERNAME%\"

echo ### Backing up My Documents...
%backup% "%USERPROFILE%\%pname%" "\\file1\staffhome\%USERNAME%\%pname%\"

echo ### Backing up Favorites...
%backup% "%USERPROFILE%\Favorites" "\\file1\staffhome\%USERNAME%\Favorites\"

echo Backup Complete!
@pauseThanks but now I get errors. Invalid drive specification..


Code: [Select]This PC is running Windows 7 Enterprise
### Backing up current folder...
Invalid drive specification
0 File(s) copied
### Backing up My Documents...
Invalid drive specification
0 File(s) copied
### Backing up Favorites...
Invalid drive specification
0 File(s) copied
Backup Complete!
Press any key to continue . . .
You are also getting errors in lines that I did not alter.


The \\file1 server is not online probably.
Well this is odd. My old script that was working yesterday isn't working either...

Servers are up and running. I can browse to each location, create, view, and edit files.. Try this:

Code: [Select]@echo off
dir "\\file1\staffhome"
pause
Well your version worked!!! Thanks!

My boss changed a ton of permissions yesterday. So I setup a share on a local machine and it worked perfectly! Now to figure out what he changed.......

Thanks for your help!!!!

7608.

Solve : CAN AN ASCII CHARACTER 0Dh OR 0Ah BE PLACED INTO A TEXT FILE USING A DOSBATCH??

Answer»

I HAVE A TEXT FILE WITH MANY LINES

TEXT.............TEXT
TEXT.............TEXT
TEXT.............TEXT
TEXT.............TEXT

AND I WANT TO KNOW HOW TO USE A BATCH FILE THAT FORCES A TAB
OR CARRIAGE RETURN OR BACKSPACE INTO THE TEXT FILE?

TEXT.............TEXT [CARRIAGE RETURN]
---->LINE space CREATED HERE
TEXT.............TEXT [CARRIAGE RETURN]
---->LINE space CREATED HERE
TEXT.............TEXT [CARRIAGE RETURN]
---->LINE space CREATED HERE
TEXT.............TEXT [CARRIAGE RETURN]

SO THAT EACH LINE IN THE NEWLY CREATED TEXT FILE HAS A CARRIAGE RETURN
BETWEEN EACH LINE.

WOULD ANYONE KNOW HOW TO GO ABOUT THIS?Quote

WOULD ANYONE KNOW HOW TO GO ABOUT THIS?

Yes. Please try turning of your CAPS LOCK and stop shouting at us. We are a peaceful tribe

Most any script language can handle the characters found on any ASCII chart. Batch code, well not so much. Batch code can handle carriage returns however.

Code: [Select]@echo off
setlocal

for /f "tokens=* delims=" %%i in (Text.txt) do (
echo %%i >> newText.txt
echo. >> newText.txt
)

File names and paths are your responsibility. GOOD luck.


edited to add the word "please"
7609.

Solve : Is it possible to add or delete pagefile.sys size and partiotion with DOS??

Answer»

Here is what I'd like to accomplish. I can do some DOS batch stuff, but other than that I am a brainless ol fart.

I have two partitions setup with aprox. 4GB each, named PageFile_1 and PageFile-2. I'd like to use only one of them at any
given time.

Every couple of weeks, I would like to UNALLOCATED from one partition and allocate to the other partition. After this is DONE I would
like to securely wipe the recently used partition so that it is ready for the next swap.

Is this possible via DOS only? I know I can wipe the free space with systernals "sdelete" via a batch file, just don't know if allocating and unallocating the pagefile.sys from partition to partition is possible.

Could use some insight with this.

ThanksPerhaps something like this:

Code: [Select]===== BATCH SCRIPT BEGIN =====
@echo off
GOTO menu
:menu
echo.
echo What would you like to do?
echo.
echo Choice
echo.
echo Change Pagefile.sys from Drive E: to Drive G: or visa versa
echo Q Quit

echo.

:choice
set /P C=[e,g,q]?
if "%C%"=="q" goto quit
if "%C%"=="g" goto SetG
if "%C%"=="e" goto SetE
goto choice


:SetG
echo Set Pagefile.sys to Drive G: at 3000, 3000?
pause
cls
regedit.exe /s DriveG_PageFileSize.REG
pause
goto menu

:SetE
echo Set Pagefile.sys to Drive G: at 3000, 3000?
pause
cls
regedit.exe /s DriveE_PageFileSize.reg
pause
goto menu

:quit
exit
:end
===== BATCH SCRIPT END =====

DriveG_PageFileSize.reg
Code: [Select]Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"PagingFiles"=hex(7):47,00,3a,00,5c,00,70,00,61,00,67,00,65,00,66,00,69,00,6c,\
00,65,00,2e,00,73,00,79,00,73,00,20,00,33,00,30,00,30,00,30,00,20,00,33,00,\
30,00,30,00,30,00,00,00,00,00

DriveE_PageFileSize.reg
Code: [Select]Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"PagingFiles"=hex(7):45,00,3a,00,5c,00,70,00,61,00,67,00,65,00,66,00,69,00,6c,\
00,65,00,2e,00,73,00,79,00,73,00,20,00,33,00,30,00,30,00,30,00,20,00,33,00,\
30,00,30,00,30,00,00,00,00,00
I would have to reboot before running sdelete.exe to wipe the cleared drive.The next question, one that arises after exporting the .reg key is: why does the following line...

Code: [Select]NAME TYPE DATA
PagingFiles REG_MULTI_SZ E:\pagefile.sys 3000 3000

appear as...

Code: [Select]"PagingFiles"=hex(7):45,00,3a,00,5c,00,70,00,61,00,67,00,65,00,66,00,69,00,6c,\
00,65,00,2e,00,73,00,79,00,73,00,20,00,33,00,30,00,30,00,30,00,20,00,33,00,\
30,00,30,00,30,00,00,00,00,00
...and, is there a way to get the .reg file in the first format, so that it is editable?I really appreciate all the help and suggestions!!

What would I do without you guys!

7610.

Solve : Using an Incrementing variable in a For /R Loop?

Answer»

I have a number of log files that all get named the same when created, but placed in different directories. I need to move and rename all the files to one directory, and have come up with a way to name them according to the computer name and time/date of move, but the batch executes so quickly that all the files end up with the same name still.

I figure the best way to eliminate the problem is to use a incremented variable to add to the name (blahFile_1.csv,blahFile_2.csv,blahFile_3.csv) This is the code I have so far:

Code: [Select]@setlocal enableextensions
@cd /d "%~dp0"
@echo off
SETLOCAL enabledelayedexpansion enableextensions


cd ..\..\..\Accounts\logs\FileUsage\


for /R %%A in (*FileUsageSummary*.*) do (


set fCount=1
copy "%%A" D:\Logs\FileUsage\%computerName%_%time:~0,2%%time:~3,2%_%date:~4,2%%date:~7,2%%date:~-2,2%_!fCount!.csv
set fCount+=1
echo !fCount!

)
ENDLOCAL

My output files however, still end up named the same. What am I doing wrong?

THANKS!
-ian
You need to use !date:~2,2! with the exclamation marks with delayed expansion. Similar with the time.

And your set command NEEDS a /a

set /a fcount+=1

and put this at the top of the batch file before the forindo loop:

set fCount=1

One thing to consider is USING a format similar to Filename-YYYYMMDD-HHMMSS.ext to name your files as this will sort naturally in a folder.

You can also add this in your loop and it will delay each file copy slightly so that each has a distinct time stamp.
ping -n 3 localhost &GT;nulThat worked perfectly! Thank you for the help!

Why did I need the /a? I suspect that's the major missing part. What does that tell DOS to do with the variable?/a tells it it is to do arithmatic otherwise you are SETTING the string 'fCount+' equal to 1 and not adding 1.Quote from: dustmites on August 07, 2012, 01:33:13 PM

Why did I need the /a? I suspect that's the major missing part. What does that tell DOS to do with the variable?

1. a (or A) is for Arithmetic. To find all the things that SET can do, type SET /? at the prompt
2. This isn't DOS.

7611.

Solve : copy all files and folders from current folder?

Answer»

Quote from: Sidewinder on April 02, 2012, 02:52:59 PM

If you select a folder, and right click the mouse, what do you expect to happen?

A context menu which includes Send To should appear, shouldn't it?


Quote from: mioo_sara on April 02, 2012, 04:16:28 AM
... but cuz source folder is changing every day so program should find the source folder (that is my current folder) and copy any folder and files from there to destination folder (d:\backup) ...
Why not get a freeware file synchronization/backup program such as Allway Sync - there are others but this is one I've used - and use it to achieve your objective? Seems to me this would be easier solution than trying to resort to some DOS technique. Quote from: soybean on April 02, 2012, 06:01:36 PM
Why not get a freeware file synchronization/backup program such as Allway Sync - there are others but this is one I've used - and use it to achieve your objective? Seems to me this would be easier solution than trying to resort to some DOS technique.
I agree. Some Sync utilities can be invoked with a template to automate a task. That might be called 'batch' programming, but it is not just plain DOS. Many programs run from a command line and run a script.

Example:some programs are written in Excel and use VBA. Such business class programs backup and archive files that have been imported. Such are often paid only programs. Some are found on download.com and have free trial.

But not knowing the intent of the OP, it is hard to know if giving bits and pieces of DOS code if he does not understand how to integrate the parts. And it not clear if he wants to invoke the DoS batch code from the GUI or the command line.

IMHO the OP needs to read some tutorials on VBscript and Cscript.
Using the command-based script host (CScript.exe)Quote
As far as I know, this has to be done thru the registry. Is this what you did?

yes i add it thru registry

Quote
But not knowing the intent of the OP, it is hard to know if giving bits and pieces of DOS code if he does not understand how to integrate the parts. And it not clear if he wants to invoke the DoS batch code from the GUI or the command line.
its part of my flash project .unfortunately flash is so week for working with windows so i should do the rest with batch programing !
i used lots of batches and 80% of the job has done so i prefer to do the rest in this way
Quote
its part of my flash project .unfortunately flash is so week for working with windows so i should do the rest with batch programing !
i used lots of batches and 80% of the job has done so i prefer to do the rest in this way

Now I am totally confused. You want to flash the BIOS?
No, you want to write a system utility using Adobe Flash. Huh?

The natural choice for a Flash app is to extend it with Java. But C# would also work. Even current versions of Visual Basic CONTROL FLASH thing.

I have never hears of DOS batch used as a supplement, extension or replacement for Flash. But there is a lot I don't know.

Are you writing a Windows app or a browser app? Browser apps often use JavaScript, vb-scrip, ActiveX or even Java at the client side.

The DOS batch stuff is essentially twenty years old. With a few improvements in recent years. IMHO it is not well suited for browser apps. It is suited for doing backups and archives and removing dead files. Not so good for doing anything visual.

Only 80% of your code works? Did you model the code? You need to get up to 99 % of your code working before working on kinks.
Have you verified the logic and sequence of your code?

A practice of professional programmers is to write a large part of the code in the best programming tool that they can use. Then fill in the tough spots with things imported from other software tools.

I am unable to visualize this with FLASH and DOS batch.
Sorry I can not help you with your quest. But keep at it and eventually you will find a solution. It is not really impossible.

Have you ever read books on structured programming? Or books about program design and incremental refinement ?
Books on structured programming with C#Quote from: Salmon Trout on April 02, 2012, 03:43:30 PM
A context menu which includes Send To should appear, shouldn't it?
I agree. Putting it into the SendTo menu which doesn't require a registry edit works perfectly. I have done that with a few of my batch files over the years.

Another option would be to just drag the source folder onto the batch file which would take it as input in the variable %1.OK. Last try. This goes back to the original question as I understand it or at least how I think I understand it. First up is a VBScript to allow the user the select a folder for the XCOPY operation:

Code: [Select]Const RETURN_ONLY_FOLDERS = &H0001
Const WINDOW_HANDLE = 0
Const MY_COMPUTER = 17

Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( WINDOW-HANDLE, "Select Folder", RETURN_ONLY_FOLDERS, MY_COMPUTER )

'Check For Cancel Button; Nothing Returned
'
If TypeName(objFolder) <> "Nothing" Then
WScript.Echo objFolder.Items.Item.Path
End If

Save the script in any folder with any name and a VBS extension.

Next up is the batch code. Replace the for statement in your existing batch file with the code below:

Code: [Select]set target=D:\Backup
for /f "tokens=* delims=" %%i in ('cscript //nologo drive:\path\scriptname.vbs') do (
if .%%i NEQ . (echo D | xcopy "%%i" %target% /e /c /y > d:\filelist.txt
) ELSE ( goto :eof )
)

Change drive:\path\scriptname.vbs to point to where you saved the VBS script.

The user will be presented with a dialog allowing selection of any folder on the system. Only folders are shown to reduce clutter. Use the left mouse button to highlight the folder name and PRESS OK. The folder path will be returned to the batch file for use by the XCOPY operation. If you CANCEL the folder dialog, the entire batch file will terminate. A file will also be created with a listing of what was copied. (filelist.txt)

Feel free to TWEAK the code as needed.

If you find this useful, then great. If not, well then not so great.

Exit stage left.
dear Geek-9pm

Quote
you want to write a system utility using Adobe Flash. Huh

yes . but i don't use latest version(adobe cs4 or 5) i'm using adobe flash 8
its rather old but unfortunately i should use it .in cs4 or 5 adobe added adobe air so you can work directly with the outside world throu java vb or lots of other scripting languages

Quote
I am unable to visualize this with FLASH and DOS batch

adobe flash 8 has not allowed any command that even think about executing anything(except media ) even opening a window in windows explorer is a big problem ! and you should do lots of scripting tricks!!

Quote
Only 80% of your code works?
no i never said that !! what i mean was my project has reached to 80% and its near to end

by the way thanks for the link
dear Squashman

please read post below i think my bad English is the problem !
dear Sidewinder
thanks for the time and script that you wrote for me
its working very nice but wish it could act automatically it needs final user to specify the source folder . cant it be done by the program itself?
please read my last post i pot another script and another explain i think cuz of my bad English i explain the situation awful!!
ok guys i'm back again !
sometimes knowing a language is not enough and you should know how to ask !
Albert Einstein !!!

first of all sorry for my bad English its my teacher's fault !
i think i explained a simple question in a very hard or bad way and i made the situation very hard and so i did not got what i wanted at the first place
now forget about right click or any stupid idea that i said at the post #1( wish i could edit it)
now i try to explain my question in a easy to understand way


lets imagine we have a folder (named johns) and we want to copy all the files and folders(including sub folders)from johns to d:\backup
that's all that's what i want !! so we copy a batch file to johns folder and run it.. now batch should start the copying process .is it that hard for even old fashion Dos base batch file to do?
now the problem is that if i could put source folder name (johns) in batch script problem could be solved but cuz final program will use these batches and source folder name will be changed in a frequently time so i prefer that batch do this job for me
i mean batch Dir from the current folder and copy any including object to the destination
below you can see a simple batch that do this but instead of coping it moves the objects(i don't like this)

Quote
@echo off
cd
dir/s/b > filelist.txt
for /f "delims=" %%F in (filelist.txt) do move "%%F" "D:\backup"

any idea ?If it is the current directory you wish to copy, you can specify the current directory using a period (.):

For example, let us go with your example; let's say we have a folder Johns on C: drive; Let's say we are writing the batch file to run from within that folder (again, following your example scenario).

if we want to copy all files and folders from the current directory, we can use xcopy and the period

Code: [Select]xcopy . D:\backup /s /i

There is something of a complication: this doesn't necessarily refer to the folder the batch file is in. If you want to always refer to the folder that the batch is in (as opposed to the current directory of the command prompt session running the batch file) you can use this instead:

Code: [Select]xcopy %~dp0 D:\backup /s /i






my my my dear BC_Programmer thank you very much it worked like a charm
that was a simple but breath taking question ! you really help me thank again
i was really becoming disappointed and thought its simple but its not possible with dos !
i pressed thanks button and if there was 200 more buttons there i would have pressed them for you
=================

and other guys
Geek-9pm ---Sidewinder---Squashman----Salmon Trout
thank you all too you tried to teach me a lot

i have a little problem i forgot to ask how should this batch file create a folder in destination and rename it to current folder's name before copying files and folders from current directory to it
in another language
1-first create a folder in destination d:\backup\ and rename it to current folder's name= example johns(where my files and folders located now)
2- now copy files and folders from current directory(johns) fo d:\backup\ new destination folder (example=johns)
thanks

thanks its done above post has been solved thanks dear friends
7612.

Solve : Booting Windows (from HDD) out of DOS?

Answer»

Hi all,

I have a SPECIFIC PXE booting solution in mind but I'm missing a little bit of DOS knowledge to make it work. Here is the situation:

I want to have PXE as the first boot option in BIOS on my workstations; from PXE I boot WINPE which loads a menu script, giving you 3 options: Windows, linux and boot from hard drive. If you choose windows or linux, Ghost.exe is started with a parameter that either PUSHES a Windows or Linux IMAGE, depending on your choice.

If you choose 'boot from hard drive', it simply has to load the OS that is on the HDD (windows in most cases). However this means that I somehow have to insert a section in my DOS script that loads the OS from the hard drive and I have no idea how to do this; googling hasn't really helped so far.

Is there anyone that has experience with this and could point me in the right direction?

Thanks in advance!if your version of Windows (which you conspicuously don't state) is any NT family OS (Windows 2000, XP, Vista, 7 etc) you simply cannot START it from MS-DOS. However, if I read your query correctly, you aren't running "DOS" at all, but a command prompt in Windows PE. You can't boot an installed Windows from PE either. You MIGHT be able to do something with Grub4DOS. For the benefit of all it would help you the OP would explain what PXE is and why it should control the boot process.
http://en.wikipedia.org/wiki/Preboot_Execution_Environment

As ST stated, GRUB is the most universal boot loader for use on desktop computers and there is one version for DOS.
http://en.wikipedia.org/wiki/GNU_GRUB

7613.

Solve : Batch file - output " ...done! " after an operation??

Answer»

Perhaps I'm just boneheaded and not seeing the obvious, but can someone please tell me how I'd get my batch to append " done! ", or similar, after an operation?

I know I can do this with clever use of the ECHO command, as below, but I'm wondering if there's an easier way because using the ECHO method gets tedious when several commands are desired on screen.

A simple example of what I'm using now:

Code: [Select]@ECHO OFF

CLS
ECHO Running command 1...
Put command 1 here

CLS
ECHO Running command 1... done!

CLS
ECHO Running command 1... done!
ECHO Running command 2...
Put command 2 here

CLS
ECHO Running command 1... done!
ECHO Running command 2... done!
ECHO Running command 3...
Put command 3 here

CLS
ECHO Running command 1... done!
ECHO Running command 2... done!
ECHO Running command 3... done!

ECHO All done, exiting...

EXIT


The output, (with command 3 not yet complete), would look LIKE this:

Code: [Select]Running command 1... done!
Running command 2... done!
Running command 3...
You are looking for a way of appending something to the same line?

So you have

Running command 1... (then you run command1) and then you see done! at the end of the same line - is that what you want?

Here is a trick using set /p to show text without a newline:


@echo off
0>nul set /p="Running command1... "
ping www.google.com > nul
echo done!





QUOTE from: Salmon Trout on APRIL 09, 2012, 07:04:07 AM

You are looking for a way of appending something to the same line?


Yea, that's exactly what I want, thanks!


So, If I'm thinking this through correctly, I'd use your template above and simply replace your ping command for mine, yes?

Can I assume that this method supports multiple commands?

For example:

Code: [Select]
@echo off
0>nul set /p="Running CommandSet1... "
ping www.google.com > nul
ping www.sony.com > nul
ping www.yahoo.com >nul
echo done!

Since experimentation is the key to learning, why don't you try that and see if it works?
Just got done doing so and ANSWERED my own questions, thank you!Another thing to try:


@echo off
0>nul set /p="Running CommandSet1"
ping www.google.com > nul
0>nul set /p="."
ping www.sony.com > nul
0>nul set /p="."
ping www.yahoo.com >nul
0>nul set /p="."
ping www.yahoo.com >nul
0>nul set /p="."
ping www.yahoo.com >nul
0>nul set /p="."
ping www.yahoo.com >nul
0>nul set /p="."
ping www.yahoo.com >nul
0>nul set /p=". "
echo done!

Perfect, thanks!
7614.

Solve : CPU usage without wmic?

Answer»

Hi all!
I'm Italian (sorry for my English!) and I would write a batch file that measures CPU usage percentage.
After I'll "invoke" this batch file by jsp page and I'll can see output in a web page.

My .bat uses wmic:
Code: [Select]ECHO off
wmic path Win32_Processor get LoadPercentage /format:list
and I've this PROBLEM: waiting time for wmic is too high and my web page don't show me LOAD Percentage.

Is there another DOS command that doesn't use wmic?

Thanks!


7615.

Solve : Assistance creating backup script?

Answer»

I'm trying to create a batch script to enumerate user profiles on both Windows XP and Windows 7 workstations. The purpose of the script is to:
1.) First the script will determine the operating system and run the appropriate commands for the different user profile file structures.
2.) Then the script will delete any user folders older than 45 days
2.) Copy some folders and files from each remaining user profile to their respective network shares (their H: drives - in this case \\cfs002\%Username%). The files/folders would be dumped into a folder named "backup" on their H: drives. The script thus far is enumerating and reading the contents of the user profiles just fine, but I'm having difficulty with the code to move the folders to each user's respective network drive.
During Enumeration the variable %%K takes on the C:\Users\Username value. I want to take just the username portion of that path and have that value PUT into destination directory (incorrectly coded %%K). Currently it is putting 'C:\Users\Username' in that variable, but I just want Username to be passed to it.
ie. (Windows 7 SECTION) C:\Users\Username\Favorites folder needs to get COPIED to \\cfs002\Username\Backup\
The script is currently trying to copy it to \\cfs002\C:\Users\Username\Backup (which obviously won't work). I need to strip out the "C:\Users\" part of it.

Anyone up for the challenge?

Code: [Select]:: Delete user profiles older than 30 days
:: Enumerate Each User Profile on the PC used within the last 30 days
:: Copy Desktop files to the user's H: drive
:: Copy IE Favorites to the user's H: drive
:: Copy anything locally in the My Documents folder to the user's H: drive
:: Copy any locally stored .pab and .pst files to the user's H: drive
:: Copy Outlook SIGNATURE file and settings to the user's H: drive
:: Copy Outlook settings file to the user's H: drive

REM Check Windows Version
ver | findstr /i "5\.0\." > nul
IF %ERRORLEVEL% EQU 0 GOTO ver_2kxp
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_2kxp
ver | findstr /i "6\.0\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Vista7
ver | findstr /i "6\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Vista7
goto warn_and_exit

:: This Section Is For Windows 2000 and XP Cleanup
:: Delete user accounts older than 45 days
:: delprof /q /I /d:45
cls

:ver_2kxp

:: variables

:: The following 7 commands enumerate the existing Windows 2000/XP user profiles and copies the data to the user's H: drive (in this case \\CFS002\%USERNAME%)

for /d %%K in ("C:\Documents and Settings\*") do (
Xcopy /e /i /y "%%~fK\Favorites\*" "\\cfs002\%%~fK\Backup"
Xcopy /e /i /y "%%~fK\My Documents\*" "\\cfs002\%%~fK\Backup"
Xcopy /e /i /y "%%~fK\Desktop\*" "\\cfs002\users\%%~fK\Backup"
Xcopy /y "%%~fK\Local Settings\Application Data\Microsoft\Outlook\*.pst" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\Local Settings\Application Data\Microsoft\Outlook\*.pab" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\Local Settings\Application Data\Microsoft\Outlook\*.nk2" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\Local Settings\Application Data\Microsoft\Outlook\*.ost" "\\cfs002\%%~fK\Backup\Outlook Files"
)
pause

:ver_Vista7

:: variables

:: The following 7 commands enumerate the existing Windows Vista/7 user profiles and copy the data to the user's H: drive (in this case \\CFS002\%USERNAME%)

for /d %%K in ("C:\Users\*") do (
Xcopy /e /i /k /y "%%~fK\Favorites\*" "\\cfs002\%%~fK\Favorites\"
Xcopy /e /i /y "%%~fK\My Documents\*" "\\cfs002\%%~fK\Backup\"
Xcopy /e /i /y "%%~fK\Desktop\*" "\\cfs002\%%~fK\Backup\"
Xcopy /y "%%~fK\AppData\Local\Microsoft\Outlook\*.pst" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\AppData\Local\Microsoft\Outlook\*.pab" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\AppData\Local\Microsoft\Outlook\*.nk2" "\\cfs002\%%~fK\Backup\Outlook Files"
Xcopy /y "%%~fK\AppData\Local\Microsoft\Outlook\*.ost" "\\cfs002\%%~fK\Backup\Outlook Files"
)

pause
Try using the file name modifier with the %%K variable. (ie: %%~nK)

The logic flow seems illogical. When :ver_2kxp completes and pauses, it will fall into :ver_Vista7. Either use a goto to skip over the the block of code or use a goto :eof to terminate the script.

[string](0..9|%{[char][int](32+("051073068069087073078068069082").substring(($_*3),3))})-replace "\s{1}\b"

7616.

Solve : I need on screen keyboard load help?

Answer»

I'm working on a project with a graphics INTERFACE, the end product will not have
a connected keyboard. You can go to the run command and type in OSK for the keyboard
(Using XP Pro).

I tried to write a batch file to run when you restart the computer but the batch file keeps
a dos window open the whole time the keyboard is displayed. I can X the box but I don't
want the end product to look LIKE an amateur (me) did the work.

My simple batch file was:
osk
exit

It seems the osk command is ALWAYS open as long as the keyboard is showing on the screen.

Is there a way to do a command add-on (i.e. osk /end) to let the dos box exit?Quote

It seems the osk command is always open as long as the keyboard is showing on the screen.
Is there a way to do a command add-on (i.e. osk /end) to let the dos box exit?
Yes, use the START command
START OSK

To find which options will help you, do this:
START /?
...and get a list of all the options for the start command.So far so good.

Popped it right up. Now I have to find a way to always keep it on top.
The software I'm using and the keyboard don't seem to like sharing the screen.
When the keyboard is up and I roll the mouse to it it drops off the screen, kind of
defeats the purpose for the keyboard!

Thanks for your help.Are you doing a program in a language like Visual Basic or Visual C++ and need the OSK? You may be able to invoke it as a child process. Not sure. Bit in that case, it not LONGER is a DOS thing.
The OSK has its own internal setting for Always on top. Is this set? Seems to work for all the programs I use.IT depends on where I call it from. I am doing a graphics interface that lives in its own world and the two didn't seem to be able to co-exist.

I FOUND if I run the keyboard command in the startup folder for Windows it will do what I need. I just have to create a tag that tells the
operator not to "x" out of the keyboard, just minimize it.

If I call it up from the graphic software it will run but when I cursor over it it drops out.
7617.

Solve : deleting a drive mapping without knowing the drive letter?

Answer»

Hello
Does ANYONE know how I can put a BATCH file together which will delete a particular mapping, eg \\server1\admin\private but where this drive mapping is non-standard so could be e:\ on ONE or p:\ on another?
Thanks
fcNewcastleFor what purpose may i ASK ? ?Code: [Select]for /f "tokens=1-3" %%G in ('net use ^| find "\\server1\admin\private"') do net use %%H /deletehello - many thanks for your responses - I'll try that. It's because a number of our users have mapped the main network drive to different letters. We're now standardising on one particular one which I can set through group policy. But this should allow me to clear their VARIOUS instances.
Thanks
FC

7618.

Solve : batch file lookup table??

Answer»

hi,

I'm not sure the subject accurately describes my scenario, but here's what I'm trying to do...

I have two text files...

file 1 - "plants.csv" has a list with a REFERENCE number

tomatoes,831
peppers,266
squash,595
apples,338
basil,831
eggplant,595

...and so on...

file 2, "months.csv" contains the same reference number, with a description as well.

january,637
february,338
march,484
april,831
may,266
june,595
july,926

With a batch file, how can I make this happen...

New file name "PlantWhen.csv"

tomatoes,831,april
peppers,266,may
squash,595,june
apples,338,february
basil,831,april
eggplant,595,june

The plants and months thing are just an example, what I'm trying to do is a little more complicated, but this is a GOOD representation

thanks in advance...
That is normally don in Excel or a similar program.
Is there a special reason or using a batch file?
Tokens and nested loops. In the outer loop, for each line of plants.csv: split line into two tokens, call them A and B, the DELIMITER being a COMMA. (e.g. A=tomatoes B=831) then read each line of months.csv, again splitting the lines into 2 comma-separated tokens, we'll call them C and D (e.g. C=January D=637). Compare token D to token B and if the same write token A token B Token C as a line to PlantWhen.csv.


Geek-9pm, yeah I'd usually do this in excel or a spreadsheet, but I'm writing a script...the VALUES above don't really mean anything.

Salmon, thanks, I had my if statement in the wrong place, your narrative helped tremendously...here's what worked. one line.

for /F "tokens=1-2 delims=," %%A in (plants.csv) do for /F "tokens=1,2 delims=," %%H in (months.csv) do if %%B == %%I echo %%A,%%B,%%H>>PlantWhen.csv

7619.

Solve : Wallpaper?

Answer»

Is it possible to change an xp WALLPAPER via batch file?Code: [Select]SET TargetFile = Targetfilename
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "%Targetfilename%"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
I added a file and all it does is removes the wallpaper
Code: [Select]SET TargetFile = "C:\Documents and Settings\WAUJOR\Desktop\cat.jpg"
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "%TargetFile%"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 0
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 2
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParametersNo version of windows so far SUPPORTS anything but .bmp and .rle file types as the wallpaper.

When you use the DIALOG and select a png,gif, or jpg image, it converts it to a .bmp file and sets the registry values to the converted file. Since you are setting those values directly, there is no magic conversion.thxis it DIFFERENT on vista or 7

7620.

Solve : Batch script to rename a word in vbs file?

Answer»

I'm trying to write a batch script to rename a certain word ina .vbs file.

BASCIALLY i want it to find this...
'S20120411
change to...
'S20120412

so i want it to find S2012 or 'S2012 what ever easier and change 0411 to 0412 then the next day change 0412 to 0413 and so on for everyday but modifying the vbs file not making a copy. as you can see its the date i was thinking maybe it can use the system date and paste it everyday if its possbile.Seems like it would be easier for the vbscript to just pull the current date.The thing is i have a vbs script thats going to automate through a webpage to download a file. Right now i have everything setup except for finding that file . The file NAME changes everyday to today's date and there no unqiue id for it so i get grab directly.
I was thinking maybe use the following formula for the date in the batch script but i' m not SURE if that would work.

for /f "tokens=1-5 delims=/ " %%d in ("%date%")


i have this CODE right now just need to make some changes..


Code: [SELECT]@echo off
SETLOCAL=ENABLEDELAYEDEXPANSION

rename testfile.txt text.tmp
for /f %%a in (text.tmp) do (
set foo=%%a
if !foo!==ex3 set foo=ex5
echo !foo! >> text.txt)
del text.tmp

7621.

Solve : Batch File Help, using a wildcard(dynamic) directory?

Answer»

Hello! I need to count the NUMBER of files in a directory where one of the layers is dynamic, MEANING C:\level1\level2\{dynamic directory}\error. So, I need to count the amount of files in the error directory and they SAVE it to a text file. There are only 2 directories in the "dynamic" directory.I guess I would do something like this.
Code: [Select]pushd C:\Level1\Level2
for /F "tokens=*" %%G in ('dir /ad /b /s error') do for /f "tokens=1 delims= " %%I in ('dir /a-d %%G ^| find "File(s)"') do echo %%I>errorfilecount.txt

7622.

Solve : Please explain what this code is doing?

Answer»

Quote from: Salmon Trout on April 14, 2012, 11:27:52 AM

1. Check that the variables %driveletter% %wantedfolder% and %backupfilename% expand to what you think they do
2. Check your code much more carefully (it is usually better to copy and paste code, and not to re-type it) This will AVOID wasting other PEOPLES time.

MKDIR "%%driveletter:\%wantedfolder%"
)

MOVE /Y "%backupfilename%" "%driverletter%:\%wantedfolder%\"

3. If you truly WANT to do coding, you need to LEARN (a) to check your own work (b) to be accurate, careful and thorough.
4. If you truly want others to help you, read point (3) again.
5. Read point (3) again.


GOT it...



MKDIR "%driveletter%:\%wantedfolder%"
)

MOVE /Y "%backupfilename%" "%driveletter%:\%wantedfolder%\"



Sorry, I missed the typos... So does it work now, or not?
Yup.
Thanks.
7623.

Solve : How to delete certain lines in a txt file by using bat??

Answer»

I want to delete some lines in a TXT file BU using bat file.

My text file is like this:

<<<To be kept words #1>>>
To be kept words #2

<<<To be deleted words #1>>>
<<To be deleted words #2>>
<To be deleted words #3>
<To be deleted words #4>

To be kept words #3
<To be deleted words #5 >
<To be deleted words #6 >

To be kept words #4>


Can anyone give me some ADVICE? I'm totally NEW for DOS commands. Than you very much in advance.I googled some results. But none of them can be applied for my file, as what I want to delete are lines while others(my google results) are totally words like'cow' or 'cat'.

What I find in google are like this:

@ECHO off
setlocal enabledelayedexpansion

FOR /F "usebackq delims=" %%G IN ("am.txt") DO (
Set "line=%%G" & echo !line:"=!
)>>"am2.txt"

Can anyone give me some suggestions?Lets say we have the following file
Code: [Select]apples are good
oranges are great
coconut is ok
kiwi is green
tomato is read
And I want to remove lines with the words kiwi and oranges in them.
Code: [Select]findstr /v /i /c:"kiwi" /c:"oranges" myfile.txt >newfile.txtNow my new file looks like this.
Code: [Select]apples are good
coconut is ok
tomato is readQuote from: salmon on August 10, 2012, 01:35:24 AM

I want to delete some lines in a txt file bu using bat file.

My text file is like this:

<<<To be kept words #1>>>
To be kept words #2

<<<To be deleted words #1>>>
<<To be deleted words #2>>
<To be deleted words #3>
<To be deleted words #4>

To be kept words #3
<To be deleted words #5 >
<To be deleted words #6 >

To be kept words #4>


Can anyone give me some advice?

Is there a pattern to the lines or text that are being deleted?

Show us a sample of the real text and explain what needs to be removed. We have experience but we need to see the real data, to spot where certain commands can be used.
7624.

Solve : cannot copy outlook.pst to server shared folder?

Answer»

Quote from: Uselesscamper on August 28, 2011, 07:42:15 PM

right...thx.
A noobie mistake but still good advice lol

Welcome Aboard !

Who knows...they may return..... Quote from: desmond on October 16, 2009, 03:09:58 AM
I try to write a script to copy Outlook.pst from my MS outlook2003 to a SERVER shared folder in C drive, but nothing is being copied

My Outlook.pst is under:
C:\Documents and Settings\desmond ang\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst

server name and ip: server, 192.168.1.32
server shared folder is: backup

My script is below. Please help. THANKS


@ECHO OFF
xcopy "%userprofile%\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst" //192.168.1.32/C/backup/

I think there is low space on your server. You should check that the pst file is not oversized. If it has more than 2GB size then you need to split pst files. After you split it in small sizes, you could be able to backup to the server. Don't WORRY about the divided file. All such files can LATER be merged as original file.It generally occurs due to oversized pst file. If your pst file is larger than 2GB, then it may create problem in copying to the server. In such case the file may also get damaged. Therefore, you should first split pst files then try to copy to the server.Stop spamming the Forum...

Topic Closed.
7625.

Solve : List Filenames and Date[SOLVED]?

Answer»

Hey, thanks for reading this

First I WOULD like to introduce the problem in hand.
We have a file repository containing code files (*.sql ; *.xep ; *.dll ; *.aspx ; *.gif) that you are going to submit to Production pretty soon. In this repository we have the main folders which contain the most recent code files to go to PROD, but we also have all the CHANGE Folders that where submitted to PRE-PROD with code. You can see the main repository structure in the image below:



The protocol is that whenever we submit something to PRE-PROD, we e create a Change Folder, place it in the main repository, and also update the main folders, but sometimes we forget to do the second part
What i was trying to do in a automated way is: if there is a file with the same name in the main folder and the change folder they need the have the same modified date day (at least), this specific crossing i could easily do in EXCEL or even SQL.
So, finally , what i needed help in, is getting into a csv fileformat (';' separating values, and '\n' separating rows), all the *.sql ; *.xep ; *.dll ; *.aspx ; *.gif from the main repository directory and sub-directories.

So far I i have tested with this dos commands:

Code: [Select]dir *.sql *.xep *.aspx *.dll *.gif /s /a:-D>listWithDate.txt
this one gets me a list, ie: listWithDate.txt, that a i have FORMATED in this fashion:

Code: [Select]2012/03/19[2sapces]14:27[Nspaces]4.006[1space][filename]
2012/03/19[2sapces]14:27[Nspaces]10.006[1space][filename]
So needed help in on of the two:
.batch to list Filenames and Date to a csv formated file
.or batch to FORMAT the listWithDate.txt into a csv formated file


Many thanks in advance Solved, i just need to open the txt file with excel

7626.

Solve : Command to activate block control panel feature in gpedit.msc?

Answer»

Hi,
I'm looking for a way to ACTIVATE the access block for the control panel that you find in gpedit.msc using CMD. Is this possible? All help would be APPRECIATE, been looking for this for weeks.There are macro programs that record KEYSTROKES and mouse movements, and you can compile the resulting script into an executable.

Is that an option?User Key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

System Key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

Value Name: NoControlPanel
Value Type: Dword
Value Data: 1 (Control Panel disabled) 0 (Control Panel enabled)

Create reg file and use reg.exe to incorporate into registry.

But why not use gpedit.msc?

Thank you for answering, I'll read up on reg files then.
I'm not using gpedit.msc because the whole point of this is that I'm creating a password protected application that will activate and deactivate it. It's for WORK, to stop people from meddling with the computers.if this is for work, you should probably be using the domain group policy anyway...Quote from: TechnoGeek on August 11, 2012, 07:49:54 PM

if this is for work, you should probably be using the domain group policy anyway...

Exactly.
7627.

Solve : Win 7 command prompt Format 2nd Drive Access Denied?

Answer»

Placed this here vs Win 7 since its command prompt.

Trying to format Drive S: in Windows 7 Command Prompt and running into issues. Tried using RUNAS and running into more issues. I am the admin of this system, yet my profile frankenstein doesnt allow for formatting my S: drive without elevated privileges. What am I missing?
Quote

C:\Users\frankenstein>format s: /fs:FAT32
Access Denied as you do not have sufficient privileges.
You have to invoke this utility running in elevated mode.

C:\Users\frankenstein>
Did you try rite clicking command and select "run as admin ? ?

How many Drives/partitions in this PC...
Give us the lay of the land.This is part of my RAMdisk project. The RAMdisk has to be formatted upon every reboot since the formatting is wiped out when the system is shut down. So my plan is to write a batch file that performs a FAT32 Format so that the S: drive is ready to roll when the system is running. This batch file will be called by STARTUP and will perform this format when Windows 7 boots.

This system is my test system with 1 physical hard drive 160GB IDE at C: and a virtual hard drive which is an allocated section of system RAM that is 810MB in size mapped as S: to the OS. Only other drive is DVD-RW as D:

Digging in runas on windows 7 command prompt a google search suggested using an elevated trust level, but i only have 1 as shown below.

C:\Users\frankenstein>runas /showtrustlevels
The following trust levels are available on your system:
0x20000 (Basic User)
C:\Users\frankenstein>http://social.technet.microsoft.com/Forums/en-US/w7itprosecurity/thread/cd82780b-6afa-4404-8515-5d646a5623de/

This link on google doesnt look too good with what i want to do, but there has to be a way to make this work.

Attached are pics of before and after formatting it FAT32. Really hoping to be able to do this at start up vs having to manually format each time I want to use RAMdisk.

[year+ old attachment DELETED by admin]What ramdisk driver are you using, and is it able to do a format on create? The ramdisk driver most likely requires administrative privilege to mount a device object and should be able to format it.AR RAM Disk V1.20 is no longer supported but if it works then the drive is automatically created on each boot.Yes its AR Ramdisk that I'm using. Played with it some and strangely that if the drive created is small in size it keeps its formatting such as a 24MB held the formatting as FAT32 after a reboot, yet 810MB loses its info on SHUTDOWN or reboot. I was impressed that it was written for XP and worked ok on Windows 7 32 bit. Was thinking that if I can Format S: /fs:FAT32 on each boot as part of startup that it would be almost like initializing this space to be clean and ready to roll. If formatting is lost it will ensure that its formatted and ready to be accessed at S:Try the different disk options. Is there an option for NTFS (I don't use a ram disk these days).NTFS not supported as this pic shows it doesnt like NTFS formatting. FAT32 works, but thats probably why i am getting security issue requiring elevated privilages, NTFS would probably allow it more than FAT32 through inherritance if NTFS would work.

[year+ old attachment deleted by admin]AR RAM disk doesn't need formatting - if it's working ok. Maybe it's just not win 7 compatible. Try a different Ram disk.Try sizing it at or below 768MG...Do you have these options selected? The Ram disk option never worked for me.

This is from the XP box...

[year+ old attachment deleted by admin]Found a better solution. Went with different vendor for solution. Went with DataRAM Ramdisk VERSION 4.0.0 and this saves the formatting so no having to reformat each time etc and it has options to save to Hard Drive from Ram before shutdown as well as LOAD from HD to RAM on startup. So no batching required now I guess.

Thanks Everyone for your input on this! Cool Beans...
7628.

Solve : Relative paths in .bat files disappearing??

Answer»

Firstly, hi to everyone, this is my first post. I stumbled here after a rather frustrating Google tiki tour.
Wondering if anyone can help with a batch file issue that I’ve encountered a number of times and has just left me STUMPED. I’m trying to Echo relative paths into another file. I don’t want what the relative path equals just the relative path label.

So here’s an example of what I would put in for the line:
Echo RoboCopy /switches "D:\My Files" "%^userprofile%\My Files" > “D:\My Files\RestoreBackup.cmd”

It works perfectly if I type it into a cmd window:
RoboCopy /switches "D:\My Files" "%userprofile%\My Files"
This line is EXACTLY what I want to appear in the target file!

But as soon as I put it into a .bat or .cmd file I get this:
RoboCopy /switches "D:\My Files" "\My Files"

If I remove the ^ then I get this:
RoboCopy /switches "D:\My Files" "C:\Users\Admin\My Files"

This certainly isn’t the only situation where this DISCREPANCY between cmd line and batch file result has affected me. If anyone can shed some light it’ll really help me out now and in the future. ALSO if you could travel back in time and tell me years ago you could save me countless hours

I appreciate your help

Thankyou
You appear to appreciate that percent signs are special characters in batches and have to be "escaped". The escape character for a percent sign is another percent sign (not a caret). In other words in a batch when this line is executed:

echo %username%

... the result is that %username% is replaced by the variable's value. This is by design.

If you want to echo a percent sign then the variable name then another percent sign use this

echo %%username%%


Thank you so so much! I really can't properly express my gratitude for your help.

I spent so much time looking through walls of text but that worked like a charm.

Thank you so much!Most other special characters use a caret

e.g.
command:
dir > temp.txt
dir *.jpg | find "Mother"
dir *.jpg & echo. & echo Done

batch:
dir ^> temp.txt > script.bat
dir *.jpg ^| find "Mother" > script.bat
dir *.jpg ^& echo. ^& echo Done > script.bat

Note: unlike percent signs, the exclamation marks used with delayed EXPANSION variables cannot be escaped simply by doubling. Use two carets thus ^^!

Useful reference page

http://www.robvanderwoude.com/escapechars.php



Cool. I've never ACTUALLY used the & and | symbols in batch files before. I knew about the carrot tho.

Thanks for the pointers, I'll have to play around with those. I'm constantly writing batch files, mostly for my backups and also for mounting ramdisks and creating temporary junction points to folder locations so my games load faster

7629.

Solve : Viewing/showing special characters/computer language - how to??

Answer»

I'm playing around with MS-Dos in a VMware Player virtual machine, I have a "for dummies" book, "DOS" and I'm looking for where this book tells me what commands to type if I'd like to see the computer language characters, such as the omega, alpha symbols, a heart symbol (on white playing-card like background), etc, but I cannot find this anywhere in this book. I even tried searching online but couldn't find anything - COULD you PLEASE help me?

Thanks in advance.if all you wish to do is to show it, then this will do
Code: [Select]echo Ωopen charmap, select the character you want to use, copy it then paste it into the DOS windowYou are most likely to be after the ascii table.

http://www.google.com.au/search?hl=en&q=ascii+character+set&btnG=Google+Search

To get an ascii character at the MSDOS prompt and in MSDOS editors then hold down ALT and type the three digit number of the ascii value on the number pad and release ALTI wanted these ascii CODES to show up in like, several ROWS in white against a blue background, the way someone showed me once about 20 years ago on a Dos machine - how to I get DOS to do this?This is a Qbasic script so save it as char.bas and run it with

qbasic /run char.bas

Code: [Select]COLOR 15, 1
FOR c = 1 TO 255
PRINT CHR$(c); " ";
NEXT
Foxidrive,
Didn't we TALK about this on dostips a few months back?
Thought I remember someone posting a Debug script that would list all the characters to the screen.I don't recall. Maybe debug was used to dump the character set from rom in the BIOS.

7630.

Solve : ren command with wild cards?

Answer»

I am trying to rename multiple files in a folder, APPENDING a text to the end of each filename. for example, I am using the following ren command to rename 4 files, but it only renames 2 files correctly, says :"A duplicate file name exists" error for the 1 file:

command: ren *.* *_new.*

SalesDigest_Natl_Trad.pdf
SalesDigest_Natl.pdf
SalesDigest_Atlanta_Reg.pdf
SalesDigest_Atlanta.pdfFile names in the folder: ->


File names after executing the command:->
SalesDigest_new.pdf
SalesDigest_Natl_new.pdf
SalesDigest_Natl.pdf
SalesDigest_Atlanta_new.pdf


As you can see, the results are not as expected. I know there are issues with using ren with wild cards. Any suggestions?

My ultimate goal is to append a timestamp to the end of each file in the folder, for which I am using the following command:
ren *.* *_%date:~7,2%%date:~10,4%.*Code: [Select]@echo off
SET var=_%date:~7,2%%date:~10,4%
for /f "delims=" %%a in ('dir *.pdf /b') do ren "%%a" "%%~na%var%%%~xa"Thank you foxidrive!

This is excatly what I was looking for.

Thanks,
MaxxJust out of curiosity, why does the single line rename command (in my first post) mess up the file names? Thanks!

Btw, below is my final batch file which will rename all the files under a folder except the sub DIRECTORIES.

==============================================================
@echo off
REM This batch file appends the files under the Monthly_Sales folder with date in YYYYMM format
cd Monthly_Sales
if %errorlevel% neq 0 exit /b %errorlevel%
set var=_%date:~10,4%%date:~4,2%
for /f "delims=" %%a in ('dir *.* /b/A:-D') do ren "%%a" "%%~na%var%%%~xa"
cd ..
==============================================================
Quote from: maxxcontractor on September 25, 2012, 03:00:02 PM

Just out of curiosity, why does the single line rename command (in my first post) mess up the file names? Thanks!

The wildcard you used results in two files getting the same new name, so the second one causes an error, and is skipped.

Study these and you will see how the wildcard works

1. SalesDigest_Atlanta.pdf becomes SalesDigest_new.pdf
2. SalesDigest_Atlanta_Reg.pdf becomes SalesDigest_Atlanta_new.pdf
3. SalesDigest_Natl.pdf becomes SalesDigest_new.pdf (this already exists because it was used at step 1)
4. SalesDigest_Natl_Trad.pdf becomes SalesDigest_Natl_new.pdf

The syntax is ren [Drive:][PATH] filename1 filename2. You can use wildcards (* and ?) in either file name parameter. If you use wildcards in filename2, the characters represented by the wildcards will be identical to the corresponding characters in filename1.





Expanding slightly, the syntax is ren file1 file2.

In your ren command:

file1 is *.* which means 'process every file'.

file2 is *_new.* which is the specification for the new name and is interpreted as "everything in the original name up to the last underscore, followed by _new. followed by everything after the last dot in the original name"

This means that these two original file names would get the same new name.

SalesDigest_Atlanta.pdf - > SalesDigest_new.pdf
SalesDigest_Natl.pdf -> SalesDigest_new.pdf

The original name that sorts earliest is processed first, and gets the new name. The second one causes a name collision and is skipped with this error message sent to the console:

C:\>ren *.* *_new.*
A duplicate file name exists, or the file
cannot be found.

If anyone is interested, there is a good summary on Superuser

http://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards
7631.

Solve : Merge CSV files then paste into a column in the master sheet?

Answer»

Hi,
I use a simple batch file to copy all csv's in a folder and merge them into one master csv file. We then open this in excel to check productivity. I know this would be much easier to write in VB on excel, but i was curious if a batch file could do this. Basicaly, I want to know if I could have a portion of the file name placed into the last column of the csv file. For example:

Copy "directory\path\*.csv" "directory\path\All_Csv"
then possibly
like a where statement (since it is a UNC on windows 7)
net use V: \\server\path
where "\\server\path:*.csv*" > results.txt or pipe to the clipboard i suppose
then somehow copy the results of the txt file
and place them in the last or first column on csv file

However, these files contain 50 to 100s of lines each, so i would want the file name to replicated on the file it goes with

I am really interested in being able to copy the results of a where statement or results of any command without physically using the mouse.

Thanks,I am not fully understanding what your input is and what your intended output is.
Could you give us an example of what two of the input files LOOKS like and then an example of what the outfile needs to look like.

file1
Code: [Select]apple,8123
orange,9123file2
Code: [Select]beans,2324
peas,234243Output
Code: [Select]apple,8123,?????
orange,9123,?????
beans,2324,?????
peas,234243,?????Squash,
Ill explain the process. These csv files are extracts out of xls sheets that my team works. These extracts get picked up in a nightly process and inserted in SQL tables that load into databases. All csv files go from Column A to Column DD in excel. We were wanting to combine the files in order to create a quick pivot table to check productivity for quick results on certain occasions. All files have the same column headers given in below in File1 and the details of course correspondence in the same sequence. They are named in the following way Work_Client_UserNameAndCompany_Date-1741.csv. Basically what I want to do is ADD the whole file name and/or just the UserName in column DF of the report, or the last column the notepad code given below. So there would be a header added to the end of this file called File_Name and then under it following the logic it would provide the file name.

File1:
Code: [Select][PRACTICE,DATA-BASE,CHARGE STATUS,CURR PST,CURR PIWC,AGING WEEKS,AGING BUCKET,ACCT,PatAltID,CHARGE,DOS,CHG POST DATE,POS,DEPT,CHG REF PROV CODE,CHG PROV CODE,CHG ORD PROV CODE,CURR INSR CODE,CUR INS POLICY NUMBER,CUR INS GROUP NUMBER,CUR INS REL CODE,PMT CODE,MAPPED PMT MSG 1,MAPPED PMT MSG 2,MAPPED PMT MSG 3,MAPPED PMT MSG 4,PMT INS PAID CODE,PROC CODE,MOD 1,MOD 2,CHG UNITS,DX Code 1,DX Code 2,DX Code 3,DX Code 4,OWED AMOUNT,DOS TOTAL,ACCT,CHARGE,CTRL GROUP NUMBER ,PAY / ADJ CODE,NEXT PAYR INS CODE,NEXT PAYR PIWC,PRNT CLM,MSG 1,MSG 2,MSG 3,MSG 4,CHECK NUMBER,BANK ABA NUMBER,ACTION / NOTES,STATUS,DATE WORKED,AGING DATE,PMT POST DATE,PMT DATE,PMT AMOUNT,PMT CODE DUP,PMT MSG 1,PMT MSG 2,PMT MSG 3,PMT MSG 4,Pmt ABA,PMT CTRL GRP,PAT FIRST NAME,PAT LAST NAME,PAT DOB,ACCOUNT INSURANCE TOTAL,CHARGE BILLED AMT,CHARGE PAID AMT,CHARGE ADJ AMT,REF PLUS CHG REF AUTH NO,CUR INS PRI PREAUTH,CHG INS SET,CHG INS HIST,DFLT INS SET,DFLT INS HIST,SET ERROR,LAST CLAIM DATE,PRI CLAIMS,SEC CLAIMS,TER CLAIMS,CLAIM DELAY,CLAIM GROUP,AGE DAYS,CHG CUR INS CODE,CHG PRI INS CODE,CHG SEC INS CODE,CHG TER INS CODE,CUR INS NAME,CUR PIWC,CUR INS TYPE,CUR INS CLASS,PRI INS NAME,PRI PIWC,PRI INS TYPE,PRI INS CLASS,SEC INS NAME,SEC PIWC,SEC INS TYPE,SEC INS CLASS,TER INS NAME,TER PIWC,TER INS TYPE,TER INS CLASS,ANALYST,KEY,REPT DATE]Squashman might have a better way to do it but here's mine: it creates newfile.csv

Code: [Select]@echo off
for %%a in (*.csv) do set /p var=<"%%a">nul & goto :next
:next
>newfile.tmp echo %var%,File_Name
for %%a in (*.csv) do (
for /f "skip=1 delims=" %%b in ('type "%%a"') do (
>> newfile.tmp echo %%b,%%a
)
)
move /y newfile.tmp newfile.csv >nulAll I really wanted was a small example like I described in my first post. I am a visual person. I need to see the input and see what you want the output to look like.
I think Foxidrive has you covered.Sorry sqush I am new to this form, ill consider shortening my example in future questions. The code fox gave me works perfectly. It does delete the headers in the file, but not a biggie i can always grab the headers from a different file and paste them into the first row.

I really appreciate you both HELPING me with this.

Thanks,Quote from: codemonkey on August 11, 2012, 11:26:52 PM

The code fox gave me works perfectly. It does delete the headers in the file, but not a biggie i can always grab the headers from a different file and paste them into the first row.

It is supposed to create the headers for the new csv file, but remove all the headers of the individual files.

If you want to keep the headers for all the individual files then remove skip=1

I also note now that the headers you have are too long for the set /p command.

Try this:

Code: [Select]@echo off
for /f "delims=" %%a in ('dir /b *.csv') do (
for /f "delims=" %%b in ('type "%%a"') do (
>newfile.tmp echo %%b,File_Name
goto :next
)
)
:next
for %%a in (*.csv) do (
for /f "skip=1 delims=" %%b in ('type "%%a"') do (
>> newfile.tmp echo %%b,%%a
)
)
move /y newfile.tmp newfile.csv >nul
7632.

Solve : Working of DOS?

Answer»

Hi guys, i want to know how that the DOS and its commands are working. I mean CONSIDER a command md which makes a directory. In here what process in going . How DOS creates directory etc ... Like this For all commands i need explanation Your QUESTION is a little vague - and to explain the operation of the cmd prompt could take hundreds of pages.

If you have specific questions then it's probably better if you ask them - or else we don't know how much info to offer and at what level.from what I understand cmd.exe simply opens exe's in system 32 and inputs certain parameters based on the /'s, -'s or |'s into that exe. I would assume these exe's are written in c++ but they could be just as easily made in any language (I wrote one in batch and converted it and it runs just like it's own command)No.
The original DOS was written in assembly.ms-dos (and win3.1, win95, win98, win ME) used the command interpreter, called command.com, which processed certain file-related commands. more advanced commands and 3rd party programs were separate .com or .exe files, which were executed by the command interpreter. cmd.exe is a bit of a 'modern' command.com, which actually USES the standard WINDOWS API to run commands. when you type the md command, cmd.exe directly executes a CreateFile API call. some commands, as previously in ms-dos, are executed by external programs (such as xcopy). It would be pointless to find out how every command is executed because there are many of them, and some of the processes are changed by command-line switches you pass to them. An explanation of WHY you need this information would possibly help us find a better resource for you.If the OP has already stated study of C++ or C#, he would do well to pursue his study. IMHO.
DOS is history. If .you want to learn history -
read the book "Windows 95".Quote from: Geek-9pm on August 11, 2012, 09:11:45 PM

If the OP has already stated study of C++ or C#, he would do well to pursue his study. IMHO.
DOS is history.
(...)

The OP has stated study of C++/C#?

I guess what I was really getting at was, if he needs to actually know how DOS worked to program something similar, that's one thing. KNOWING how 'DOS' (aka the command-prompt-that-people-think-is-dos-but-isn't) now works is something that is already indirectly covered in many programming tutorials (how to create folders, copy files, get directory listings, etc.) That's why I asked for what purpose he is researching this....and I don't think the OP is going to return either. 6 days, a number of posts, and no reply...
7633.

Solve : Batch File to Convert Txt files?

Answer»

Hi,
I am trying to convert data in a text file to a delimiter format to open in excel.

Below is a SAMPLE code of what I want to do:

Text file comes like below (Always a first word with ":" and then information regarding it next
Code: [Select]
Apple: 1234
Orange: Jon THOMAS
Pear: He was walking down the street

What I want the new txt or csv file to LOOK like in excel (The pipes are just used for reference as columns)
Code: [Select]
Apple | Orange | Pear |
1234 | Jon Thomas| He was walking down the street|

I was trying to use a For F/ delims command that I used to merge CSV files however I could not figure it out.

Thanks,This will give you a .CSV for to open in excel. Line length becomes important if the files are large.

Code: [Select]@echo off
setlocal EnableExtensions EnableDelayedExpansion
for /f "tokens=1,* delims=: " %%a in (file.txt) do (
set "var=!var!,%%a"
set "var2=!var2!,%%b"
)
>file.csv echo %var:~1%
>>file.csv echo %var2:~1%
Here's another way to do it which handles larger files - though there is a LEADING comma on each line.

Code: [Select]@echo off
for /f "tokens=1,* delims=: " %%a in (file.txt) do (
set /p "=,%%a">>filea.tmp <nul
set /p "=,%%b">>fileb.tmp <nul
)
echo.>>filea.tmp

copy /b filea.tmp+fileb.tmp file.csv
del filea.tmp
del fileb.tmpFox,
Thank you for the help. This is actually exactly what I was looking for.Small change to fix the leading comma.
Code: [Select]@echo off
setlocal enabledelayedexpansion
set comma=
for /f "tokens=1,* delims=: " %%a in (file.txt) do (
set /p "=!comma!%%a">>filea.tmp <nul
set /p "=!comma!%%b">>fileb.tmp <nul
set comma=,
)
echo.>>filea.tmp

copy /b filea.tmp+fileb.tmp file.csv
del filea.tmp
del fileb.tmpQuote from: Squashman on September 28, 2012, 09:58:52 AM

Small change to fix the leading comma.

Good thinking.
7634.

Solve : cmd line command and Unicode?

Answer»

Hi, I'm trying to obtain text files in Unicode format, via the command:

cmd /u /c type myfile.txt>myunicodefile.txt

as suggested here:
http://www.dostips.com/?t=Snippets.AnsiToUnicode

I also gave a look to the cmd specifications.

I have to do that to several files, so I call that from a script (written in Scilab).
The file is CREATED in Unicode, but i find that the "è" character and similar are translated in others.
Is there a way to obtain the file with the "è" not changed?

thank you very muchtry setting codepage 1252
Any hint about how to do that? I'm just going crazy

Or... let's change strategy:
when I use that cmd command line, in my Unicode output file i find the "è" changed in "Þ", the thorn character (can you see it?).
I think that if I change the "è" in the ANSI input file, with another character, i could find it changed back in "è" in the Unicode output file. But with what character do I have to replace the "è"?

Many THANKS Found! "Š"
Quote from: mauro012345 on May 15, 2012, 01:55:10 AM

Any hint about how to do that? I'm just going crazy

Google "cmd change code page", but I'll tell you if you don't know how to do that.

chcp 1252
Quote from: mauro012345 on May 14, 2012, 08:19:11 AM
Hi, I'm trying to obtain text files in Unicode format, via the command:

cmd /u /c type myfile.txt>myunicodefile.txt

as suggested here:
http://www.dostips.com/?t=Snippets.AnsiToUnicode

I also gave a look to the cmd specifications.

I have to do that to several files, so I call that from a script (written in Scilab).
The file is created in Unicode, but i find that the "è" character and similar are translated in others.
Is there a way to obtain the file with the "è" not changed?

thank you very much
So you used a tip from the dostips.com website but then came here asking how to use it? Why didn't you just post on the dostips.com forums?Quote from: Squashman on May 15, 2012, 03:51:20 PM
So you used a tip from the dostips.com website but then came here asking how to use it? Why didn't you just post on the dostips.com forums?
Didn't know they have a forum

Anyway my SOLUTION didn't work as I expected. In fact, I had to start from UTF-8 and reach the Unicode format and that's not so easy! This "è" is driving me crazy...
I'll give a look to the Salmon hint, thanks.Quote from: mauro012345 on May 17, 2012, 08:34:32 AM
Didn't know they have a forum

Anyway my solution didn't work as I expected. In fact, I had to start from UTF-8 and reach the Unicode format and that's not so easy! This "è" is driving me crazy...
I'll give a look to the Salmon hint, thanks.
Click the link you posted and SCROLL down!lol... there is forum there!
7635.

Solve : To be, or not to be, that is the question !!?

Answer»

hi
i have a problem with my batch script
i WANT to DIR and check to see if these files are exist or not
Quote

myflash.rar source.fla newfile.swf movie.flv *.reg
if they are exist (mostly in source folder) go to finish and end but if there are not at least one of those files exist MOVE everything from source folder to extra folder

important=
1-its not Necessary for existence of all of those files at the same time
2-but at least one of those should be in source folder
3-if there were not at lease one of those files move everything from source folder to extra folder

my script is here but i dont know why its not working and how should i fix it

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s myflash.rar source.fla newfile.swf movie.flv *.reg') do (
IF EXIST %%a GOTO finish
IF NOT EXIST %%a GOTO nofile

:nofile
move "source\*.*" "extra"
:finish
:end
)
This just looks like what you were trying to do in your previous thread. Why didn't you keep POSTING in that one?TOPIC Closed.

See your other thread for replies.
7636.

Solve : if here are more than (..) file?

Answer»

hi
i have a problem
i want to DIR from current folder to see if there are more than 6 .swf files and if there are more program should go to END AND CLOSE but if there are less than 6 .swf files check the second file types ( flv and jpg)
if there is any amount of these files program should do 2 job
1- make a COPY of them to d:\files
2-go to second step(step 5)
thanks I always like PEOPLE to at least make an attempt at starting a script. So I will at least give you an idea on how to start it.
Code: [Select]for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
do the rest of your stuff here
)dear Squashman
thanks for the reply

before starting this topic i tried my best ! and cuz i am beginner so there was no hope !
i tried below script to count how many swf files exited in the current folder
Quote

dir "*.swf" | find /i "file"

and it worked but below script is not working i dont know why

Quote
for /f "tokens=1 delims= " %%a in ('dir *.swf ^| find "File(s)"') do set var=%%a
if %var% lss 6 goto step2
if %var% more 6 goto step3

:step2
for /f "tokens=1 delims= " %%G in ('dir *.jpg *.flv ^| findstr /R /C:"File(s) ') do (
xcopy %%G d:\files /s /i

:step3
:end
I gave you the code for when it is greater than 6 and the code for the FOR loop. You have refused to use both. Why?

There is no such thing as a MORE compare operator.
Open up a command prompt and type: if /?
dear Squashman
its too complicated for me ! CANT you do the rest believe it or not if i could figure it out myself i would have done that

and something elas i tried this script and it did nothing why ?
there were just 2 swf files !!
Quote
for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
IF %%G LSS 6 GOTO :step2
)
::step2
echo= > comments.txt
pause
:EOF
:end
please helpYou don't need a :EOF label to go to. GOTO :EOF is the same as using the exit command.
Your goto for step 2 does not work because your label has 2 colons in front of it.ok now i tried this one and it worked but it looks ugly to me can someone make it better or fix the problems?
working script
Quote
for /f "tokens=1 delims= " %%G in ('dir *.swf ^| findstr /R /C:"File(s) .* bytes$"') do (
IF %%G GTR 6 GOTO :EOF
IF %%G LSS 6 GOTO :step2
)
:step2
IF EXIST *.jpg IF EXIST *.flv GOTO step3
IF not EXIST *.jpg IF not EXIST *.flv GOTO EOF
:step3
xcopy *.jpg d:\files
xcopy *.flv d:\files
pause
:EOF
:end

problems=
1-if some ( jpg or flv ) files are exited in sub-directories they cant be find or copy
2- script is not sharp enough and is not working exactly(SOMETIMES good sometimes bad !)ok my other topic closed so i came here
but to me its a different question !!
====================
here is my topic please read it and if you can help

hi
i have a problem with my batch script
i want to DIR and check to see if these files are exist or not


Quote
myflash.rar source.fla newfile.swf movie.flv *.reg

if they are exist (mostly in source folder) go to finish and end but if there are not at least one of those files exist move everything from source folder to extra folder

important=
1-its not Necessary for existence of all of those files at the same time
2-but at least one of those should be in source folder
3-if there were not at lease one of those files move everything from source folder to extra folder

my script is here but i dont know why its not working and how should i fix it

Quote

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s myflash.rar source.fla newfile.swf movie.flv *.reg') do (
IF EXIST %%a GOTO finish
IF NOT EXIST %%a GOTO nofile

:nofile
move "source\*.*" "extra"
:finish
:end
)
1) You need to use the /B switch with the DIR command
2) don't use a space as a delimiter.
3) move your closing parenthesis after your IF statements.
4) You should put quotes around your variable names when dealing with file names and directory paths.dear Squashman
i tried what you said or at least what i got from your answer but it didn't worked
Quote
1) You need to use the /B switch with the DIR command
you man dir/s/B i tried this one too dir/B

Quote
2) don't use a space as a delimiter.
where? you mean space in line 4 in my previous post? i removed it !
Quote
3) move your closing parenthesis after your IF statements.
which one? the one in line 2 or 9 ? if i remove parenthesis in line 9 ) it wont be able to run it !

4) You should put quotes around your variable names when dealing with file names and directory paths.
i hope you mean names in line 2 . right? i put quotes around them
"myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"

my final batch is below and it still is not working . i don't know which part is missing !

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s/B "myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"') do (
IF EXIST %%a GOTO finish
IF NOT EXIST %%a GOTO nofile
)
:nofile
move "source\*.*" "extra"
:finish
:end

1) In regards to using DIR /B /S. Do you understand why you need to use both of those switches. Just type DIR /S at a cmd prompt, then type DIR /B /S and you should see why.
2) NO! You are using a Space as a delimiter in your FOR LOOP! Either close up the space or get rid of the delims option all together.
3) Of course the last one. You need to end the code block in the correct spot. I didn't say REMOVE it. I said move it after your IF statements.
4) No! Those file names don't have any spaces in them. If they did you would need quotes. I specifically said VARIABLES! What do you think is going to happen to your IF EXIST test if their is a space in the directory path.Quote
1) In regards to using DIR /B /S. Do you understand why you need to use both of those switches. Just type DIR /S at a cmd prompt, then type DIR /B /S and you should see why.

i just wanted my bat to SEARCH and look into sub-directories too !

Quote
3) Of course the last one. You need to end the code block in the correct spot. I didn't say REMOVE it. I said move it after your IF statements
.

brilliant my friend you are truly a master
it worked like a charm
Quote
4) No! Those file names don't have any spaces in them. If they did you would need quotes. I specifically said VARIABLES! What do you think is going to happen to your IF EXIST test if their is a space in the directory path.
i think error was not because of those file names i didn't change them and it solved
just that bad parenthesis )
and something else= i replaced line 3 with 4 and it solved !!
my final working script is below
thanks dear master Squashman

Quote
@echo off & setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/s/B "myflash.rar" "source.fla" "newfile.swf" "movie.flv" "*.reg"') do (
IF NOT EXIST %%a GOTO nofile
IF EXIST %%a GOTO finish
)
:nofile
move "source\*.*" "extra"
:finish
:end
Well I hope your paths don't have spaces in them because it won't work if it does.
7637.

Solve : cmd?

Answer»

Hi,

I am hard to use cmd for Dos. could ANYONE know to use cmd ? Quote from: Lao Kuy on MAY 17, 2012, 03:49:35 AM

Hi,

I am hard to use cmd for Dos. could anyone know to use cmd ?
To do what?See a list of CMD options with the following:
Select START, select Run type in
CMD /?
then press enter and a DOS box will open with help information.
Does that help?

7638.

Solve : Deleting Files Based on File Name?

Answer»

I am trying to create a batch file to delete all files in a directory (including subdirectories) in which the 5th and 6th characters in the file name are equal to "09". The file names are based on a date code and I want to delete files based on certain dates. If someone could point me in the right direction it would be GREATLY appreciated.This can be done in a FOR LOOP.
You can make a filter based non the DIR command. Or you can make some other kind of filter.

But may I ask why you need to delete the files? Why not just move them to an archive? Surly they must still have some value.

Simple answers:
This is a simple filter for DIR
Code: [Select]DIR ???09*.*Here is a delete filter
Code: [Select]DEL ???09*.*Files DELETED this way night never be n recovered.
Quote from: Hopenhower on May 16, 2012, 12:43:53 PM

I am trying to create a batch file to delete all files in a directory (including subdirectories) in which the 5th and 6th characters in the file name are equal to "09". The file names are based on a date code and I want to delete files based on certain dates. If someone could point me in the right direction it would be greatly appreciated.
Code: [Select]del ????09*.* /s
Thank you BC. It was much to complex for me. He used numbers instead of pictures. I am not good with numbers.Well that was easy! Thanks both of you for your help. I wasn't aware of the ? placeholder. I was thinking more of a couple If Then statements that used DOS's version of Mid String (if such a thing exists). I was making it way harder than it needed to be.
I am not permanently DELETING the files by the way. Before running this I am making a copy of all of the files, then just going into the copy and deleting specific files. Then going into the ORIGINAL copy and deleting the other ones. I'm sure this can all be done in a single batch file, but I only need to do it once.
Thanks!I would suggest that a filter be applied to make the files hidden. Most program will not include hidden files in a precess of preparing a report. If that is what you want.Quote from: Geek-9pm on May 17, 2012, 01:38:09 PM
I would suggest that a filter be applied to make the files hidden. Most program will not include hidden files in a precess of preparing a report. If that is what you want.
I don't recall the user requesting to do anything with hidden files.
7639.

Solve : need cmds for startup?

Answer»

My system crashed after a windows update. I tried RESTORING it but it did not help. The function keys don't work only command prompt under S-DOS; and it has been many years since I remembered the command codes. Am I screwed or what?
C:\test>help
For more information on a specific command, type HELP command-name
ASSOC Displays or modifies file extension associations.
ATTRIB Displays or changes file attributes.
BREAK Sets or clears extended CTRL+C checking.
BCDEDIT Sets properties in boot database to control boot loading.
CACLS Displays or modifies access control lists (ACLs) of files.
CALL Calls one batch program from another.
CD Displays the name of or changes the current directory.
CHCP Displays or sets the active code page number.
CHDIR Displays the name of or changes the current directory.
CHKDSK Checks a disk and displays a status report.
CHKNTFS Displays or modifies the checking of disk at boot time.
CLS Clears the screen.
CMD Starts a new instance of the Windows command interpreter.
COLOR Sets the default console foreground and background colors.
COMP Compares the contents of two files or sets of files.
COMPACT Displays or alters the compression of files on NTFS partitions.
CONVERT Converts FAT volumes to NTFS. You cannot convert the
current drive.
COPY Copies one or more files to another location.
DATE Displays or sets the date.
DEL Deletes one or more files.
DIR Displays a list of files and subdirectories in a directory.
DISKCOMP Compares the contents of two floppy disks.
DISKCOPY Copies the contents of one floppy disk to another.
DISKPART Displays or configures Disk Partition properties.
DOSKEY Edits command lines, recalls Windows commands, and
creates macros.
DRIVERQUERY Displays current device driver status and properties.
ECHO Displays messages, or turns command echoing on or off.
ENDLOCAL Ends localization of environment changes in a batch file.
ERASE Deletes one or more files.
EXIT Quits the CMD.EXE program (command interpreter).
FC Compares two files or sets of files, and displays the
differences between them.
FIND Searches for a text string in a file or files.
FINDSTR Searches for strings in files.
FOR Runs a specified command for each file in a set of files.
FORMAT Formats a disk for use with Windows.
FSUTIL Displays or configures the file system properties.
FTYPE Displays or modifies file types used in file extension
associations.
GOTO Directs the Windows command interpreter to a labeled line in
a batch program.
GPRESULT Displays Group Policy information for machine or user.
GRAFTABL Enables Windows to display an extended character set in
graphics mode.
HELP Provides Help information for Windows commands.
ICACLS Display, modify, backup, or restore ACLs for files and
directories.
IF Performs conditional processing in batch programs.
LABEL Creates, changes, or deletes the volume label of a disk.
MD Creates a directory.
MKDIR Creates a directory.
MKLINK Creates Symbolic Links and Hard Links
MODE Configures a system device.
MORE Displays output one screen at a time.
MOVE Moves one or more files from one directory to another
directory.
OPENFILES Displays files opened by remote users for a file share.
PATH Displays or sets a search path for executable files.
PAUSE Suspends processing of a batch file and displays a message.
POPD Restores the previous value of the current directory saved by
PUSHD.
PRINT Prints a text file.
PROMPT Changes the Windows command prompt.
PUSHD Saves the current directory then changes it.
RD Removes a directory.
RECOVER Recovers READABLE information from a bad or defective disk.
REM Records comments (remarks) in batch files or CONFIG.SYS.
REN Renames a file or files.
RENAME Renames a file or files.
REPLACE Replaces files.
RMDIR Removes a directory.
ROBOCOPY Advanced utility to copy files and directory trees
SET Displays, sets, or removes Windows environment variables.
SETLOCAL Begins localization of environment changes in a batch file.
SC Displays or configures services (background processes).
SCHTASKS Schedules commands and programs to run on a computer.
SHIFT Shifts the position of replaceable parameters in batch files.
SHUTDOWN Allows proper local or remote shutdown of machine.
SORT Sorts input.
START Starts a separate window to run a specified program or command.
SUBST Associates a path with a drive letter.
SYSTEMINFO Displays machine specific properties and configuration.
TASKLIST Displays all currently running tasks including services.
TASKKILL Kill or stop a running process or application.
TIME Displays or sets the system time.
TITLE Sets the window title for a CMD.EXE session.
TREE Graphically displays the directory structure of a drive or
path.
TYPE Displays the contents of a text file.
VER Displays the Windows version.
VERIFY Tells Windows whether to verify that your files are written
correctly to a disk.
VOL Displays a disk volume label and serial number.
XCOPY Copies files and directory trees.
WMIC Displays WMI information inside interactive command shell.

For more information on tools see the command-line reference in the online help.

C:\test>

C:\test>cd /?
Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]

.. Specifies that you want to change to the parent directory.

Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.

Use the /D switch to change current drive in addition to changing current
directory for a drive.

If Command Extensions are enabled CHDIR changes as follows:

The current directory string is converted to use the same case as
the on disk names. So CD C:\TEMP would actually set the current
directory to C:\Temp if that is the case on disk.

CHDIR command does not treat spaces as delimiters, so it is possible to
CD into a subdirectory name that contains a space without surrounding
the name with quotes. For example:

cd \winnt\profiles\username\programs\start menu

is the same as:

cd "\winnt\profiles\username\programs\start menu"

which is what you would have to type if extensions were disabled.

C:\test>
C:\Windows\system32\rstrui.exe

or

unplug from wall and rebootHi Bill...Quote from: patio on April 17, 2012, 12:10:59 PM

Hi Bill...

Who is Bill? My name is Dean Stone.Quote from: DeanStone77 on April 17, 2012, 01:00:11 PM
Who is Bill? My name is Dean Stone.

Classic
taken care ofQuote from: Salmon Trout on April 17, 2012, 01:17:21 PM
Classic

7640.

Solve : Create Batch file to change name of specific file?

Answer»

How can I change the name of a specific FILENAME (INFORMddmmyyyy.csv). The file will have a different date each day

""""SET filename= "INFORM%dd%%mm%%yyyy%.csv"""""""?
Code: [Select]@Echo Off
SET dd=%date:~0,2%
SET mm=%date:~3,2%
SET yy=%date:~8,2%
SET yyyy=%date:~8,4%
SET ndate=%dd%%mm%%yy%

SET filename= "INFORM%dd%%mm%%yyyy%.csv"

@For /F "tokens=1,2,3 delims=: " %%A in ('Time /t') do @(
Set Hour=%%A
Set Min=%%B
Set Allm=%%A%%B
)


ren %filename% OUTFORM%ndate%%Allm%.csv

Quote from: petreli on April 18, 2012, 09:20:42 AM

""""SET filename= "INFORM%dd%%mm%%yyyy%.csv"""""""?

The space is a real character, so that filename will resolve to a file file name with a leading space. This SEEMS to be BETTER:

Code: [Select]SET filename=INFORM%dd%%mm%%yyyy%.csv

If it turns out that filename has embedded spaces or other special characters, use the quotes on the output side:

Code: [Select]ren "%filename%" "OUTFORM%ndate%%Allm%.csv"

Hope this helps, not really sure what the question is.

HI

Thanks for the reply, I RECEIVED "The system cannot find the file specified"

I changed the Set File name to the exact filename without the date varibles. It has worked I guess its the date varibles I need to look at now.

Do I have SET yyyy=%date:~8,4% set correctly? year format needs to be yyyy

What I am trying to do in this case is rename a specified filename. The fileaname will change from day to day with the date at endHi

Got it sorted, may not be tidy but does the job.

Code: [Select]@Echo Off
for /F "tokens=1-4 delims=/ " %%A in ('date/t') do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)

SET dd=%date:~0,2%
SET mm=%date:~3,2%
SET yy=%date:~8,2%



SET ndate=%dd%%mm%%yy%
SET fulldate=%dd%%mm%%yyyy%


SET filename=INForm%dd%%mm%%DateYear%.csv

@For /F "tokens=1,2,3 delims=: " %%A in ('Time /t') do @(
Set Hour=%%A
Set Min=%%B
Set Allm=%%A%%B
)


ren %filename% OUTFORM%ndate%%Allm%.csv


pause
7641.

Solve : typing text in ms dos?

Answer»

how do i type text like a letter in ms DOS? i have windows 7What do you mean? Your QUESTION is not CLEAR.

This is a duplicate post.

how would i type some kind of text in ms dos ? what would be at he CMD?Quote from: 5794 on May 16, 2012, 09:44:57 AM

how would i type some kind of text in ms dos ? what would be at he cmd?

yes
7642.

Solve : Batch file editing?

Answer»

Quote

the word document has the prompts for the batch file
I don't get it. Why are a few batch file exercises "prompts"...

Quote
correction I gave simple and straight forward prompts that I ask you to interpret into batch script.
I see. The program itself is a simple text editor that happens to be able to run the program via the SHELL. There are a few issues with this idea:

-It's not new. Or revolutionary. I think a good portion of those who work with batch files and deals with other programming languages writes a batch file editor at some point.

-It's text editing capability is limited. The only thing going for it is the ability to save and run the file via terminal, but you can setup notepad++, Editpad, Sublime text, and various other programs to do the same; they can also capture the output to a new window/text file. Those editors also have more versatile editing functions, options and syntax highlighting, too, line numbers, and (for some)code folding.

-It really really seems like you are TRYING really hard to get somebody to do your batch file homework.

Basically, while this is an interesting practice project, you aren't going to be proving that you can speed up the editing of Batch files since it doesn't really do so.

Bugs and Issues:
-if Defualt.bat doesn't exist in the current directory, an unhandled exception occurs.
This is because you've accidentally doubled the slashes after the drive specification in the catch block.
Additionally, the path is hard coded as C:\Program Files\BatPad.

- the temporary file is never deleted.
-Save acts as a Save As. Save As MENU option exists but is invisible. a Save option should only act like Save As if the text has no file, otherwise it should save to the same file.
-the "Run" toolstripItem's image doesn't have a transparent background.

-not visible running the program, but the code has a LOT of redundancies. I count at least 2 complete sets of the toolstrip event routines.



-If you want to compete with Editpad, Notepad++, sublime text, etc- your undo/redo needs to be done with a stack. This may be beyond your capability in the shorter-term of the project (same with syntax highlighting) so I would suggest perhaps revising your goals for the project to something more attainable.I agree with pretty much everything that BC said. You should work on adding intellisense or syntax highlighting so that there is something that sets it apart from being a notepad with a button that shells a batch file. Also, since you are probably not using all of the features of .NET 4, you should probably change to .NET 2 or 3 so that XP users don't have to install anything to run it. A long time ago, when I first started programming in VB6, I made a program like yours except it was for vbscript instead of batch. Another thing that would be easy to do would be to create a set of command line programs in the same directory that could act as a sort of "highbrid" batch language that has certain commands that you implement. I know this sounds kind of junky, but you could even implement an "include" command that wouldn't actually be written to the outputted batch file, but would tell the program what exes to include with the batch to extend the language. Then when you "compile" the code, it could copy it into an executable ARCHIVE so it appears as if you made your own language lol. You probably shouldn't do that
7643.

Solve : DOS batch to identify and display the process currently using most processor tim?

Answer»

DOS BATCH to IDENTIFY and display the process currently using most processor time, once a second.

I have a sound problem you can read all about at http://www.computing.net/answers/hardware/sporadic-noise-events-hard-to-find-common-denominator/87197.html
Before re-imaging the system, I want to see what process is using all that power when the problem happens. TASK manager doesn't respond fast enough. A script that will read the tasklist entry with the HIGHEST utilization number and display it every second (or fraction--a PARAMETER would be good) would be useful, but I don't have a day to dope out how to do it. Any DOS pros out there have time to assist?
Check here: http://www.thesycon.de/eng/latency_check.shtml for DPC latency checker.

7644.

Solve : How to assign tasks to processors on one PC by Dos command??

Answer»

For a PC with multi-processors, how to ASSIGN TASKS to specified processors by Dos commands?

How to check availability of processors?

THANK you for help.1. START /? (look for the help for the /AFFINITY and /NODE switches)

2. wmic cpu get NumberOfCores


7645.

Solve : colors?

Answer»

Is it possible to make a like a red SQUARE with either batch or powershell?Quote from: TheWaffle on May 14, 2012, 12:04:37 PM

Is it possible to make a like a red square with either batch or powershell?

You mean like the red square in downtown Moscow or the red square on my plaid shirt?

Back in the old days, there was a DOS driver (ANSI.SYS) that allowed you to move the cursor around the screen and produce color characters. Don't know if anything like that still exists for NT batch. Powershell would be a better choice.

Code: [Select]Add-TYPE -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$brush = new-object Drawing.SolidBrush Red
$pen = new-object Drawing.Pen black
$rect = new-object Drawing.Rectangle 10, 10, 180, 180
$form = New-Object Windows.Forms.Form

$formGraphics = $form.createGraphics()

$form.add_paint(
{
$formGraphics.FillRectangle($brush, $rect)
$pen.color = "red"
$pen.width = 5
}
)

$form.ShowDialog()

I found this in the snippet closet, but suspect it came from the internet. Save script with a PS1 extension and run from a Powershell prompt. You can also run from a NT prompt by preceding the script name with the interpreter name (Powershell).

Enjoy.
Quote from: Sidewinder on May 14, 2012, 03:48:12 PM
You mean like the red square in downtown Moscow or the red square on my plaid shirt?

... or the red square in the Martin Cruz Smith novel?
I've been using Ansi Escape codes to change the background, foreground and text color, to make COLORED DOS menus for somewhere around 30 years.

You have to first load the Ansi.sys driver and then know what escape codes to put into your text.

This is just one example, of an Ansi color menu I did, for my ME Utilities, DOS, boot disk.



Here's the "Menu.txt" file, for that screen.

[1;33;44m CD Rom Drivers Are Loaded

[41m Main Menu, Windows ME Utilities [44m

1. Fdisk (setup new hard drive)

2. Fdisk: Make New Boot Record

3. Format drive C: 3A. Format drive D:

4. Scandisk C: ( /autofix )

5. Scandisk All Drives ( /all /autofix )

6. Run "Scanreg /restore" (restores an older version of the Registry)

7. Delete WMIEXE.exe (this file, not needed by Windows)

8. Run HOOVER.bat (deletes 98, ME junk files)

9. REMOVE all files from "C:\_Restore\*.*" in Windows ME.

Type your choice at the DOS prompt and press ENTER.


This is just a text file, called by the Menu.bat, batch file when it's run.

This is not MEANT to be a tutorial, which I'm not prepared to do, but just one example of what can be done.

I'm sure you can find a good tutorial somewhere.

Good Luck,


You can also try the debug command on 32-Bit systems for a batch file.They have some interesting threads over on the Dostips.com forums about Color and Drawing Rudimentary graphics in pure batch.I personnally wanna see the Red Square from Moscow...
7646.

Solve : Display a the date & time when a file was last accessed?

Answer»

I need to display the date and time when a file was last accessed (not modified). I found several entries in this forum but I was not able to use any of them successfully. I was trying not to use an external program.LOOK at the help for the DIR command. You should see what you are looking for.You can parse the output of dir /b /ta [filename] using FOR /F and use the ~t delimiter to (in theory) get the last-accessed time like this...

for /f %%A in ( ' dir /b /TA "d:\path\filename.ext" ' ) do set accesstime=%%~tA

... but there are some points to note:

The NTFS file system stores time values in UTC format, so they are not affected by changes in time zone or daylight saving time. The FAT file system stores time values based on the local time of the computer. Also there are some quite complicated gotchas to do with time zones, daylight saving time (summer time) etc.

Not all file systems can record creation and last access times. Clearly CDFS and UDF won't show access times for example.

Not all file systems record them in the same manner. For example, the resolution of create time on FAT is 10 milliseconds, while write time has a resolution of 2 seconds and access time has a resolution of 1 day, so it is really the access date. The NTFS file system delays updates to the last access time for a file by up to 1 hour after the last access.

Access time recording can slow down the file system to some extent, and there is a registry setting to disable it on NTFS volumes, HKEY_LOCAL_MACHINE\SYSTEM\CurrentContolSet\Control \Filesystem\NtfsDisableLastAccessUpdate (1=DISABLED 0=enabled), so it may be disabled on some NTFS filesystems. The default setting was "enabled" up to XP, and "disabled" in Vista and Windows 7. I don't know about Windows 8, but I expect it's disabled there too.

Some information here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724290%28v=vs.85%29.aspx
Thanks for the very detailed answer.
I tried what was suggested with the dir parameter, but in XP I get back a date that does not match any of the dates (creation, modified, accessed) displayed in the file properties. Is there any other mean to get to it?
Actually I need to check the same parameter that dropbox uses to decide if it must sync a file or not. I assume is the access parameter, because I have a Truecrypt file that even if opened does not show any change in the "modified" date/time field but it does for the "access" date/time.
Any hint on which parameter is Dropbox using other than "access"? And any hint on how to display it?deleted commentQuote from: ventodibolina on May 12, 2012, 11:48:33 AM

I tried what was suggested with the dir parameter, but in XP I get back a date that does not match any of the dates (creation, modified, accessed) displayed in the file properties. Isthere any other mean to get to it?

Does it differ by much, or is it wildly off? However I think chasing access information is a waste of time. A quick Google told me that Dropbox will only sync the files in your Dropbox folder, which leads me to imagine that the Dropbox local client that is run on a user's machine must keep some kind of record of its own (e.g. changed hash*) to use when deciding that a file needs to be synced. It cannot reliably use filesystem last-access time, as a little thought would soon tell you. I already told you above that for FAT it only has a resolution of 24 hours (MULTIPLE access time changes on the same day are ignored) and in NTFS it can be WRONG for up to 1 hour after the access takes place and also in XP may be disabled by the user and is disabled by default on modern Windows. Finally and conclusively, a changed last access time is not a definite indication that a file has changed in any way. Maybe a change in the last write time might be, but not always. If you insist on chasing file time stamps*, to see the last write time for a file use dir /b /TW instead of dir /b /TA in the one liner I posted above.

* I was right. I Googled "Dropbox file change DETECTION" (hint: had you thought of doing this?) and found that Dropbox splits each file into 4 MB blocks and creates a hash on each block. That way, if you change a contiguous 2MB of a 100MB file, it will likely only need to upload 4MB (or 8MB if you cross into a second 4MB block) to re-sync the file, thus saving bandwidth. To find out about file hashing, Google is your friend, but I would imagine that in order to duplicate the functionality of the Dropbox client in this regard you will have to learn some fancy programming tricks.Quote from: ventodibolina on May 12, 2012, 11:48:33 AM
deleted comment

uh huh...

I understand your remarks, however I think I get what I need by using the DIR command which I found to partially work wit htis syntax:

for /f "tokens=1" %%G in ('dir /TA "C:\filename.txt"') DO set attributes=%%G

However by doing echo %attributes% I get only the last of 5 lines. How can I get the 3rd line which contains the access date?
Quote from: ventodibolina on May 12, 2012, 11:40:36 AM
Actually I need to check the same parameter that dropbox uses to decide if it must sync a file or not. I assume is the access parameter, because I have a Truecrypt file that even if opened does not show any change in the "modified" date/time field but it does for the "access" date/time.
Any hint on which parameter is Dropbox using other than "access"? And any hint on how to display it?
I have never used TrueCrypt but I am wondering if every time you open and close your TrueCrypt file does it reset the Archive attribute regardless of any files being changed inside the TrueCrypt file. And if this is true, does Dropbox look at the Archive attribute to sync?Quote from: ventodibolina on May 12, 2012, 06:07:00 PM
I understand your remarks, however I think I get what I need by using the DIR command which I found to partially work wit htis syntax:

for /f "tokens=1" %%G in ('dir /TA "C:\filename.txt"') DO set attributes=%%G

However by doing echo %attributes% I get only the last of 5 lines. How can I get the 3rd line which contains the access date?
Code: [Select]for /f "tokens=1" %%G in ('dir /TA "C:\filename.txt" ^| find "filename.txt"') DO set attributes=%%GSurely if Dropbox rehashes file blocks periodically to check if the local copy has changed from the one in the cloud, then the local file is being accessed and the access time will change, even if nothing has changed and no syncing needs to be done?
This may not be possible in this instance, but......

When I worked for the county, I had to almost beat those old gals with a club to get them to do their daily and weekly data backups.
So to put some teeth in it, I set it up to run the backup program from a batch file, and in the same batch file was a routine to read the date and time from the real time clock and add that info line to the end of a text file.

Then all the supervisor had to do was read that text file with a HOT KEY combo, to get a detailed list of exactly when that backup program was run. That text file would continue to live till it was deleted, by the supervisor.

It was a little devious, but it got the job done. Eh?


7647.

Solve : Trouble erasing files?

Answer»

Quote from: geoffl on August 04, 2012, 06:35:32 AM

Using ntvdm in XP

Both my solutions work in XP in a batch file running under cmd or command. I think you have typo'd something - they also work as far back as MSDOS V6.22 IIRC.

When you say ntvdm, do you mean DosBox or do you simply click on a batch file and it runs in a CMD prompt?
Or do you type COMMAND to open a command shell?

It makes no difference as you have a solution - but the options I provided work just fine.To run my stuff I create an icon by new, shortcut, and load my com file. The .PIF it makes is different from the one you get if you load a .bat file. The .PIF has no shortcut tab - but allows you to load autoexec and config files. These differences I thought were running under XP or running under ntvdm. I have a device which will run under the second option but not the first so there must be a difference.If you have now got a solution for erasing all files without a prompt, my advice is don't worry about it.
Thank you for your help. It is greatly appreciated.
GeofflI love to take a tomcat to a dog show!

In DOS and even in win-XP there is a LITTLE known command that MS has tried to forget that they ever wrote.

It's "Deltree.exe" . It's a combination of the two words Delete and TREE, because that's exactly what it can do..."delete an entire tree structure".
It will not run in Vista, Win-7 or Win-8.

Add the /y switch and Deltree could delete an entire hard drive and never ask the dumb question "Are you Sure?".
My secretary actually did that to me once....she was trying to erase some floppy disks and she forgot to put in the drive letter "A:". Deltree erased my hard drive, by default.

For instance:
deltree /y C:\*.* will delete an entire C: drive.
deltree /y "C:\Windows\temp\*.*" will delete all the files and any sub-folders in the Windows\temp folder.
deltree /y "C:\xyz.txt" would just delete the one file "xyz.txt" from the root directory of C:

So it's either as general or specific as you make it with your syntax.

I use it in my XPCleanup.bat program which cleans up all the junk in my Windows XP, C: drive, which I keep in FAT-32 format.
I run that batch file from my desktop, from my Startup folder and from my GHOST boot disk.

Cheers Mates!
The Shadow

Quote from: TheShadow on August 13, 2012, 03:23:31 PM
It's "Deltree.exe" . It's a combination of the two words Delete and TREE, because that's exactly what it can do..."delete an entire tree structure".
It will not run in Vista, Win-7 or Win-8.

No, but RMDIR will, and RMDIR /S /Q C:\ does the same as DELTREE /y C:\*.*, doesn't it?

http://www.infocellar.com/winxp/rmdir.htm


Close, but no cigar!

I can use Deltree to remove just one type of file, like .tmp from a large directory like Windows.
I don't see any way to use the RD command to do that.
There are many times when I don't WANT to remove a directory, just one file or one type of file in the directory.

For just one file, I can always use the 'Delete' command. Oh well, TIME marches on and we must adjust accordingly.
Thanks for all the input.
The Shadow
7648.

Solve : batch script to copy and rename a folder that had contents in it?

Answer»

i need help with BATCH script to COPY and RENAME a folder thats has files in it with today date.


i use this code for my file but its not working for the folder
Code: [Select]for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "\\nasdata02\finance01\DATA\SMS_MC\Projects\_Databases\Archive\S\Section 1011\Monthly 1011 Olie Process\Template\EWM10AI*.txt" *EWM10AI1-PBSR-%%e%%f%%g.txt

Could you PROVIDE an example of what your input files look like and what you want the output to look like. I am not following your logic at all.

7649.

Solve : Can not format a mount point when the mount point has spaces in the name??

Answer»

OK i had to create three partitions on a hardisk then mount them to a specific folder. i CREATED a bat file which will do this just fine. The problem is when i GO to format the Mount point one of them has a space in its name and format stops right there.

Example:
the folder i used as my mount point is c:\tester 1
the command to format this should be

format c:\tester 1 /fs:ntsf /v:test /q /y

everytime i run this commands it comes back with
INVALID paramater -1


It SEE's the space in the folder name and thinks that it is the end of the folder name. I have already tried to put the file name in quotes but this does not work for format. AFAIK there's no way to format a mount-point (folder) using the format command; you should be able to use FDISK, diskpart, windows disk management, or a similar utility. Not sure if a device name would work either though. Is there a specific reason to require a mount point to do it?Can you format it with a simple name and adjust the name/mountpoint afterward?

7650.

Solve : It shouldn't be this difficult...?

Answer»

Hello all,

I am new to the forum here and I really just joined because I have a very specific question REGARDING batch files. I am trying to create a batch file that will open a log file in a log file viewer so that when the following installation process runs, the user can see when it is completed (the installation gives no on screen prompts and using the log file is the only way to know for certain that the installation took.) The log file viewer I am using is called Trace32. The batch file copies this down to the local system from a network location, then uses assoc and ftype commands to designate Trace32 to be the default viewing program. The problem comes in when the log file is opened. Trace32 opens up, however the log file is not displayed. In order to see the log file, one would have to then select open and select the log file to see it. The issue becomes a little more convoluted when I use windows to double-click on the very same file, and it opens up in Trace32 like I'm wanting it to do with the batch file. Any ideas as to what be causing this? I'd really like to minimize user interaction as much as possible, as I'm sure most of you are aware, the general user has a knack for messing things up when given the opportunity to do so. I have copied the pertinent PARTS of the batch file below (changing some locations too.) I can't do the whole thing because of proprietary network rules and regs, sorry.

assoc .log=logfile
xcopy c:\users\shaun\desktop\Startup\Trace32.exe c:\windows\system32\cmsetup /q /y>nul
ftype logfile=c:\windows\system32\cmsetup\Trace32.exe
start cmsetup.log

Any help would be greatly APPRECIATED. Thank you in advance.BTW, this is a Win 7 cmd prompt environment, for any of the subtle differences there may be between environments.If Trace32 has some dangerous features for users, maybe use notepad to open the log file if its not a formatting nightmare and ascii text. The worst a user can do with notepad is change the log file and save it.

I use to use START notepad.exe "error.log" for reporting errors to users.

So maybe you can just use START NOTEPAD.EXE "cmsetup.log" and send the user to the safety of the notepad environment vs Trace32's interface.Oddly enough, this ended up working when I used the full file path for the program to start and the log file to open.

start c:\windows\system32\cmsetup\Trace32.exe c:\windows\system32\cmsetup\cmsetup.log

On talking with a colleague I found out that unless the file and program are in the system path, the batch file will not be able to process the locations correctly. That is why I was running into the issue I found. Doing it this way also eliminates the need for the assoc and ftype commands, so it ended up saving some time and space.

Thanks.I know this is an old thread, but I came across this thread via search because I was having a similar problem.

For me, Trace32 was already set as the default .LOG file viewer and was previously displaying logs with no trouble. Then Trace32.exe got moved or deleted and the new copy would open but would not display any log data. I was opening the log files through the GUI by double-clicking the log file, so command line was not involved in my case. I could open log files in Notepad and see that there was data there, but Trace32 wouldn't display it.

What fixed my issue was opening Trace32, going to File > Open, UNCHECK the "Ignore existing lines" checkbox, and opening a log file. The first time Trace32 did the same thing and did not SHOW existing lines, but after closing Trace32 and re-opening by double-clicking a log file it opened correctly and displayed the existing lines.

I hope this will be helpful for someone else in the future as well. I found my answer in the "ConfigMgr2007Toolkit.chm" that is included with the Toolkit. My original copy of Trace32 was copied from a colleague and was *just* Trace32, not the whole toolkit.