I want use the Windows 10 Command Prompt to open files whose names are in certain range. The files i want to open have names like AF87314.corr.fits (some files may have .corr.fits.discarded extension) and as an example suppose i want to open the files from AF87314 to AF87320. On Linux (Ubuntu) i can use

ds9 AF873{14..20}.corr.fits

(ds9 is the program that i use to open those images). On Windows i cannot. Is there a solution to my problem?

Thanks in advance to all of you.

EDIT: Thanks Ian C. for giving a possible solution, but it is not the one i am looking for since each image opens in a new window of the program. I need to pass all of the filenames to the command at once, so that only one window is open at a time and i can work on all of the images at the same time.

EDIT2: Thanks LPChip as well, but something doen not work doing what you suggested. Using for instance ds9 AF873{30..35}.corr.fits the program gives an error saying that the file [full-path-to-file]/AF873 could not be opened (please note that the latter part of the filename is missing). I'm in the right folder however, i can open any files with ds9 AF87330.corr.fits.

EDIT3: I think i found a possible solution, which is to use findstr. Later, when i get home i'll test it a bit more, because it uses regex and i'm not familiar with it.

  • 1
    Command Prompt can't do this, but Powershell does. – LPChip Nov 9 '17 at 9:34
  • That could be okay, but how? – Ale Nov 9 '17 at 12:00
  • If I'm not mistaken, similar to how it is done in Linux. So .\ds9 AF873{14..20}.corr.fits – LPChip Nov 9 '17 at 12:13
  • Please see the edit. – Ale Nov 9 '17 at 15:45
  • I'm not exactly sure how the syntax is, that's why I added: If I'm not mistaken... – LPChip Nov 9 '17 at 15:47

You can use a FOR loop.

FOR /l %K in (14,1,20) DO DS9.EXE AF873%K.corr.fits

Things to note

  • The %K is your variable number that changes with each file.
  • Because /l is a counter, this only works with numbers, not with other characters
  • For simplicity sake, I am leaving out any reference to file paths.
  • /l does not use leading zeroes. If we take your example and wanted to start at 08 instead of 14
    • You can't use in (8,1,20), the result would be AF8738, AF8739, AF87310, AF87311, ...
    • You would have to use in (308,1,20) ... AF87%K.corr.fits
|improve this answer|||||
  • This is what i was looking for since the part of the filename that changes is just made of numbers. – Ale Nov 9 '17 at 12:02
  • I tried and I was wrong, this is not what i was looking for. It opens N times the program where N is the number of files i want to open. If possible i'd like all the files to be passed as arguments to the program once for all. – Ale Nov 9 '17 at 12:07
  • Not all programs support multi-document windows. See Notepad and MS Paint. Others like Notepad++, Adobe Reader & Excel do. I believe you can specify multiple documents on the command line to open them simultaneously; e.g. Excel.exe doc1 doc2 doc3, but I don't remember ever seeing a command line dynamically expanded to open multiple documents in one window. – Altered-Ego Nov 10 '17 at 11:32
  • ds9 does support opening multiple files in the same window, but i need to open more than 10 files at the same time, writing each filename each time is a pain... – Ale Nov 10 '17 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.