We have a 2 step process that collects all filenames from a folder into a Word document for use elsewhere.
The original process was to run an old DOS batchfile that collected the filenames into a DOS .txt. Then we launched a Word .docx with a macro that imported the .txt and massaged the formatting. After visual inspection we hit ‘Save’ and that was it.
I had the bright idea that a step could be taken out by launching Word directly from the batch, so I inserted the line: start winword filename. This works great except that the default location that Word wants to save in is now my Templates folder. Running it the old way still works perfectly.
The question is: why is the default location changed by launching Word programmatically and how can it be forced back to the correct location?
Thanks
you can use:
start /D C:\path\to\folder "" winword.exe
this program starts winword.exe and save all files to C:\path\to\folder
ill assume that winword.exe is in the current directory.
for help with the start command : http://ss64.com/nt/start.htm
I investigated the start command, but never did figure out why it operated differently. The eventual solution was to include the Save action in the macro. I still don't know why we didn't have to do that before, but it works now so we're declaring success and moving on.
Related
My Process:
For version control, all my files are named with the format "fileName_v#.#"
I keep a folder called 'Live Environment', and as a new version is rolled out, the current file (ex. fileName_v1.0) is removed from 'Live Environment' folder, and the new version (ex. fileName_v2.0) is moved into 'Live Environment'.
My batch script is used to keep all users on the most current version. It works perfect, except with every version I need to go back and update the hard-coded file name in my script to the new file name.
I would like to use a wildcard to search this folder for whatever file is in the 'Live Environment' folder, and then perform the copy function.
Current Code:
::Sets the default install location as the user's desktop
set "DestinationFolder=%userprofile%\desktop"
::Copies and saves file to the user's Desktop
copy /-y "\\myUNCPath\Live Environment\fileName_v*.accdb" "%DestinationFolder%\copiedFile.accdb"
My Issue:
I've hardcoded the "fileName_v#.#.accdb" in for each version so far, and the code executes perfectly. The second I remove the hardcoded file version and add the "*" wildcard, the code errors. The copy function still runs, but simply creates an empty .accdb file on the users desktop, which when used gives the error:
"Unrecognized database format"
At this point I'm overthinking this and making it harder than it needs to be. A set of fresh eyes on the issue would be helpful. Any help would be greatly appreciated!
#aschipfl - that worked! Thanks for the comment.
Simply adding "/b" to the copy line fixed the issue.
copy /-y /b
(For more details see the aschipfl's comment posted below the question).
I'm trying to output my logfiles to a subfolder relative to my install script, and MSIExec doesn't seem to like it when used with the "/l*v" command. I've tried variations of %~dp0Logs (with and without quotes, etc.). If I manually enter the full path like: /l*v c:\scripts\logs\%computername%.txt" it works fine, but the script is always going to be in different locations (USB, network, etc.).
I see references online to using the %temp% system variable which I guess works, but not the parent lookup folder variable of %dp0. And I'm using the same variable elsewhere in my script for other things, like running the MSI and file copy commands (copy "%~dp0Files\Images\%LogonBackgroundWinXP%"...). I've even tried setting a variable like: Set LogFolder=%dp0\logs, but that doesn't seem to work either.
Am I missing something or am I just going to have to find another folder lookup method just for my log files?
Thanks,
Brian
I guess all I needed was a few hours away from this and lunch! Works perfectly fine, not sure what I was doing wrong before. I was going to do a copy command afterwards, but now I don't have to.
I felt it was better to ask this separately rather than expect an answer from my comment on my previous post.
I already have variables set for the directory number %jobn% which is unique is there a way I can search for the unknown element to add to another variable, I know via the command line I can run Dir D09854* and I will get a single report with the full name, can this be collected somehow and add to a named variable?
S:\SWDA\HBOS>dir d09854*
Volume in drive S is Images
Volume Serial Number is FE8F-38FE
Directory of S:\SWDA\HBOS
18/02/2013 10:29 <DIR> D09854_Parent Test
I want to add the elements after "_" to a variable %DirDesc% so I can create the full path by combining %jobn%%DirDesc% to get "D09854_Parent Test"
dir d09854* /b will recover the full folder name in one line, without the extra cruft, if that's any use? What are you writing this widget in?
Does it have to be Good Old Fashioned DOS, or can the newer Command extensions be used?
With limited old DOS, I can't think of a way to get that into a SET Variable without piping it to a temporary batch file, having first ECHO'd a set variable= into it, and using >> in the pipe to append to it... and then CALL the temporary batch file to execute the command!
I work extensively using the shell. When I continue working on some project one week later, I go to some "folder" and realize that I do not remember what I was doing. Sometimes and before stopping work what I do is:
history > DIRX_HISTORY_20100922
so later I have a look at the commands I used, I can remember much better what I was doing.
I wonder if somehow, some script or something could do this automatically each time I type a command in a directory, so this DIRX_HISTORY_20100922 is created and a new one is modified depending on the date and on the directory name.
Thanks
Have a look at my history logging functions. They save the current directory along with the command that was executed. You can grep for the directory and it will show you the commands that you were using there.
Bash's PROMPT_COMMAND variable can be used to save the last line of your history to a file for every command you enter.
ie.
PROMPT_COMMAND="history 1 >> DIRX_HISTORY"
I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.