Skip to content

Instantly share code, notes, and snippets.

@GEJ1
Last active April 19, 2024 18:33
Show Gist options
  • Save GEJ1/969697a9b5aa265acbfccfdc44c02528 to your computer and use it in GitHub Desktop.
Save GEJ1/969697a9b5aa265acbfccfdc44c02528 to your computer and use it in GitHub Desktop.
edf2asc in batch
"""
Requires edf2asc software installed
"""
import os
import subprocess
import config
def main():
# Specify the folder containing .EDF files
input_folder = "path/to/input_folder"
# Specify the folder where you want to save the .ASC files
output_folder = "path/to/output_folder"
# Check if the output folder exists
if not os.path.exists(output_folder):
print(f"{output_folder} does not exist!")
# Iterate through all .EDF files in the input folder
for edf_file in os.listdir(input_folder):
if edf_file.endswith(".EDF"):
# Extract the file name without extension
filename, _ = os.path.splitext(edf_file)
# Specify the output file path
asc_file = os.path.join(output_folder, f"{filename}.ASC")
# Create a subprocess with input redirection
process = subprocess.Popen(["edf2asc", os.path.join(input_folder, edf_file), asc_file], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
# Provide the response to the prompt (e.g., 'Y' for Yes)
response = 'Y\n'
# Send the response to the subprocess
process.stdin.write(response)
process.stdin.flush()
# Wait for the subprocess to finish
process.wait()
# Close the subprocess stdin
process.stdin.close()
# Print a message indicating the conversion
print(f"Converted {filename}.EDF to {filename}.ASC")
print("ALl conversions completed!")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment