How to open all files in a directory from command prompt - windows

I wan't to open up every excel file in a certain folder using the windows command prompt. I know I can do this if I know the name of each file, but I want to just open all as the file names might change. Thanks.

for %1 in (*.xlsx) do start excel "%%1"
In the command prompt, you can execute the above command which opens all the excel sheets in the current directory. You could store this as batch file by giving full path too
for %1 in (<path>\*.xlsx) do start excel "%%1"
Edit: As #CristiFati noted, if the excel is not there in the path,
for %1 in (<path>\*.xlsx) do "C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.exe" "%%1"

Navigate to the folder in command prompt.
Then run the following command
FOR %F IN (*.*) DO START %F
Credit goes to here:
https://superuser.com/questions/1503993/cmd-command-to-open-all-files-in-a-subdirectory

Related

Batch file replacing issue

I'm trying to change my group policies by replacing the scripts.ini file in C:\Windows\System32\GroupPolicy\Machine\Scripts by using a batch file. The batch file is on my desktop in a folder called replacer, the custom scripts.ini is in the same folder. When i right click the batch file and "Run as administrator" it suddenly can't find the scripts.ini file that's in the same folder. When i don't run as administrator it finds it, but can't replace the scripts.ini file in group policies.
Edit:
Here's the code(1 line):
xcopy /s/y scripts.ini C:\Windows\System32\GroupPolicy\Machine\Scripts
When you run a batch script by double clicking it, the current directory will be the folder where the script resides.
But when you run the script as Administrator by right mouse clicking, then the current directory is something else, typically C:\wINDOWS\system32.
Your script can use %~dp0 to get the full path of where the script is installed, so you can simply prefix your source file with that path:
xcopy /s/y "%~dp0scripts.ini" C:\Windows\System32\GroupPolicy\Machine\Scripts
If you have additional commands that depend on the current directory, then I suggest you use PUSHD to change your current directory instead
pushd "%~dp0"
xcopy /s/y scripts.ini C:\Windows\System32\GroupPolicy\Machine\Scripts

Why cannot i use batch XCOPY while running in admin mode?

i have run very simple script:
xcopy some.exe c:\folder\ /h/y and it works normally. but when i try to run .bat file with this code as administrator - cmd line opens for a moment but nothing happens (file not copied). Can anyone explain this issue?
i also tried to use echo xcopy instead of xcopy, but nothing had changed.
i need only admin running of .bat file, cause i want to copy file in \windows\system32 folder
when you start a batchfile as administrator, it's working directory is C:\windows\system32\. So your script doesn't find your file. Either work with absolute paths, or change the working directory.
You can change it to the directory, where your batchfile resides with:
cd /d "%~dp0"
Note: to keep the window open to read any errormessages, append a pause command.

startup batch file hangs up on second command

I created a startup bat file that looks like this
taskkill /im RemoteDesktopManager.exe
C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
"C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
"C:\Program Files\Mozilla Firefox\firefox.exe"
it does the first and second, but won't go any further, they all exist
how can I fix this?
update : I tried suggestion provided by #phd443322 and wrote this:
taskkill /im RemoteDesktopManager.exe
start "" /w C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" /w "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" /w "C:\Program Files\Mozilla Firefox\firefox.exe"
intrestingly each command still waits for that program to be closed to continue to the next.
so why still not working?
Below there is a working Batch file, as first advised by phd443322:
taskkill /im RemoteDesktopManager.exe
start "" C:\Users\kheradmand\AppData\Local\Google\Chrome\Application\chrome.exe
start "" "C:\Program Files (x86)\JetBrains\PhpStorm 7.1.2\bin\PhpStorm.exe"
start "" "C:\Program Files\Mozilla Firefox\firefox.exe"
Batch files wait for programs to exit unlike interactive. These are the rules documented in the Start command.
If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:
non-executable files may be invoked through their file association just
by typing the name of the file as a command. (e.g. WORD.DOC would
launch the application associated with the .DOC file extension).
See the ASSOC and FTYPE commands for how to create these
associations from within a command script.
When executing an application that is a 32-bit GUI application, CMD.EXE
does not wait for the application to terminate before returning to
the command prompt. This new behavior does NOT occur if executing
within a command script.
When executing a command line whose first token is the string "CMD "
without an extension or path qualifier, then "CMD" is replaced with
the value of the COMSPEC variable. This prevents picking up CMD.EXE
from the current directory.
When executing a command line whose first token does NOT contain an
extension, then CMD.EXE uses the value of the PATHEXT
environment variable to determine which extensions to look for
and in what order. The default value for the PATHEXT variable
is:
.COM;.EXE;.BAT;.CMD
Notice the syntax is the same as the PATH variable, with
semicolons separating the different elements.
When searching for an executable, if there is no match on any extension,
then looks to see if the name matches a directory name. If it does, the
START command launches the Explorer on that path. If done from the
command line, it is the equivalent to doing a CD /D to that path.

execute 2 commands in File shortcut

I am using Windows 7 professional.
I have auto generated file shortcut for the program.
I need to delete one folder before starting the program every time.
Can I automatize it without creating .bat file? e.g. using this command del \directory\path\* /g "C:\Program Files (x86)\program.exe" in the shortcut properties.
Yes you can do this:
C:\Windows\System32\cmd.exe /C "del \directory\path\* /Q & "C:\Program Files (x86)\program.exe"
The & sign tells the shell to run several commands in sequence.

Run a script file as administrator

I have this .vbs script that I am trying to run on windows 7.
It has to run with full permissions and it has to do it automatically.
To be clear When the user double clicks on the file it will get the prompt that asks "to allow to run the file as an administrator", and then run with full permissions.
To do this I created a batch file (run.bat) that calls the script file
cscript "V02.vbs"
pause
then I created a shortcut for the batch file which I can choose to run as admin.
The problem I encounter now is that when I run the batch file as admin the folder changes to c\windows\system32. The script, batch file and shortcut are all in the same folder. is there a way to get the folder location?
I may have misunderstood...
The easiest solution would be to "hardcode" that path into the patch file with a -
cd \path\to\my\script
cscript myscript.vbs
pause
Use "modifiers with batch parameters". From the linked documentation:
%~dp1 Expands %1 to a drive letter and path.
Since %0 is your script, %~dp0 is what you want:
cscript "%~dp0V02.vbs"
pause
Note that %~dp0 includes the trailing backslash, so your v02.vbs file name above becomes quite hard to read.

Resources