Identify UNIX and Windows file type

Hi Team,

I am a beginner to powerShell and wanted to find a solution for the below issue. Need your advise on this.

I have a bunch of UNIX and Windows file in a directory. I need to

  1. Identify list of UNIX file and mark it as False
  2. Identify list of WINDOWS file and mark it as TRUE.

Kindly help me to achieve this.

Pranav,

Welcome to the forum. :wave:t4:

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

Thanks

Sure Olaf, I will do it from next time, I am going though the rules and regulations. I will definitely follow.

Sorry for the confusion.

According to the questions you’ve got in the comments on SO and your answers:

There’s no general way of distinguishing UNIX from Windows files because it depends on the file type. A plain text file for example like CSV or XML is pretty much the same on Windows or UNIX.

So you either have to elaborate much more detailed what your question is actually about or you’re pretty much out of luck.

Olaf,

Basically any file other than windows file(txt, docs) have to return False(sorry for my confusing terminology). If it is a windows file, then it need to return TRUE.

I tried Get - ChildItem, but not getting the required result.

There is no easy way for all file types to determine if they come from windows or UNIX/Linux. You may be able to tell this for some/ a few file types. But not in general for all.

Olaf,

Is there a way to accept txt file alone. Anything other than that, it can mark it as False.

So far, I used this command.

ls -rec | select PSParentpath, Extension -u

I can separate the parent path and extension based on the files.

The final path is to get it to TRUE or FALSE.

But how should the path tell you if it’s from UNIX or Windows? :thinking:

Could you please tell the whole story? … not just the way you think you have to go to achive whatever you need to achive. What’s the final goal and what’s the situation right now?

Here is the story:

There is a variety of files with extension like cpp,hpp,sql etc. Any file that gets checked into GIT is text based. Some of the text based file get mistakenly converted to UNIX file due to issue in the code.

so i want to mark the txt file as TRUE and mark any other file other than txt file as False.

What does that mean? How do they get converted?

Are you working on a Windows machine? If you want to check something in into GIT you have to configure your GIT to handle the files accordingly. It may make a difference what editor you’re unsing or what setting you use for text files in your editor. For text files there’s usually only one difference between Windows and Linux - the line ending / line breaks / new lines.

Good Information. Noted.

But is it possible for you to mark the txt file as TRUE and mark any other file other than txt file as False using PS. Just for my knowledge update.

I don’t know what that means. How would you mark them if you don’t use PowerShell?

Thanks Olaf for your time, I am sorry to take your time.

There is a basic premise for ux based files and dos base files is that the difference is how each line is terminated. I believe that is what the original post is based on to determine the ux file versus the dos/windows file. There are a couple of utilities in *nix that convert between the two. Perhaps Olaf if you had a look at these utilities you might be able to suggest a solution? This is way out of my league …

I actually mentioned this already. :wink: But it only matters if you’re talking about text files. The OP couldn’t even tell what files he is talking about.

Understood … sorry for missing your previous mention …

Don’t worry. :+1:t4: Sometimes it gets messy when there are a lot of answers in a thread.